Java Code Examples for org.apache.jena.rdf.model.Resource#isAnon()
The following examples show how to use
org.apache.jena.rdf.model.Resource#isAnon() .
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: AbstractSPARQLExecutor.java From shacl with Apache License 2.0 | 6 votes |
protected AbstractSPARQLExecutor(Constraint constraint) { this.queryString = getSPARQL(constraint); try { this.query = ARQFactory.get().createQuery(queryString); Resource path = constraint.getShapeResource().getPath(); if(path != null && path.isAnon()) { String pathString = SHACLPaths.getPathString(constraint.getShapeResource().getPropertyResourceValue(SH.path)); query = SPARQLSubstitutions.substitutePaths(query, pathString, constraint.getShapeResource().getModel()); } } catch(QueryParseException ex) { throw new SHACLException("Invalid SPARQL constraint (" + ex.getLocalizedMessage() + "):\n" + queryString); } if(!query.isSelectType()) { throw new IllegalArgumentException("SHACL constraints must be SELECT queries"); } }
Example 2
Source File: Shape.java From shacl with Apache License 2.0 | 6 votes |
public Shape(ShapesGraph shapesGraph, SHShape shape) { this.shape = shape; this.shapesGraph = shapesGraph; Resource path = shape.getPath(); this.path = path; this.deactivated = shape.isDeactivated(); this.severity = shape.getSeverity(); if(path != null) { if(path.isAnon()) { jenaPath = (Path) SHACLPaths.getJenaPath(SHACLPaths.getPathString(path), path.getModel()); } else { predicate = JenaUtil.asProperty(path); } } else { nodeShape = true; } collectTargets(); }
Example 3
Source File: SPDXFile.java From tools with Apache License 2.0 | 6 votes |
/** * @param r1 * @param r2 * @return */ private boolean resourcesEqual(Resource r1, Resource r2) { if (r2 == null) { return false; } if (r1.isAnon()) { if (!r2.isAnon()) { return false; } return r1.getId().equals(r2.getId()); } else { if (!r2.isURIResource()) { return false; } return r1.getURI().equals(r2.getURI()); } }
Example 4
Source File: RdfModelObject.java From tools with Apache License 2.0 | 6 votes |
/** * Returns true if the two resources represent the same node * @param r1 * @param r2 * @return */ protected boolean resourcesEqual(Resource r1, Resource r2) { if (r1 == null) { return (r2 == null); } if (r2 == null) { return false; } if (r1.isAnon()) { if (!r2.isAnon()) { return false; } return r1.getId().equals(r2.getId()); } else { if (!r2.isURIResource()) { return false; } return r1.getURI().equals(r2.getURI()); } }
Example 5
Source File: ClassHierarchyLoader.java From gerbil with GNU Affero General Public License v3.0 | 6 votes |
protected Set<Resource> getClasses(Model readModel) { ResIterator iterator = readModel.listSubjectsWithProperty(RDF.type, RDFS.Class); Resource r; Set<Resource> classes = new HashSet<Resource>(); while (iterator.hasNext()) { r = iterator.next(); if (!r.isAnon()) { classes.add(r); } } iterator = readModel.listSubjectsWithProperty(RDF.type, OWL.Class); while (iterator.hasNext()) { r = iterator.next(); if (!r.isAnon()) { classes.add(r); } } return classes; }
Example 6
Source File: DB2Closure.java From quetzal with Eclipse Public License 2.0 | 6 votes |
private static void closureNoTest(Resource r, Model closureBlob, Collection<Resource> visited, ClosureTest test, Collection<String> resources) { visited.add(r); String gid = ((DB2Graph) r.getModel().getGraph()).getGraphID(); String key = null; if (r.isAnon()) { key = gid + ":" + r.getId(); } else { key = gid + ":" + r.getURI(); } if (resources.contains(key)) { return; } resources.add(key); StmtIterator sIter = r.listProperties(); for (; sIter.hasNext();) { Statement stmt = sIter.nextStatement(); closure(stmt, closureBlob, visited, test, resources); } }
Example 7
Source File: RDFLabels.java From shacl with Apache License 2.0 | 5 votes |
/** * Gets the label for a given Resource. * @param resource the Resource to get the label of * @return the label (never null) */ public String getLabel(Resource resource) { if(resource.isURIResource() && resource.getModel() != null) { String qname = resource.getModel().qnameFor(resource.getURI()); if(qname != null) { return qname; } else { return "<" + resource.getURI() + ">"; } } else if(resource.isAnon() && resource.getModel() != null && resource.hasProperty(RDF.first)) { StringBuffer buffer = new StringBuffer("["); Iterator<RDFNode> members = resource.as(RDFList.class).iterator(); while(members.hasNext()) { RDFNode member = members.next(); buffer.append(RDFLabels.get().getNodeLabel(member)); if(members.hasNext()) { buffer.append(", "); } } buffer.append("]"); return buffer.toString(); } else if(resource.isAnon()) { return getBlankNodeLabel(resource); } else { return resource.toString(); } }
Example 8
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 5 votes |
private void writeNestedShapes(IndentedWriter out, Resource subject) { for(Resource node : JenaUtil.getResourceProperties(subject, SH.node)) { if(node.isAnon()) { writeShapeBody(out, node); } } }
Example 9
Source File: PathExpression.java From shacl with Apache License 2.0 | 5 votes |
public PathExpression(RDFNode expr, Resource path, NodeExpression input) { super(expr, input); this.path = path; if(path.isAnon()) { pathString = SHACLPaths.getPathString(path); Path jenaPath = (Path) SHACLPaths.getJenaPath(pathString, path.getModel()); eval = new PathEvaluator(jenaPath, expr.getModel()); } else { pathString = FmtUtils.stringForRDFNode(path); eval = new PathEvaluator(JenaUtil.asProperty(path)); } eval.setInput(input); }
Example 10
Source File: Skolemizer.java From Processor with Apache License 2.0 | 5 votes |
public Model build(Model model) { if (model == null) throw new IllegalArgumentException("Model cannot be null"); Map<Resource, String> resourceURIMap = new HashMap<>(); ResIterator resIt = model.listSubjects(); try { while (resIt.hasNext()) { Resource resource = resIt.next(); if (resource.isAnon()) { URI uri = build(resource); if (uri != null) resourceURIMap.put(resource, uri.toString()); } } } finally { resIt.close(); } Iterator<Map.Entry<Resource, String>> entryIt = resourceURIMap.entrySet().iterator(); while (entryIt.hasNext()) { Map.Entry<Resource, String> entry = entryIt.next(); ResourceUtils.renameResource(entry.getKey(), entry.getValue()); } return model; }
Example 11
Source File: RDFToTopicMapConverter.java From ontopia with Apache License 2.0 | 5 votes |
private LocatorIF getTopicIndicator(Resource subject, String property, Model model) throws JenaException, MalformedURLException { Property prop = model.getProperty(property); NodeIterator it = model.listObjectsOfProperty(subject, prop); while (it.hasNext()) { Resource obj = (Resource) it.next(); if (obj.isAnon()) continue; // FIXME: is this really ok? return new URILocator(obj.getURI()); } return null; }
Example 12
Source File: DB2DescribeHandler.java From quetzal with Eclipse Public License 2.0 | 5 votes |
private static Resource otherModel(Resource r, Model model) { if (r.isURIResource()) return model.createResource(r.getURI()); if (r.isAnon()) return model.createResource(r.getId()); return r; }
Example 13
Source File: DB2Closure.java From quetzal with Eclipse Public License 2.0 | 4 votes |
public boolean traverse(Resource r) { return r.isAnon(); }