if (r.hasProperty(VCARD4.fn)) { vcard.setFormattedName(r.getProperty(VCARD4.fn).getString()); if (r.hasProperty(VCARD4.hasName)) { StmtIterator nameIterator = r.listProperties(VCARD4.hasName); while (nameIterator.hasNext()) { Statement nameStatement = nameIterator.nextStatement(); Resource structuredNameResource = nameStatement.getResource(); StructuredName structuredName = new StructuredName(); if (structuredNameResource.hasProperty(VCARD4.family_name)) { structuredName.setFamily(structuredNameResource.getProperty(VCARD4.family_name).getString()); if (structuredNameResource.hasProperty(VCARD4.given_name)) { structuredName.setGiven(structuredNameResource.getProperty(VCARD4.given_name).getString()); structuredNameResource.listProperties(VCARD4.hasHonorificPrefix).forEachRemaining( structuredNameResource.listProperties(VCARD4.hasHonorificSuffix).forEachRemaining( structuredNameResource.listProperties(VCARD4.hasAdditionalName).forEachRemaining( if (r.hasProperty(VCARD4.organization_name)) { vcard.setOrganization(r.getProperty(VCARD4.organization_name).getString()); if (r.hasProperty(VCARD4.hasEmail)) { r.listProperties(VCARD4.hasEmail).forEachRemaining(emailStatement -> { Resource emailResource = emailStatement.getResource(); if (emailResource.isResource()) { Statement valueStatement = getValueStatement(emailResource);
private String createIndex(String url, String slug, SolidUtilities utilities) throws Exception { Model model = ModelFactory.createDefaultModel(); Resource containerResource = model.createResource("#this"); containerResource.addProperty(RDF.type, model.getResource(VCARD4.NS + "AddressBook")); containerResource.addProperty( model.createProperty(VCARD4.NS + "nameEmailIndex"), model.createResource("people.ttl")); containerResource.addProperty( model.createProperty(VCARD4.NS + "groupIndex"), model.createResource("groups.ttl")); containerResource.addProperty(DC_11.title, slug); return utilities.postContent( url, "index", BASIC_RESOURCE_TYPE, model); }
/** Utility method for debugging model problems. **/ @SuppressWarnings("unused") public static void describeModel(Model model) { model.listSubjects().forEachRemaining( r -> { logger.info(r.toString()); StmtIterator props = r.listProperties(); props.forEachRemaining(p -> logger.info("\t" + p.getPredicate() + " " + p.getObject())); } ); } }
/** Checks if a {@link Resource} is a given type. **/ public static boolean isType(Resource resource, String type) { return resource.listProperties(RDF.type) .toList() .stream() .anyMatch(s -> s.getResource().getURI().equalsIgnoreCase(type)); }
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; }
public void testRoundTripping1() { Model m = ModelFactory.createDefaultModel(); Property startTime = m.createProperty("http://jena.hpl.hp.com/test#startTime"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); Literal xsdlit0 = m.createTypedLiteral(cal); Resource event = m.createResource(); event.addProperty(startTime, xsdlit0); StringWriter sw = new StringWriter(); m.write(sw); StringReader reader = new StringReader(sw.toString()); Model m1 = ModelFactory.createDefaultModel(); m1.read(reader, null); assertTrue( m.isIsomorphicWith(m1) ); Literal xsdlit1 = m1.listStatements().next().getObject().as(Literal.class); assertEquals(xsdlit0, xsdlit1); }
@Test public final void theresOneWithABNodeObject() { Model m = ModelFactory.createDefaultModel(); Resource anon = m.createResource(); m.createResource("http://example").addProperty(RDF.type, anon); StmtIterator it = m.listStatements(null, null, anon); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 1); } }
public void testToStatement() { Triple t = triple( "a P b" ); Statement s = model.asStatement( t ); assertEquals( node( "a" ), s.getSubject().asNode() ); assertEquals( node( "P" ), s.getPredicate().asNode() ); assertEquals( node( "b" ), s.getObject().asNode() ); }
private static List<Resource> equivalentTypes( Resource type ) { List<Resource> types = new ArrayList<>(); types.add( type ); for (StmtIterator it = type.getModel().listStatements( ANY, OWL.equivalentClass, type ); it.hasNext();) types.add( it.nextStatement().getSubject() ); return types; }
/** * Load the premises or conclusions for the test. */ public Model getDoc(Resource test, Property docType) throws IOException { Model result = ModelFactory.createDefaultModel(); StmtIterator si = test.listProperties(docType); while ( si.hasNext() ) { String fname = si.nextStatement().getObject().toString() + ".rdf"; loadFile(fname, result); } return result; }
protected Content getInitialContent( Assembler a, Resource root ) { Model partial = ModelFactory.createDefaultModel(); Resource combined = partial.createResource(); for (StmtIterator it = root.listProperties( JA.initialContent ); it.hasNext();) transferContentProperties( partial, it.nextStatement().getResource(), combined ); return contentFromModel( a, root, partial, combined ); }
public void readKeyReferences(Model model, Set<String> keyRefs) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException { Property typeProp = model.createProperty(Ontology.getSigIri(), "hasVerificationCertificate"); StmtIterator si = model.listStatements(null, typeProp, RdfUtils.EMPTY_RDF_NODE); if (si.hasNext()) { keyRefs.add(si.next().getObject().asResource().getURI()); } }
@Override public StatusTestCaseResult read(final Resource resource) { checkNotNull(resource); TestCaseResult test = TestCaseResultReader.create(DCTerms.description, RDFUNITv.testCaseLogLevel).read(resource); TestCaseResultStatus status = null; for (Statement smt : resource.listProperties(RDFUNITv.resultStatus).toList()) { status = TestCaseResultStatus.resolve(smt.getObject().asResource().getURI()); } checkNotNull(status); return new StatusTestCaseResultImpl(resource, test.getTestCaseUri(), test.getSeverity(), test.getMessage(), test.getTimestamp(), status); } }
public void testAddTypedPropertyBoolean() { final Resource r = model.createResource(); r.addLiteral(RDF.value, true); Assert.assertEquals(model.createTypedLiteral(true), r.getProperty(RDF.value).getLiteral()); }
private String createContainer(String url, String slug, SolidUtilities utilities) throws Exception { Model containerModel = ModelFactory.createDefaultModel(); Resource containerResource = containerModel.createResource(""); containerResource.addProperty(DCTerms.title, slug); return utilities.postContent(url, slug, BASIC_CONTAINER_TYPE, containerModel); }
private Statement lgg(Model model, Statement s1, Statement s2) { Resource s = s1.getSubject().equals(s2.getObject()) ? s1.getSubject() : model.createResource(AnonId.create(s1.getSubject().toString() + s2.getSubject().toString())); RDFNode o = s1.getObject().equals(s2.getObject()) ? s1.getObject() : model.createResource(AnonId.create(s1.getObject().toString() + s2.getObject().toString())); return model.createStatement(s, s1.getPredicate(), o); }
private static String getLabels( Resource r ) { Model m = r.getModel(); String labels = "", prefix = "labels: "; for (StmtIterator it = r.listProperties( RDFS.label ); it.hasNext();) { String label = it.nextStatement().getObject().asNode().toString( m, true ); labels += prefix + label; prefix = ", "; } return labels.equals( "" ) ? getIncomingProperty( r ) : " [" + labels + "]"; }
private synchronized List<String> findContainedEnvelopeUris(final Model envelopeGraph, final String envelopeGraphUri) { Resource envelopeGraphResource = envelopeGraph.getResource(envelopeGraphUri); StmtIterator it = envelopeGraphResource.listProperties(WONMSG.CONTAINS_ENVELOPE); if (it.hasNext()) { List ret = new ArrayList<String>(); while (it.hasNext()) { ret.add(it.nextStatement().getObject().asResource().getURI()); } return ret; } return Collections.emptyList(); }
private static void addToIdList(Statement stmt, Set<AnonId> ids) { if (stmt.getSubject().isAnon()) { ids.add(stmt.getSubject().getId()); } if (stmt.getObject().isAnon()) { ids.add(stmt.getObject().asResource().getId()); } }
private static List<Resource> collectMissingSuperClasses(Resource metaClass, Resource superClass) { List<Resource> toAdd = new ArrayList<Resource>(); StmtIterator it = vocabulary.listStatements(null, RDF.type, metaClass); while (it.hasNext()) { Resource c = it.nextStatement().getSubject(); if (!c.equals(superClass)) { if (c.getProperty(RDFS.subClassOf) == null) { toAdd.add(c); } } } return toAdd; }