コード例 #1
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  // 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);
    }
  }
コード例 #2
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  public static List getObjects(Model m, Resource subject, Resource predicate)
      throws ModelException {

    List result = new ArrayList();

    if (m == null || m.size() == 0) return result;

    for (Enumeration en = m.find(subject, predicate, null).elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      result.add(st.object());
    }
    return result;
  }
コード例 #3
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  // returns list of statements
  public static void replaceMult(Statement st, NodeFactory f, Map o2n, Collection result)
      throws ModelException {

    List l1 = new ArrayList();
    replaceMultSPO(st, f, o2n, l1, st.subject(), 0);

    List l2 = new ArrayList();
    for (int i = 0; i < l1.size(); i++)
      replaceMultSPO((Statement) l1.get(i), f, o2n, l2, st.predicate(), 1);

    for (int i = 0; i < l2.size(); i++)
      replaceMultSPO((Statement) l2.get(i), f, o2n, result, st.object(), 2);
  }