コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
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);
     }
   }
 }
コード例 #4
0
 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);
 }
コード例 #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
 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);
 }
コード例 #7
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);
 }
コード例 #8
0
 private static void addIntersections(Model result, Model schema, Statement s) {
   Resource type = s.getSubject();
   List<RDFNode> types = asJavaList(AssemblerHelp.getResource(s));
   Set<Resource> candidates = subjectSet(result, ANY, RDF.type, types.get(0));
   for (int i = 1; i < types.size(); i += 1)
     removeElementsWithoutType(candidates, (Resource) types.get(i));
   addTypeToAll(type, candidates);
 }
コード例 #9
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);
   }
 }
コード例 #10
0
 /**
  * Add to <code>classes</code> the subject and object of the statement <code>xSubClassOfY</code>.
  */
 private static void addClasses(Set<RDFNode> classes, Statement xSubClassOfY) {
   classes.add(xSubClassOfY.getSubject());
   classes.add(xSubClassOfY.getObject());
 }