Example #1
0
  public static Statement replaceNamespace(
      Statement st, String o, String n, NodeFactory f, Map o2n, Set resourcesToIgnore)
      throws ModelException {

    boolean replaced = false;
    Resource subj = st.subject();
    Resource pred = st.predicate();
    RDFNode obj = st.object();

    if (obj instanceof Resource
        && !(obj instanceof Statement)
        && o.equals(((Resource) obj).getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(obj))) {

      replaced = true;
      Resource r = f.createResource(n, ((Resource) obj).getLocalName());
      if (o2n != null) o2n.put(obj, r);
      obj = r;
    }

    if (o.equals(subj.getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(subj))) {

      replaced = true;
      Resource r = f.createResource(n, subj.getLocalName());
      if (o2n != null) o2n.put(subj, r);
      subj = r;
    }

    if (o.equals(pred.getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(pred))) {

      replaced = true;
      Resource r = f.createResource(n, pred.getLocalName());
      if (o2n != null) o2n.put(pred, r);
      pred = r;
    }
    return replaced ? f.createStatement(subj, pred, obj) : st;
  }
Example #2
0
  /** Extracts the namespace prefix out of a URI. */
  public static String getNamespace(Resource r) throws ModelException {

    String ns = r.getNamespace();
    return ns != null ? ns : guessNamespace(r.getURI());
  }
Example #3
0
  public static void collectNamespaces(Resource r, Collection target) throws ModelException {

    String ns = r.getNamespace();
    if (ns != null) target.add(ns);
  }
Example #4
0
  /** Delivers the name out of the URI (without the namespace prefix). */
  public static String getLocalName(Resource r) throws ModelException {

    if (r.getNamespace() == null) return guessName(r.getURI());
    else return r.getLocalName();
  }