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);
     }
   }
 }
 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);
 }
 public void testFindSubject() {
   StmtIterator iter = model.listStatements(new SimpleSelector(null, null, RDFS.Resource));
   assertTrue(iter.hasNext());
   Resource subject = iter.nextStatement().getSubject();
   iter.close();
   iter = model.listStatements(new SimpleSelector(subject, null, (RDFNode) null));
   int i = 0;
   while (iter.hasNext()) {
     i++;
     Statement stmt = iter.nextStatement();
     assertEquals(subject, stmt.getSubject());
   }
   assertEquals(3, i);
 }
 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);
 }
 public void testAll() {
   StmtIterator iter = model.listStatements(new SimpleSelector(null, null, (RDFNode) null));
   int i = 0;
   while (iter.hasNext()) {
     i++;
     iter.next();
   }
   assertEquals(6, i);
 }
 /**
  * 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);
   }
 }
 public void testFindObject() {
   StmtIterator iter = model.listStatements(new SimpleSelector(null, null, RDFS.Resource));
   int i = 0;
   while (iter.hasNext()) {
     i++;
     Statement stmt = iter.nextStatement();
     assertEquals(RDFS.Resource, stmt.getObject());
   }
   assertEquals(2, i);
 }
 public void testFindProperty() {
   StmtIterator iter = model.listStatements(new SimpleSelector(null, RDFS.label, (RDFNode) null));
   int i = 0;
   while (iter.hasNext()) {
     i++;
     Statement stmt = iter.nextStatement();
     assertEquals(RDFS.label, stmt.getPredicate());
   }
   assertEquals(2, i);
 }
 public void testFindPropertyAndObject() {
   StmtIterator iter = model.listStatements(new SimpleSelector(null, RDF.value, 123));
   int i = 0;
   while (iter.hasNext()) {
     i++;
     Statement stmt = iter.nextStatement();
     assertEquals(RDF.value, stmt.getPredicate());
     assertEquals(123, stmt.getInt());
   }
   assertEquals(2, i);
 }
Exemplo n.º 10
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);
   }
 }
Exemplo n.º 11
0
 private static Set<Resource> subjectSet(Model result, Resource S, Property P, RDFNode O) {
   return result.listStatements(S, P, O).mapWith(Statement.Util.getSubject).toSet();
 }
Exemplo n.º 12
0
 private static void addIntersections(Model result, Model schema) {
   StmtIterator it = schema.listStatements(ANY, OWL.intersectionOf, ANY);
   while (it.hasNext()) addIntersections(result, schema, it.nextStatement());
 }
Exemplo n.º 13
0
 /**
  * Answer the set of all classes which appear in <code>m</code> as the subject or object of a
  * <code>rdfs:subClassOf</code> statement.
  */
 private static Set<RDFNode> findClassesBySubClassOf(Model m) {
   Set<RDFNode> classes = new HashSet<RDFNode>();
   StmtIterator it = m.listStatements(null, RDFS.subClassOf, (RDFNode) null);
   while (it.hasNext()) addClasses(classes, it.nextStatement());
   return classes;
 }