private void addShapesAsObjectsOf(Model model, ImmutableSet.Builder<Resource> shapes) { shapesAsObjectsOf.forEach(r -> model.listObjectsOfProperty(r).toSet().stream() .filter(RDFNode::isResource) .map(RDFNode::asResource) .forEach(shapes::add)); }
private void addShapesAsObjectsOf(Model model, ImmutableSet.Builder<Resource> shapes) { shapesAsObjectsOf.forEach(r -> model.listObjectsOfProperty(r).toSet().stream() .filter(RDFNode::isResource) .map(RDFNode::asResource) .forEach(shapes::add)); }
@Override public Set<Resource> getUsedProperties() { Resource path = getPathAsRdf(); if (path.isURIResource()) { return ImmutableSet.of(path); } else { return path.getModel().listObjects() .toSet().stream() .filter(RDFNode::isURIResource) .map(RDFNode::asResource) .filter(r -> !r.getNameSpace().equals(RDF.getURI())) .filter(r -> !r.getNameSpace().equals(SHACL.namespace)) .collect(Collectors.toSet()); } }
@Override public Set<Resource> getUsedProperties() { Resource path = getPathAsRdf(); if (path.isURIResource()) { return ImmutableSet.of(path); } else { return path.getModel().listObjects() .toSet().stream() .filter(RDFNode::isURIResource) .map(RDFNode::asResource) .filter(r -> !r.getNameSpace().equals(RDF.getURI())) .filter(r -> !r.getNameSpace().equals(SHACL.namespace)) .collect(Collectors.toSet()); } }
private Set<String> getTypes(Model m, String uri) { Set<String> typeUris = new HashSet<>(); for (RDFNode typeNode : m.listObjectsOfProperty(m.createResource(uri), RDF.type).toSet()) { if (typeNode.isURIResource()) { typeUris.add(typeNode.asResource().getURI()); } } return typeUris; }
private static <T> Class<? extends T> determineConcreteClass( LockableModel locking, String uri, Class<T> resultClass) throws InvalidConfigurationRdfException { Set<Class<? extends T>> concreteClasses = new HashSet<>(); try (LockedModel m = locking.read()) { for (RDFNode node : m .listObjectsOfProperty(createResource(uri), RDF.type) .toSet()) { if (!node.isURIResource()) { throw typeMustBeUriResource(node); } String typeUri = node.asResource().getURI(); if (!isConcreteClass(typeUri)) { continue; } concreteClasses.add(processTypeUri(typeUri, resultClass)); } } if (concreteClasses.isEmpty()) { throw noConcreteClasses(uri); } if (concreteClasses.size() > 1) { throw tooManyConcreteClasses(uri, concreteClasses); } return concreteClasses.iterator().next(); }
Set<RDFNode> tmp; if(isFwd) { tmp = model.listObjectsOfProperty(start.asResource(), property).toSet(); } else if(start.isResource()) { tmp = new HashSet<RDFNode>(model.listSubjectsWithProperty(property, start).toSet());
@Test public void dataAssertionTest() { _model.read(MiscTests.class.getResourceAsStream("/decimal-int.owl"), null); final Individual entity = _model.getIndividual(NAMESPACE + "/dataAssertion.owl#ENTITY"); final DatatypeProperty value = _model.getDatatypeProperty(NAMESPACE + "/dataAssertion.owl#dataAssertionValue"); Assert.assertTrue(value.isFunctionalProperty()); Assert.assertEquals(1, entity.listPropertyValues(value).toSet().size()); }
@Test public void dataAssertionTest() { _model.read(MiscTests.class.getResourceAsStream("/decimal-int.owl"), null); final Individual entity = _model.getIndividual(NAMESPACE + "/dataAssertion.owl#ENTITY"); final DatatypeProperty value = _model.getDatatypeProperty(NAMESPACE + "/dataAssertion.owl#dataAssertionValue"); Assert.assertTrue(value.isFunctionalProperty()); Assert.assertEquals(1, entity.listPropertyValues(value).toSet().size()); }
private static void confirmEligibilityForResultClass(LockableModel locking, String uri, Class<?> resultClass) throws InvalidConfigurationRdfException { String resultClassUri = toJavaUri(resultClass); try (LockedModel m = locking.read()) { Set<RDFNode> types = // m.listObjectsOfProperty(createResource(uri), RDF.type) .toSet(); for (RDFNode typeNode : types) { if (typeNode.isURIResource()) { String typeUri = typeNode.asResource().getURI(); if (isMatchingJavaUri(resultClassUri, typeUri)) { return; } } } throw noTypeStatementForResultClass(uri, resultClassUri); } }
@Test public void incrementalDeletionTest() { final Individual entity = _model.createIndividual(NAMESPACE + "/dataAssertion.owl#ENTITY", null); final DatatypeProperty property = _model.createDatatypeProperty(NAMESPACE + "/dataAssertion.owl#ENTITY", true); final Statement firstValue = _model.createLiteralStatement(entity, property, "1"); final Statement secondValue = _model.createLiteralStatement(entity, property, "2"); // TODO: prepare registers PelletGraphListener. This implies a different behaviour of the whole graph before and // after the first read operation. Please, delete comment if this is as designed. _model.prepare(); _model.add(firstValue); _model.remove(firstValue); _model.add(secondValue); try { _model.listObjectsOfProperty(property).toSet(); } catch (final InconsistentOntologyException e) { Log.error(_logger, e); Assert.fail("Both values are contained in the knowledge base."); } }
@Test public void incrementalDeletionTest() { final Individual entity = _model.createIndividual(NAMESPACE + "/dataAssertion.owl#ENTITY", null); final DatatypeProperty property = _model.createDatatypeProperty(NAMESPACE + "/dataAssertion.owl#ENTITY", true); final Statement firstValue = _model.createLiteralStatement(entity, property, "1"); final Statement secondValue = _model.createLiteralStatement(entity, property, "2"); // TODO: prepare registers PelletGraphListener. This implies a different behaviour of the whole graph before and // after the first read operation. Please, delete comment if this is as designed. _model.prepare(); _model.add(firstValue); _model.remove(firstValue); _model.add(secondValue); try { _model.listObjectsOfProperty(property).toSet(); } catch (final InconsistentOntologyException e) { Log.error(_logger, e); Assert.fail("Both values are contained in the knowledge base."); } }