Esempio n. 1
0
  public static Set toSet(Model m) throws ModelException {

    Set s = new HashSet();
    Enumeration en = m.elements();
    while (en.hasMoreElements()) s.add(en.nextElement());
    return s;
  }
Esempio n. 2
0
  /** Fills <tt>m</tt> with statements from <tt>s</tt> and returns it. */
  public static Model toModel(Set s, Model m) throws ModelException {

    Iterator it = s.iterator();
    while (it.hasNext()) {
      Object o = it.next();
      if (o instanceof Statement) m.add((Statement) o);
    }
    return m;
  }
Esempio n. 3
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;
  }