Exemple #1
0
  public static void collectResourcesSO(Model m, Collection target) throws ModelException {

    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      if (!(st.object() instanceof Literal) && !(st.object() instanceof Statement))
        target.add(st.object());
      target.add(st.subject());
    }
  }
Exemple #2
0
  public static void replaceResources(Collection src, Collection dest, NodeFactory f, Map o2n)
      throws ModelException {

    Iterator it = src.iterator();

    while (it.hasNext()) {

      Statement st = (Statement) it.next();
      dest.add(replaceResources(st, f, o2n));
    }
  }
Exemple #3
0
  public static void collectPredicates(Model m, Collection target) throws ModelException {

    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      target.add(st.predicate());
    }
  }
Exemple #4
0
  // returns list of statements
  protected static void replaceMultSPO(
      Statement st, NodeFactory f, Map o2n, Collection result, RDFNode toReplace, int position)
      throws ModelException {

    Collection replacements;

    if (toReplace instanceof Statement) {

      List l = new ArrayList();
      replaceMult((Statement) toReplace, f, o2n, l);

      if (l.size() == 1 && toReplace == l.get(0)) {
        result.add(st);
        return; // keep the same
      } else replacements = l;

    } else {

      Object ro = o2n.get(toReplace);

      if (ro instanceof Collection) replacements = (Collection) ro;
      else if (ro != null) {

        replacements = new ArrayList();
        replacements.add(ro);

      } else { // no replacement needed

        result.add(st); // keep the same statement
        return;
      }
    }

    for (Iterator it = replacements.iterator(); it.hasNext(); ) {

      Statement rs = null;
      Object rr = it.next();

      switch (position) {
        case 0:
          rs = f.createStatement((Resource) rr, st.predicate(), st.object());
          break;
        case 1:
          rs = f.createStatement(st.subject(), (Resource) rr, st.object());
          break;
        case 2:
          rs = f.createStatement(st.subject(), st.predicate(), (RDFNode) rr);
          break;
      }
      result.add(rs);
    }
  }
Exemple #5
0
  public static void collectNamespaces(Resource r, Collection target) throws ModelException {

    String ns = r.getNamespace();
    if (ns != null) target.add(ns);
  }