Refine search
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.setFamily(structuredNameResource.getProperty(VCARD4.family_name).getString()); structuredName.setGiven(structuredNameResource.getProperty(VCARD4.given_name).getString()); structuredNameResource.listProperties(VCARD4.hasHonorificPrefix).forEachRemaining( prefix -> structuredName.getPrefixes().add(prefix.getString()) suffix -> structuredName.getSuffixes().add(suffix.getString()) additional -> structuredName.getAdditionalNames().add(additional.getString()) ); vcard.getStructuredNames().add(structuredName); vcard.setOrganization(r.getProperty(VCARD4.organization_name).getString()); Resource emailResource = emailStatement.getResource(); String mailTo = valueStatement.getObject().toString(); Matcher matcher = MAIL_TO_PATTERN.matcher(mailTo); checkState(matcher.matches(), "%s mail to address doesn't match", mailTo);
/** 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())); } ); } }
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 ); } }
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; }
public static List<Resource> getResourceProperties(Resource subject, Property predicate) { List<Resource> results = new LinkedList<>(); StmtIterator it = subject.listProperties(predicate); while(it.hasNext()) { Statement s = it.next(); if(s.getObject().isResource()) { results.add(s.getResource()); } } return results; }
public static void addStatements(Model model, Statement s) { if(!IGNORED_PROPERTIES.contains(s.getPredicate())) { model.add(s); } if(s.getObject().isAnon()) { for(Statement t : s.getModel().listStatements(s.getResource(), null, (RDFNode)null).toList()) { addStatements(model, t); } } }
/** * Utility method for logging */ public static String stmtString(Statement statement) { return " [subject = " + statement.getSubject().getURI() + "] [property = " + statement.getPredicate().getURI() + "] [object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm() + " (Literal)" : ((Resource)statement.getObject()).getURI() + " (Resource)") + "]"; }
public static MetricMapper createDefault() { Model model; try { model = RdfReaderFactory.createResourceReader("/org/aksw/rdfunit/dqv/metricMappings.ttl").read(); } catch (RdfReaderException e) { throw new IllegalArgumentException("Cannot read default metric mappings", e); } ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>(); model.listStatements().toList().stream() .filter(smt -> smt.getPredicate().equals(RDFUNITv.metric)) .filter(smt -> smt.getObject().isResource()) .forEach(smt -> builder.put(smt.getSubject().getURI(), smt.getObject().asResource().getURI())); return new MetricMapper(builder.build()); }
@Override public boolean test(Statement s) { String predicate = s.getPredicate().getURI().substring(s.getPredicate().getURI().lastIndexOf("/")); String object = null; if(s.getObject().isURIResource()){ object = s.getObject().asResource().getURI(); object = object.substring(object.lastIndexOf("/")+1); } else if(s.getObject().isLiteral()){ object = s.getObject().asLiteral().getLexicalForm(); } return isSimiliar2QuestionWord(object) || isSimiliar2QuestionWord(predicate); }
@Test public final void thereIsOneFrench() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, null, "fr"); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 1); Assert.assertTrue(lis.get(0).getObject().toString().equals("texte@fr")); }
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()); } }
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 + "]"; }
protected Rule(Resource resource) { this.resource = resource; order = 0; Statement s = resource.getProperty(SH.order); if(s != null && s.getObject().isLiteral()) { order = (Number) s.getLiteral().getValue(); } }
public static List<Resource> getURIResourceProperties(Resource subject, Property predicate) { List<Resource> results = new LinkedList<>(); StmtIterator it = subject.listProperties(predicate); while(it.hasNext()) { Statement s = it.next(); if(s.getObject().isURIResource()) { results.add(s.getResource()); } } return results; }
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(); }
public Statement getFunctionStatement(Resource resource) { for(Statement sc : resource.listProperties().toList()) { if(RDF.nil.equals(sc.getObject()) || (sc.getObject().isAnon() && sc.getResource().hasProperty(RDF.first))) { return sc; } } return null; } }
public static WonSignatureData extractWonSignatureData(final Resource resource) { Statement stmt = resource.getRequiredProperty(WONMSG.HAS_SIGNED_GRAPH_PROPERTY); String signedGraphUri = stmt.getObject().asResource().getURI(); stmt = resource.getRequiredProperty(SFSIG.HAS_SIGNATURE_VALUE); String signatureValue = stmt.getObject().asLiteral().getString(); stmt = resource.getRequiredProperty(WONMSG.HAS_HASH_PROPERTY); String hash = stmt.getObject().asLiteral().getString(); stmt = resource.getRequiredProperty(WONMSG.HAS_PUBLIC_KEY_FINGERPRINT_PROPERTY); String fingerprint = stmt.getObject().asLiteral().getString(); stmt = resource.getRequiredProperty(SFSIG.HAS_VERIFICATION_CERT); String cert = stmt.getObject().asResource().getURI(); return new WonSignatureData(signedGraphUri, resource.getURI(), signatureValue, hash, fingerprint, cert); }
private Object getValue(RDFNode n, Object outer) throws Exception { if (n.isLiteral()) return n.asLiteral().getValue(); if (n.isResource()) { Statement st = n.asResource().getProperty(pValue); if (st != null) { n = st.getObject(); if (n.isLiteral()) return n.asLiteral().getValue(); return parseAnything(object(), st.getObject(), outer, null); } } throw new ParseException(this, "Unknown value type for node ''{0}''", n); }