private List<VCard> parseAddressBook(Resource selfResource, SolidUtilities utilities) throws IOException { String peopleUri = selfResource.getProperty(NAME_EMAIL_INDEX_PROPERTY).getResource().getURI(); Model peopleModel = utilities.getModel(peopleUri); List<VCard> vcards = new ArrayList<>(); ResIterator subjects = peopleModel.listSubjects(); while (subjects.hasNext()) { Resource subject = subjects.nextResource(); Model personModel = utilities.getModel(subject.getURI()); Resource personResource = SolidUtilities.getResource(subject.getURI(), personModel); if (personResource == null) { throw new IllegalStateException(subject.getURI() + " not found in " + subject.toString()); } vcards.add(parsePerson(personResource)); } return vcards; }
private static Resource[] subjectsTypes(Model model) { Set<Resource> types = new HashSet<>(); ResIterator rs = model.listSubjects(); while (rs.hasNext()) { Resource r = rs.nextResource(); Statement s = type(r); if (s != null) { types.add(s.getObject().asResource()); } } return types.toArray(new Resource[0]); }
protected void writeRDFStatements( Model model, PrintWriter writer ) { ResIterator rIter = model.listSubjects(); while (rIter.hasNext()) writeRDFStatements( model, rIter.nextResource(), writer ); }
protected void writeRDFStatements( Model model, PrintWriter writer ) { ResIterator rIter = model.listSubjects(); while (rIter.hasNext()) writeRDFStatements( model, rIter.nextResource(), writer ); }
private List<Resource> getPortal1s(Model model) { List<Resource> portals = new ArrayList<Resource>(); try { model.enterCriticalSection(Lock.READ); ResIterator portalIt = model.listResourcesWithProperty( RDF.type, PORTAL); while (portalIt.hasNext()) { Resource portal = portalIt.nextResource(); if ("portal1".equals(portal.getLocalName())) { portals.add(portal); } } } finally { model.leaveCriticalSection(); } return portals; }
private Set<String> findRootIdentifiers(Model model, TypeConfig targetName) { Set<String> identifiers = new HashSet<>(); Model currentmodel = ModelFactory.createDefaultModel(); Resource res = currentmodel.createResource(targetName.getId()); Property property = currentmodel.createProperty(RDF_TYPE); ResIterator iterator = model.listResourcesWithProperty(property, res); while (iterator.hasNext()) { identifiers.add(iterator.nextResource().toString()); } return identifiers; }
private Set<String> findRootIdentifiers(Model model, TypeConfig targetName) { Set<String> identifiers = new HashSet<>(); Model currentmodel = ModelFactory.createDefaultModel(); Resource res = currentmodel.createResource(targetName.getId()); Property property = currentmodel.createProperty(RDF_TYPE); ResIterator iterator = model.listResourcesWithProperty(property, res); while (iterator.hasNext()) { identifiers.add(iterator.nextResource().toString()); } return identifiers; }
/** * Get the won node URI from a {@link Dataset} * * @param ds Dataset which holds won node information * @return */ private String getWonNodeUriFromDataset(Dataset ds) { if (ds.listNames().hasNext()) { Model model = ds.getNamedModel(ds.listNames().next()); if (model.listSubjectsWithProperty(WON.HAS_URI_PATTERN_SPECIFICATION).hasNext()) { return model.listSubjectsWithProperty(WON.HAS_URI_PATTERN_SPECIFICATION).nextResource().toString(); } } return null; }
private void processModel(Model baseModel) throws IOException { writeLine("{"); boolean first = true; ResIterator subjectIterator = baseModel.listSubjects(); while (subjectIterator.hasNext()) { if (!first) { writeLine(","); } first = false; Resource subjectResource = subjectIterator.nextResource(); processSubject(subjectResource); } writeLine(""); writeLine("}"); }
/** * Test that a transitive reduction is complete. * Assumes test graph has no cycles (other than the trivial * identity ones). */ public void doTestTransitiveReduction(Model model, Property dp) { InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model); for (ResIterator i = im.listSubjects(); i.hasNext();) { Resource base = i.nextResource(); List<RDFNode> directLinks = new ArrayList<>(); for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) { directLinks.add(j.next()); } for (int n = 0; n < directLinks.size(); n++) { Resource d1 = (Resource)directLinks.get(n); for (int m = n+1; m < directLinks.size(); m++) { Resource d2 = (Resource)directLinks.get(m); if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) { assertTrue("Triangle discovered in transitive reduction", false); } } } } }
/** * Test that a transitive reduction is complete. * Assumes test graph has no cycles (other than the trivial * identity ones). */ public void doTestTransitiveReduction(Model model, Property dp) { InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model); for (ResIterator i = im.listSubjects(); i.hasNext();) { Resource base = i.nextResource(); List<RDFNode> directLinks = new ArrayList<>(); for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) { directLinks.add(j.next()); } for (int n = 0; n < directLinks.size(); n++) { Resource d1 = (Resource)directLinks.get(n); for (int m = n+1; m < directLinks.size(); m++) { Resource d2 = (Resource)directLinks.get(m); if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) { assertTrue("Triangle discovered in transitive reduction", false); } } } } }
protected void writeModel(Model model) { // Needed only for no prefixes, no blank first line. boolean doingFirst = true; ResIterator rIter = listSubjects(model); for (; rIter.hasNext();) { // Subject: // First - it is something we will write out as a structure in an object field? // That is, a RDF list or the object of exactly one statement. Resource subject = rIter.nextResource(); if ( skipThisSubject(subject) ) { if (N3JenaWriter.DEBUG) out.println("# Skipping: " + formatResource(subject)); continue; } // We really are going to print something via writeTriples if (doingFirst) doingFirst = false; else out.println(); writeOneGraphNode(subject) ; } rIter.close(); }
public RmlMappingDocument fromRdf(Model data, Function<RdfResource, Optional<DataSource>> dataSourceFactory) { ResIterator tripleMaps = data.listSubjectsWithProperty(data.createProperty(NS_RR + "subjectMap")); MappingDocumentBuilder resultBuilder = rmlMappingDocument(); try { while (tripleMaps.hasNext()) { Resource resource = tripleMaps.nextResource(); buildTripleMap(JenaResource.fromModel(data, resource), resultBuilder.withTripleMap(resource.getURI())); } } finally { tripleMaps.close(); } return resultBuilder.build(dataSourceFactory); }
/** * Run all the tests in the manifest * @param manifestFile the name of the manifest file relative to baseDir * @param log set to true to enable derivation logging * @param stats set to true to log performance statistics * @return true if all the tests pass * @throws IOException if one of the test files can't be found */ public boolean runTests(String manifestFile, boolean log, boolean stats) throws IOException { // Load up the manifest Model manifest = FileManager.get().loadModel(baseDir + manifestFile); ResIterator tests = manifest.listResourcesWithProperty(RDF.type, PositiveEntailmentTest); while (tests.hasNext()) { Resource test = tests.nextResource(); if (!runTest(test, log, stats)) return false; } tests = manifest.listResourcesWithProperty(RDF.type, NegativeEntailmentTest); while (tests.hasNext()) { Resource test = tests.nextResource(); if (!runTest(test, log, stats)) return false; } return true; }
private void processIterator( final ResIterator rIter, final boolean[] subjf ) { for (int i = 0; i < num; i++) { subjf[i] = false; } while (rIter.hasNext()) { final Resource subj = rIter.nextResource(); Boolean found = false; for (int i = 0; i < num; i++) { if (subj.equals(subject[i])) { found = true; Assert.assertFalse("Should not have found " + subject[i] + " already", subjf[i]); subjf[i] = true; } } Assert.assertTrue("Should have found " + subj, found); } }
protected void writeModel(Model model) { // Needed only for no prefixes, no blank first line. boolean doingFirst = true; ResIterator rIter = listSubjects(model); for (; rIter.hasNext();) { // Subject: // First - it is something we will write out as a structure in an object field? // That is, a RDF list or the object of exactly one statement. Resource subject = rIter.nextResource(); if ( skipThisSubject(subject) ) { if (N3JenaWriter.DEBUG) out.println("# Skipping: " + formatResource(subject)); continue; } // We really are going to print something via writeTriples if (doingFirst) doingFirst = false; else out.println(); writeOneGraphNode(subject) ; } rIter.close(); }
private void processIterator( final ResIterator rIter, final boolean[] subjf ) { for (int i = 0; i < num; i++) { subjf[i] = false; } while (rIter.hasNext()) { final Resource subj = rIter.nextResource(); Boolean found = false; for (int i = 0; i < num; i++) { if (subj.equals(subject[i])) { found = true; Assert.assertFalse("Should not have found " + subject[i] + " already", subjf[i]); subjf[i] = true; } } Assert.assertTrue("Should have found " + subj, found); } }
/** * Run all the tests in the manifest * @param manifestFile the name of the manifest file relative to baseDir * @param log set to true to enable derivation logging * @param stats set to true to log performance statistics * @return true if all the tests pass * @throws IOException if one of the test files can't be found */ public boolean runTests(String manifestFile, boolean log, boolean stats) throws IOException { // Load up the manifest Model manifest = FileManager.get().loadModel(baseDir + manifestFile); ResIterator tests = manifest.listResourcesWithProperty(RDF.type, PositiveEntailmentTest); while (tests.hasNext()) { Resource test = tests.nextResource(); if (!runTest(test, log, stats)) return false; } tests = manifest.listResourcesWithProperty(RDF.type, NegativeEntailmentTest); while (tests.hasNext()) { Resource test = tests.nextResource(); if (!runTest(test, log, stats)) return false; } return true; }
/** * Report of functor literals leaking out of inference graphs and raising CCE * in iterators. */ public void testFunctorCCE() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/cceTest.owl"); InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base); // boolean b = anyInstancesOfNothing(test); ResIterator rIter = test.listSubjects(); while (rIter.hasNext()) { // Resource res = rIter.nextResource(); } }
/** * Report of functor literals leaking out of inference graphs and raising CCE * in iterators. */ public void testFunctorCCE() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/cceTest.owl"); InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base); // boolean b = anyInstancesOfNothing(test); ResIterator rIter = test.listSubjects(); while (rIter.hasNext()) { // Resource res = rIter.nextResource(); } }