Java Code Examples for org.apache.jena.rdf.model.Resource#getPropertyResourceValue()
The following examples show how to use
org.apache.jena.rdf.model.Resource#getPropertyResourceValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClosedConstraintExecutor.java From shacl with Apache License 2.0 | 5 votes |
ClosedConstraintExecutor(Constraint constraint) { this.closed = constraint.getShapeResource().hasProperty(SH.closed, JenaDatatypes.TRUE); RDFList list = JenaUtil.getListProperty(constraint.getShapeResource(), SH.ignoredProperties); if(list != null) { list.iterator().forEachRemaining(allowedProperties::add); } for(Resource ps : JenaUtil.getResourceProperties(constraint.getShapeResource(), SH.property)) { Resource path = ps.getPropertyResourceValue(SH.path); if(path.isURIResource()) { allowedProperties.add(path); } } }
Example 2
Source File: OrConstraintExecutor.java From shacl with Apache License 2.0 | 5 votes |
OrConstraintExecutor(Constraint constraint) { super(constraint); if(hasOnlyDatatypeConstraints()) { datatypeURIs = new HashSet<String>(); for(Resource shape : shapes) { Resource datatype = shape.getPropertyResourceValue(SH.datatype); datatypeURIs.add(datatype.getURI()); } } }
Example 3
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 5 votes |
private String getPropertyTypes(Resource property) { List<String> types = new LinkedList<>(); for(Resource clas : JenaUtil.getResourceProperties(property, SH.class_)) { types.add(iri(clas)); } for(Resource datatype : JenaUtil.getResourceProperties(property, SH.datatype)) { types.add(iri(datatype)); } for(Resource node : JenaUtil.getResourceProperties(property, SH.node)) { if(node.isURIResource()) { types.add("@" + iri(node)); } } Resource nodeKind = property.getPropertyResourceValue(SH.nodeKind); if(nodeKind != null) { types.add(nodeKind.getLocalName()); } Collections.sort(types); StringBuffer sb = new StringBuffer(); for(int i = 0; i < types.size(); i++) { if(i > 0) { sb.append(" "); } sb.append(types.get(i)); } return sb.toString(); }
Example 4
Source File: ShapePathReaderTest.java From RDFUnit with Apache License 2.0 | 5 votes |
@Parameterized.Parameters(name= "{index}: Path: {1}") public static Collection<Object[]> resources() throws RdfReaderException { Model model = RdfReaderFactory.createResourceReader("/org/aksw/rdfunit/model/readers/shacl/ShapePathReaderTest.ttl").read(); Collection<Object[]> parameters = new ArrayList<>(); Property pathProperty = ResourceFactory.createProperty("http://ex.com/path"); Property pathExprProperty = ResourceFactory.createProperty("http://ex.com/pathExp"); for (Resource node: model.listSubjectsWithProperty(pathProperty).toList()) { Resource path = node.getPropertyResourceValue(pathProperty); String pathExpr = node.getProperty(pathExprProperty).getObject().asLiteral().getLexicalForm(); parameters.add(new Object[] {path, pathExpr}); } return parameters; }
Example 5
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 4 votes |
private String getPathString(Resource property) { Resource path = property.getPropertyResourceValue(SH.path); return SHACLPaths.getPathString(path); }
Example 6
Source File: ShapeReader.java From RDFUnit with Apache License 2.0 | 4 votes |
@Override public Shape read(Resource resource) { checkNotNull(resource); ShapeImpl.ShapeImplBuilder shapeBuilder = ShapeImpl.builder(); shapeBuilder .element(resource) .propertyValuePairSets(PropertyValuePairSet.createFromResource(resource)); Resource path = resource.getPropertyResourceValue(SHACL.path); if (path != null) { shapeBuilder.shaclPath( ShapePathReader.create().read(path) ); } return shapeBuilder.build(); }
Example 7
Source File: ShapePathReader.java From RDFUnit with Apache License 2.0 | 4 votes |
private static Path readPath(Resource resource) { if (resource.isURIResource()) { return new P_Link(resource.asNode()); } if (RdfListUtils.isList(resource)) { return RdfListUtils.getListItemsOrEmpty(resource).stream() .filter(RDFNode::isResource) .map(RDFNode::asResource) .map(ShapePathReader::readPath) .reduce(PathFactory::pathSeq) .orElseThrow(() -> new IllegalArgumentException("Sequence path invalid")); } Resource inverse = resource.getPropertyResourceValue(SHACL.inversePath); if ( inverse != null ) { return PathFactory.pathInverse(readPath(inverse)); } Resource alternate = resource.getPropertyResourceValue(SHACL.alternativePath); if ( alternate != null && RdfListUtils.isList(alternate)) { return RdfListUtils.getListItemsOrEmpty(alternate).stream() .filter(RDFNode::isResource) .map(RDFNode::asResource) .map(ShapePathReader::readPath) .reduce(PathFactory::pathAlt) .orElseThrow(() -> new IllegalArgumentException("Sequence path invalid")); } Resource zeroOrOne = resource.getPropertyResourceValue(SHACL.zeroOrOnePath); if ( zeroOrOne != null ) { return PathFactory.pathZeroOrOne(readPath(zeroOrOne)); } Resource zeroOrMore = resource.getPropertyResourceValue(SHACL.zeroOrMorePath); if ( zeroOrMore != null ) { return PathFactory.pathZeroOrMore1(readPath(zeroOrMore)); } Resource oneOrMore = resource.getPropertyResourceValue(SHACL.oneOrMorePath); if ( oneOrMore != null ) { return PathFactory.pathOneOrMore1(readPath(oneOrMore)); } throw new IllegalArgumentException("Wrong SHACL Path"); }
Example 8
Source File: JenaUtil.java From shacl with Apache License 2.0 | 2 votes |
/** * Gets the "first" declared rdfs:range of a given property. * If multiple ranges exist, the behavior is undefined. * Note that this method does not consider ranges defined on * super-properties. * @param property the property to get the range of * @return the "first" range Resource or null */ public static Resource getFirstDirectRange(Resource property) { return property.getPropertyResourceValue(RDFS.range); }
Example 9
Source File: JenaUtil.java From shacl with Apache License 2.0 | 2 votes |
/** * Gets the "first" type of a given Resource. * @param instance the instance to get the type of * @return the type or null */ public static Resource getType(Resource instance) { return instance.getPropertyResourceValue(RDF.type); }