コード例 #1
0
 /** "dirty" reifications - those with conflicting quadlets - should fail. */
 public void testDirtyReification() {
   Resource R = model.createResource(aURI);
   model.add(R, RDF.type, RDF.Statement);
   model.add(R, RDF.subject, S);
   model.add(R, RDF.subject, P);
   testDoesNotReify("boo", R);
 }
コード例 #2
0
 /**
  * the simplest case: if we assert all the components of a reification quad, we can get a
  * ReifiedStatement that represents the reified statement.
  */
 public void testBasicReification() {
   if (model.getReificationStyle() != ModelFactory.Minimal) {
     Resource R = model.createResource(aURI);
     model.add(R, RDF.type, RDF.Statement);
     model.add(R, RDF.subject, S);
     model.add(R, RDF.predicate, P);
     model.add(R, RDF.object, O);
     RDFNode rs = R.as(ReifiedStatement.class);
     assertEquals("can recover statement", SPO, ((ReifiedStatement) rs).getStatement());
   }
 }
コード例 #3
0
 public void testBulkByModel(Model m) {
   assertEquals("precondition: model must be empty", 0, m.size());
   Model A = modelWithStatements("clouds offer rain; trees offer shelter");
   Model B = modelWithStatements("x R y; y Q z; z P x");
   m.add(A);
   assertIsoModels(A, m);
   m.add(B);
   m.remove(A);
   assertIsoModels(B, m);
   m.remove(B);
   assertEquals("", 0, m.size());
 }
コード例 #4
0
 public void testListReifiedSpecificStatements() {
   assertEquals("no statements should match st", empty, getSetRS(model, SPO));
   /* */
   ReifiedStatement rs = model.createReifiedStatement(aURI, SPO);
   ReifiedStatement rs2 = model.createReifiedStatement(anotherURI, SPO2);
   model.add(rs, P, O);
   // assertEquals( "still no matching statement", empty, getSetRS( m, stOther ) );
   /* */
   Set justRS2 = arrayToSet(new Object[] {rs2});
   model.add(rs2, P, O);
   assertEquals("now one matching statement", justRS2, getSetRS(model, SPO2));
 }
コード例 #5
0
 protected static void addRangeTypes(Model result, Model schema) {
   Model toAdd = ModelFactory.createDefaultModel();
   for (StmtIterator it = schema.listStatements(ANY, RDFS.range, ANY); it.hasNext(); ) {
     Statement s = it.nextStatement();
     RDFNode type = s.getObject();
     Property property = s.getSubject().as(Property.class);
     for (StmtIterator x = result.listStatements(ANY, property, ANY); x.hasNext(); ) {
       RDFNode ob = x.nextStatement().getObject();
       if (ob.isResource()) toAdd.add((Resource) ob, RDF.type, type);
     }
   }
   result.add(toAdd);
 }
コード例 #6
0
 protected static void addSupertypes(Model result) {
   Model temp = ModelFactory.createDefaultModel();
   for (StmtIterator it = result.listStatements(ANY, RDF.type, ANY); it.hasNext(); ) {
     Statement s = it.nextStatement();
     Resource c = AssemblerHelp.getResource(s);
     for (StmtIterator subclasses = result.listStatements(c, RDFS.subClassOf, ANY);
         subclasses.hasNext(); ) {
       RDFNode type = subclasses.nextStatement().getObject();
       // System.err.println( ">> adding super type: subject " + s.getSubject() + ", type " + type
       // );
       temp.add(s.getSubject(), RDF.type, type);
     }
   }
   result.add(temp);
 }
コード例 #7
0
 public void testMBU(Model m) {
   Statement[] sArray = statements(m, "moon orbits earth; earth orbits sun");
   List<Statement> sList = Arrays.asList(statements(m, "I drink tea; you drink coffee"));
   m.add(sArray);
   testContains(m, sArray);
   m.add(sList);
   testContains(m, sList);
   testContains(m, sArray);
   /* */
   m.remove(sArray);
   testOmits(m, sArray);
   testContains(m, sList);
   m.remove(sList);
   testOmits(m, sArray);
   testOmits(m, sList);
 }
コード例 #8
0
 /**
  * test that listReifiedStatements produces an iterator that contains the right reified
  * statements. We *don't* test that they're not duplicated, because they might be; disallowing
  * duplicates could be expensive.
  */
 public void testListReifiedStatements() {
   assertEquals("initially: no reified statements", empty, getSetRS(model));
   ReifiedStatement rs = model.createReifiedStatement(aURI, SPO);
   // assertEquals( "still: no reified statements", empty, getSetRS( m ) );
   /* */
   model.add(rs, P, O);
   Set justRS = arrayToSet(new Object[] {rs});
   assertEquals("post-add: one reified statement", justRS, getSetRS(model));
   model.add(S, P, rs);
   assertEquals("post-add: still one reified statement", justRS, getSetRS(model));
   /* */
   ReifiedStatement rs2 = model.createReifiedStatement(anotherURI, SPO2);
   Set bothRS = arrayToSet(new Object[] {rs, rs2});
   model.add(rs2, P, O);
   assertEquals("post-add: still one reified statement", bothRS, getSetRS(model));
 }
コード例 #9
0
 /**
  * Add to <code>toAdd</code> all the superclass statements needed to note that any indirect
  * subclass of <code>X = parents.item</code> has as superclass all the classes between it and X
  * and all the remaining elements of <code>parents</code>.
  */
 private static void addSuperClasses(Model m, LinkedSeq parents, Model toAdd) {
   Resource type = parents.item;
   for (StmtIterator it = m.listStatements(null, RDFS.subClassOf, type); it.hasNext(); ) {
     Resource t = it.nextStatement().getSubject();
     for (LinkedSeq scan = parents.rest; scan != null; scan = scan.rest)
       toAdd.add(t, RDFS.subClassOf, scan.item);
     addSuperClasses(m, parents.push(t), toAdd);
   }
 }
コード例 #10
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /** 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;
  }
コード例 #11
0
 public void testBulkByModelReifying(boolean suppress) {
   Model m = modelWithStatements(ReificationStyle.Minimal, "a P b");
   addReification(m, "x", "S P O");
   addReification(m, "a", "x R y");
   Model target = modelWithStatements(ReificationStyle.Minimal, "");
   target.add(m, suppress);
   target.setNsPrefixes(PrefixMapping.Standard);
   assertIsoModels((suppress ? modelWithStatements("a P b") : m), target);
 }
コード例 #12
0
 public void testStatementListReifiedStatements() {
   Statement st = SPO;
   Model m = model;
   assertEquals(
       "it's not there yet", empty, GraphTestBase.iteratorToSet(st.listReifiedStatements()));
   ReifiedStatement rs = m.createReifiedStatement(aURI, st);
   Set justRS = arrayToSet(new Object[] {rs});
   m.add(rs, P, O);
   assertEquals("it's here now", justRS, GraphTestBase.iteratorToSet(st.listReifiedStatements()));
 }
コード例 #13
0
 /**
  * Example the conclusions graph for introduction of restrictions which require a comprehension
  * rewrite and declare new (anon) classes for those restrictions.
  */
 public void comprehensionAxioms(Model premises, Model conclusions) {
   // Comprehend all restriction declarations and note them in a map
   Map<Resource, Resource> comprehension = new HashMap<>();
   StmtIterator ri = conclusions.listStatements(null, RDF.type, OWL.Restriction);
   while (ri.hasNext()) {
     Resource restriction = ri.nextStatement().getSubject();
     StmtIterator pi = restriction.listProperties(OWL.onProperty);
     while (pi.hasNext()) {
       Resource prop = (Resource) pi.nextStatement().getObject();
       StmtIterator vi = restriction.listProperties();
       while (vi.hasNext()) {
         Statement rs = vi.nextStatement();
         if (!rs.getPredicate().equals(OWL.onProperty)) {
           // Have a restriction on(prop) of type rs in the conclusions
           // So assert a premise that such a restriction could exisit
           Resource comp =
               premises
                   .createResource()
                   .addProperty(RDF.type, OWL.Restriction)
                   .addProperty(OWL.onProperty, prop)
                   .addProperty(rs.getPredicate(), rs.getObject());
           comprehension.put(restriction, comp);
         }
       }
     }
   }
   // Comprehend any intersectionOf lists. Introduce anon class which has the form
   // of the intersection expression.
   // Rewrite queries of the form (X intersectionOf Y) to the form
   //   (X equivalentClass ?CC) (?CC intersectionOf Y)
   StmtIterator ii = conclusions.listStatements(null, OWL.intersectionOf, (RDFNode) null);
   List<Statement> intersections = new ArrayList<>();
   while (ii.hasNext()) {
     intersections.add(ii.nextStatement());
   }
   for (Statement is : intersections) {
     // Declare in the premises that such an intersection exists
     Resource comp =
         premises
             .createResource()
             .addProperty(RDF.type, OWL.Class)
             .addProperty(
                 OWL.intersectionOf, mapList(premises, (Resource) is.getObject(), comprehension));
     // Rewrite the conclusions to be a test for equivalence between the class being
     // queried and the comprehended interesection
     conclusions.remove(is);
     conclusions.add(is.getSubject(), OWL.equivalentClass, comp);
   }
   // Comprehend any oneOf lists
   StmtIterator io = conclusions.listStatements(null, OWL.oneOf, (RDFNode) null);
   while (io.hasNext()) {
     Statement s = io.nextStatement();
     Resource comp = premises.createResource().addProperty(OWL.oneOf, s.getObject());
   }
 }
コード例 #14
0
 public void testIsReified() {
   ReifiedStatement rs = model.createReifiedStatement(aURI, SPO);
   Resource BS = model.createResource(anchor + "BS");
   Property BP = model.createProperty(anchor + "BP");
   RDFNode BO = model.createProperty(anchor + "BO");
   model.add(rs, P, O);
   assertTrue("st should be reified now", SPO.isReified());
   assertTrue("m should have st reified now", model.isReified(SPO));
   assertFalse(
       "this new statement should not be reified", model.createStatement(BS, BP, BO).isReified());
 }
コード例 #15
0
 protected static void addDomainTypes(Model result, Model schema) {
   for (StmtIterator it = schema.listStatements(ANY, RDFS.domain, ANY); it.hasNext(); ) {
     Statement s = it.nextStatement();
     Property property = s.getSubject().as(Property.class);
     RDFNode type = s.getObject();
     for (StmtIterator x = result.listStatements(ANY, property, ANY); x.hasNext(); ) {
       Statement t = x.nextStatement();
       result.add(t.getSubject(), RDF.type, type);
     }
   }
 }
コード例 #16
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /** returns true if old triples from r were removed */
  public static boolean setUniqueObject(
      Model r, Resource subject, Resource predicate, RDFNode object) throws ModelException {

    Model old = r.find(subject, predicate, null);
    SetOperations.subtract(r, old);
    Statement stmt = get1(old);

    if (subject == null && stmt != null) subject = stmt.subject();
    if (predicate == null && stmt != null) predicate = stmt.predicate();

    r.add(r.getNodeFactory().createStatement(subject, predicate, object));
    return !old.isEmpty();
  }
コード例 #17
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;
  }
コード例 #18
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();
  }
コード例 #19
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 src, Model dest, Map o2n) throws ModelException {

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

    int replaced = 0;

    while (en.hasMoreElements()) {

      Statement st = (Statement) en.nextElement();
      Statement st_n = replaceResources(st, f, o2n);
      dest.add(st_n);
      if (st_n != st) // yes, pointer comparison
      replaced++;
    }
    return replaced;
  }
コード例 #20
0
 /**
  * walk down the set of statements (represented as an array), recursing with and without each
  * statement being present. The mask bits record those statements that are in the model. At the
  * bottom of the recursion (n == 0), check that R can be reified exactly when all four quad
  * components are present; the other statements don't matter.
  */
 private void testCombinations(Model m, Resource R, int mask, Object[][] statements, int n) {
   if (n == 0) {
     try {
       // System.err.println( "| hello. mask = " + mask );
       ReifiedStatement rs = (ReifiedStatement) R.as(ReifiedStatement.class);
       // System.err.println( "+  we constructed " + rs );
       assertTrue(
           "should not reify: not all components present [" + mask + "]: " + rs,
           (mask & 15) == 15);
       // System.err.println( "+  and we passed the assertion." );
     } catch (DoesNotReifyException e) { // System.err.println( "+  we exploded" );
       assertFalse("should reify: all components present", mask == 15);
     }
   } else {
     int i = n - 1;
     Statement s = (Statement) statements[i][0];
     int bits = ((Integer) statements[i][1]).intValue();
     testCombinations(m, R, mask, statements, i);
     m.add(s);
     testCombinations(m, R, mask + bits, statements, i);
     m.remove(s);
   }
 }
コード例 #21
0
 public void testThisWillBreak() {
   Resource R = model.createResource(aURI);
   SPO.createReifiedStatement(aURI);
   model.add(R, RDF.subject, R);
 }
コード例 #22
0
 protected static void addSubclassesFrom(Model result, Model schema) {
   for (StmtIterator it = schema.listStatements(ANY, RDFS.subClassOf, ANY); it.hasNext(); ) {
     Statement s = it.nextStatement();
     if (s.getSubject().isURIResource() && s.getObject().isURIResource()) result.add(s);
   }
 }
コード例 #23
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  public static void add(Model m, Resource subject, Resource predicate, RDFNode object)
      throws ModelException {

    m.add(m.getNodeFactory().createStatement(subject, predicate, object));
  }
コード例 #24
0
 /**
  * To each subclass X of <code>parents.item</code> add as superclass all the classes between X and
  * that item and all the items in the rest of <code>parents</code>.
  */
 private static void addSuperClasses(Model m, LinkedSeq parents) {
   Model toAdd = ModelFactory.createDefaultModel();
   addSuperClasses(m, parents, toAdd);
   m.add(toAdd);
 }