/** 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())); } ); } }
StmtIterator nameIterator = r.listProperties(VCARD4.hasName); while (nameIterator.hasNext()) { Statement nameStatement = nameIterator.nextStatement(); Resource structuredNameResource = nameStatement.getResource(); StructuredName structuredName = new StructuredName(); structuredNameResource.listProperties(VCARD4.hasHonorificPrefix).forEachRemaining( prefix -> structuredName.getPrefixes().add(prefix.getString()) ); structuredNameResource.listProperties(VCARD4.hasHonorificSuffix).forEachRemaining( suffix -> structuredName.getSuffixes().add(suffix.getString()) ); structuredNameResource.listProperties(VCARD4.hasAdditionalName).forEachRemaining( additional -> structuredName.getAdditionalNames().add(additional.getString()) ); r.listProperties(VCARD4.hasEmail).forEachRemaining(emailStatement -> { Resource emailResource = emailStatement.getResource(); if (emailResource.isResource()) { Statement valueStatement = getValueStatement(emailResource); String mailTo = valueStatement.getObject().toString(); Matcher matcher = MAIL_TO_PATTERN.matcher(mailTo); checkState(matcher.matches(), "%s mail to address doesn't match", mailTo); Email email = new Email(emailAddress); if (emailResource.hasProperty(RDF.type)) { emailResource.listProperties(RDF.type).forEachRemaining(typeProperty -> email.getTypes().add(EmailType.find(typeProperty.getResource().getLocalName())));
private static void closureNoTest(Resource r, Model closureBlob, Collection<Resource> visited, ClosureTest test) { visited.add(r) ; StmtIterator sIter = r.listProperties() ; for ( ; sIter.hasNext() ; ) { Statement stmt = sIter.nextStatement() ; closure(stmt, closureBlob, visited, test) ; } }
public static void addValueNodes(RDFNode focusNode, Property predicate, Collection<RDFNode> results) { if(focusNode instanceof Resource) { StmtIterator it = ((Resource)focusNode).listProperties(predicate); while(it.hasNext()) { results.add(it.next().getObject()); } } }
public static boolean exactlyOneProperty(Resource r, Property p) { StmtIterator sIter = r.listProperties(p) ; try { if ( !sIter.hasNext() ) throw new PropertyRequiredException(r, p) ; sIter.next() ; if ( sIter.hasNext() ) throw new NotUniqueException(r, p) ; } finally { sIter.close() ; } return true ; }
public static List<RDFNode> multiValue(Resource r, Property p) { List<RDFNode> values = new ArrayList<>() ; StmtIterator sIter = r.listProperties(p) ; while (sIter.hasNext()) { Statement s = sIter.nextStatement() ; values.add(s.getObject()) ; } return values ; }
protected void addExternalContents( List<Content> contents, FileManager fm, Resource root ) { StmtIterator it = root.listProperties( JA.externalContent ); while (it.hasNext()) contents.add( objectAsContent( fm, it.nextStatement() ) ); }
public static void addValueNodes(RDFNode focusNode, Property predicate, Collection<RDFNode> results) { if(focusNode instanceof Resource) { StmtIterator it = ((Resource)focusNode).listProperties(predicate); while(it.hasNext()) { results.add(it.next().getObject()); } } }
@Override public Collection<Class<?>> getApplicableTypes(Resource subject) { Set<Class<?>> result = subject .listProperties(typeProperty).toSet().stream() .map(stmt -> stmt.getObject().asNode()) .map(o -> nodeToClass.get(o)) .filter(o -> o != null) .collect(Collectors.toSet()); return result; }
/** * Helper method - extracts the truth of a boolean configuration * predicate. * @param predicate the predicate to be tested * @param configuration the configuration node * @return null if there is no setting otherwise a Boolean giving the setting value */ public static Boolean checkBinaryPredicate(Property predicate, Resource configuration) { StmtIterator i = configuration.listProperties(predicate); if (i.hasNext()) { return i.nextStatement().getObject().toString().equalsIgnoreCase( "true" ); } else { return null; } }
protected int countProperties(Resource r) { int numProp = 0 ; StmtIterator sIter = r.listProperties() ; for ( ; sIter.hasNext() ; ) { sIter.nextStatement() ; numProp++ ; } sIter.close() ; return numProp ; }
private void addExpressions(Map<Node, List<NodeExpression>> map, Resource ps, Node shapeNode, Property systemPredicate) { map.computeIfAbsent(shapeNode, n -> { List<NodeExpression> exprs = new LinkedList<>(); StmtIterator vit = ps.listProperties(systemPredicate); while(vit.hasNext()) { RDFNode expr = vit.next().getObject(); NodeExpression nodeExpression = NodeExpressionFactory.get().create(expr); exprs.add(nodeExpression); } return exprs; }); }
@Override public Collection<Class<?>> getApplicableTypes(Resource subject) { Set<Class<?>> result = subject .listProperties(typeProperty).toSet().stream() .map(stmt -> stmt.getObject().asNode()) .map(o -> nodeToClass.get(o)) .filter(o -> o != null) .collect(Collectors.toSet()); return result; }
/** * Helper method - extracts the truth of a boolean configuration * predicate. * @param predicate the predicate to be tested * @param configuration the configuration node * @return null if there is no setting otherwise a Boolean giving the setting value */ public static Boolean checkBinaryPredicate(Property predicate, Resource configuration) { StmtIterator i = configuration.listProperties(predicate); if (i.hasNext()) { return i.nextStatement().getObject().toString().equalsIgnoreCase( "true" ); } else { return null; } }
protected int countProperties(Resource r, Property p) { int numProp = 0 ; StmtIterator sIter = r.listProperties(p) ; for ( ; sIter.hasNext() ; ) { sIter.nextStatement() ; numProp++ ; } sIter.close() ; return numProp ; }
public static List<Literal> getLiteralProperties(Resource subject, Property predicate) { List<Literal> results = new LinkedList<>(); StmtIterator it = subject.listProperties(predicate); while(it.hasNext()) { Statement s = it.next(); if(s.getObject().isLiteral()) { results.add(s.getLiteral()); } } return results; }
private List<ShapeTarget> collectPropertyHelper(Resource resourceShape, Property targetProperty, ShapeTargetType shapeTargetType) { return resourceShape.listProperties(targetProperty) .toList().stream() .map(smt -> ShapeTargetCore.create(shapeTargetType, smt.getObject())) .collect(Collectors.toList()); } }
private List<Resource> listObjectPropertyValues(Resource res, Property prop) { List<Resource> values = new ArrayList<Resource>(); StmtIterator stmtIt = res.listProperties(prop); while (stmtIt.hasNext()) { Statement s = stmtIt.nextStatement(); if (s.getObject().isResource()) { values.add(s.getObject().asResource()); } } return values; }
protected int countProperties(Resource r) { int numProp = 0 ; StmtIterator sIter = r.listProperties() ; for ( ; sIter.hasNext() ; ) { sIter.nextStatement() ; numProp++ ; } sIter.close() ; return numProp ; }
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; }