Java Code Examples for org.apache.jena.graph.Graph#contains()

The following examples show how to use org.apache.jena.graph.Graph#contains() . 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: ClassMetadata.java    From shacl with Apache License 2.0 5 votes vote down vote up
private void addGroupProperties(Node nodeShape, Graph graph, Node systemPredicate) {
	ExtendedIterator<Triple> it = graph.find(nodeShape, systemPredicate, Node.ANY);
	while(it.hasNext()) {
		Node propertyShape = it.next().getObject();
		if(!graph.contains(propertyShape, SH.deactivated.asNode(), JenaDatatypes.TRUE.asNode())) {
			Node group = JenaNodeUtil.getObject(propertyShape, SH.group.asNode(), graph);
			if(group != null) {
				Node path = JenaNodeUtil.getObject(propertyShape, SH.path.asNode(), graph);
				if(path != null) {
					Set<PathMetadata> paths = groupPaths.get(group);
					if(paths == null) {
						paths = new HashSet<>();
						groupPaths.put(group, paths);
					}
					if(path.isURI()) {
						paths.add(new PathMetadata(path, false));
					}
					else {
						Node inverse = JenaNodeUtil.getObject(path, SH.inversePath.asNode(), graph);
						if(inverse != null && inverse.isURI()) {
							paths.add(new PathMetadata(inverse, true));
						}
					}
				}
			}
		}
	}
}
 
Example 2
Source File: OWLClassPropertyMetadataPlugin.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
public void init(ClassPropertyMetadata cpm, Node classNode, Graph graph) {
	ExtendedIterator<Triple> it = graph.find(classNode, RDFS.subClassOf.asNode(), Node.ANY);
	while(it.hasNext()) {
		Node superClass = it.next().getObject();
		if(superClass.isBlank() && graph.contains(superClass, OWL.onProperty.asNode(), cpm.getPredicate())) {
			if(cpm.getLocalRange() == null) {
				Node localRange = JenaNodeUtil.getObject(superClass, OWL.allValuesFrom.asNode(), graph);
				if(localRange != null) {
					cpm.setLocalRange(localRange);
					it.close();
					break;
				}
			}
			if(cpm.getMaxCount() == null) {
				Node maxCountNode = JenaNodeUtil.getObject(superClass, OWL.maxCardinality.asNode(), graph);
				if(maxCountNode == null) {
					maxCountNode = JenaNodeUtil.getObject(superClass, OWL.cardinality.asNode(), graph);
				}
				if(maxCountNode != null && maxCountNode.isLiteral()) {
					Object value = maxCountNode.getLiteralValue();
					if(value instanceof Number) {
						cpm.setMaxCount(((Number) value).intValue());
					}
				}
			}
		}
	}
}
 
Example 3
Source File: ClassPropertyMetadata.java    From shacl with Apache License 2.0 5 votes vote down vote up
public boolean hasMatchingPath(Node propertyShape, Graph graph) {
	if(inverse) {
		Node path = JenaNodeUtil.getObject(propertyShape, SH.path.asNode(), graph);
		if(path != null && path.isBlank()) {
			return predicate.equals(JenaNodeUtil.getObject(path, SH.inversePath.asNode(), graph));
		}
		else {
			return false;
		}
	}
	else {
		return graph.contains(propertyShape, SH.path.asNode(), predicate);
	}
}
 
Example 4
Source File: SHACLUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
public static boolean exists(Graph graph) {
	if(graph instanceof OptimizedMultiUnion) {
		return ((OptimizedMultiUnion)graph).getIncludesSHACL();
	}
	else {
    	return graph != null &&
        		SH.NS.equals(graph.getPrefixMapping().getNsPrefixURI(SH.PREFIX)) && 
        		graph.contains(SH.Shape.asNode(), RDF.type.asNode(), Node.ANY);
	}
}
 
Example 5
Source File: ClassPropertyMetadata.java    From shacl with Apache License 2.0 4 votes vote down vote up
private void initFromShape(Node shape, Graph graph) {
	if(!graph.contains(shape, SH.deactivated.asNode(), JenaDatatypes.TRUE.asNode())) {
		initFromShape(shape, SH.property.asNode(), graph);
		initFromShape(shape, SH.parameter.asNode(), graph);
	}
}
 
Example 6
Source File: ClassPropertyMetadata.java    From shacl with Apache License 2.0 4 votes vote down vote up
private void initFromShape(Node shape, Node systemPredicate, Graph graph) {
	ExtendedIterator<Triple> it = graph.find(shape, systemPredicate, Node.ANY);
	while(it.hasNext()) {
		Node propertyShape = it.next().getObject();
		if(!propertyShape.isLiteral()) {
			if(hasMatchingPath(propertyShape, graph)) {
				if(!graph.contains(propertyShape, SH.deactivated.asNode(), JenaDatatypes.TRUE.asNode())) {
					if(description == null) {
						description = JenaNodeUtil.getObject(propertyShape, SH.description.asNode(), graph);
					}
					if(editWidget == null) {
						editWidget = JenaNodeUtil.getObject(propertyShape, TOSH.editWidget.asNode(), graph);
					}
					if(localRange == null) {
						if(inverse) {
							// Maybe: support inverse ranges
						}
						else {
							localRange = SHACLUtil.walkPropertyShapesHelper(propertyShape, graph);
						}
					}
					if(maxCount == null) {
						Node maxCountNode = JenaNodeUtil.getObject(propertyShape, SH.maxCount.asNode(), graph);
						if(maxCountNode != null && maxCountNode.isLiteral()) {
							Object value = maxCountNode.getLiteralValue();
							if(value instanceof Number) {
								maxCount = ((Number) value).intValue();
							}
						}
					}
					if(name == null) {
						name = JenaNodeUtil.getObject(propertyShape, SH.name.asNode(), graph);
					}
					if(order == null) {
						order = JenaNodeUtil.getObject(propertyShape, SH.order.asNode(), graph);
					}
					if(viewWidget == null) {
						viewWidget = JenaNodeUtil.getObject(propertyShape, TOSH.viewWidget.asNode(), graph);
					}
				}
			}
		}
	}
}