コード例 #1
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /**
   * @return a new model in which all occurrences of the old namespace are replaced by the new one.
   *     All replaced resources are summarized in the map if not null. If resourcesToIgnore != null,
   *     ignore resources listed there.
   */
  public static Model replaceNamespace(Model m, String o, String n, Map o2n, Set resourcesToIgnore)
      throws ModelException {

    Model res = m.create();
    NodeFactory f = m.getNodeFactory();
    Enumeration en = m.elements();
    while (en.hasMoreElements()) {

      Statement st = (Statement) en.nextElement();
      res.add(replaceNamespace(st, o, n, f, o2n, resourcesToIgnore));
    }
    return res;
  }
コード例 #2
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /**
   * @return a new model in which all occurrences of the old resources are replaced by the new ones.
   *     Returns number replacements done.
   */
  public static int replaceResources(Model m, Map o2n) throws ModelException {

    NodeFactory f = m.getNodeFactory();
    Enumeration en = m.elements();

    Model toRemove = m.create();
    Model toAdd = m.create();

    while (en.hasMoreElements()) {

      Statement st = (Statement) en.nextElement();
      Statement st_n = replaceResources(st, f, o2n);

      if (st_n != st) { // yes, pointer comparison
        toAdd.add(st_n);
        toRemove.add(st);
      }
    }

    SetOperations.subtract(m, toRemove);
    SetOperations.unite(m, toAdd);

    return toAdd.size();
  }
コード例 #3
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /**
   * returns a subgraph of "m" containing "r" and all nodes reachable from "r" via directed edges.
   * These edges are also included in the resulting model.
   */
  public static Model getReachable(Resource r, Model m) throws ModelException {

    Model result = m.create();
    getReachable(r, m, result);
    return result;
  }