Java Code Examples for org.apache.jena.rdf.model.RDFNode#isAnon()
The following examples show how to use
org.apache.jena.rdf.model.RDFNode#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: PatternConstraintExecutor.java From shacl with Apache License 2.0 | 6 votes |
@Override public void executeConstraint(Constraint constraint, ValidationEngine engine, Collection<RDFNode> focusNodes) { long startTime = System.currentTimeMillis(); for(RDFNode focusNode : focusNodes) { for(RDFNode valueNode : engine.getValueNodes(constraint, focusNode)) { if(valueNode.isAnon()) { engine.createValidationResult(constraint, focusNode, valueNode, () -> "Blank node cannot match pattern"); } else { String str = NodeFunctions.str(valueNode.asNode()); if(!pattern.matcher(str).find()) { engine.createValidationResult(constraint, focusNode, valueNode, () -> "Value does not match pattern \"" + this.patternString + "\""); } } } engine.checkCanceled(); } addStatistics(constraint, startTime); }
Example 2
Source File: AbstractLengthConstraintExecutor.java From shacl with Apache License 2.0 | 5 votes |
private void validate(Constraint constraint, ValidationEngine engine, String message, int length, RDFNode focusNode, RDFNode valueNode) { if(valueNode.isAnon() || (valueNode.isURIResource() && isInvalidLength(valueNode.asNode().getURI().length(), length)) || (valueNode.isLiteral() && isInvalidLength(valueNode.asNode().getLiteralLexicalForm().length(), length))) { engine.createValidationResult(constraint, focusNode, valueNode, () -> message); } }
Example 3
Source File: SHFactory.java From shacl with Apache License 2.0 | 5 votes |
/** * Checks if a given node is a NodeShape. * This is just an approximation based on a couple of hard-coded properties. * @param node the node to test * @return true if node is a NodeShape */ public static boolean isNodeShape(RDFNode node) { if(node instanceof Resource) { if(JenaUtil.hasIndirectType((Resource)node, SH.NodeShape)) { return true; } else if(node.isAnon() && !((Resource)node).hasProperty(RDF.type)) { if(node.getModel().contains(null, SH.node, node)) { return true; } } } return false; }
Example 4
Source File: HtmlTriplePatternFragmentWriterImpl.java From Server.Java with MIT License | 4 votes |
/** * * @param outputStream * @param datasource * @param fragment * @param tpfRequest * @throws IOException * @throws TemplateException */ @Override public void writeFragment(ServletOutputStream outputStream, IDataSource datasource, ITriplePatternFragment fragment, ITriplePatternFragmentRequest tpfRequest) throws IOException, TemplateException{ Map data = new HashMap(); // base.ftl.html data.put("assetsPath", "assets/"); data.put("header", datasource.getTitle()); data.put("date", new Date()); // fragment.ftl.html data.put("datasourceUrl", tpfRequest.getDatasetURL()); data.put("datasource", datasource); // Parse controls to template variables StmtIterator controls = fragment.getControls(); while (controls.hasNext()) { Statement control = controls.next(); String predicate = control.getPredicate().getURI(); RDFNode object = control.getObject(); if (!object.isAnon()) { String value = object.isURIResource() ? object.asResource().getURI() : object.asLiteral().getLexicalForm(); data.put(predicate.replaceFirst(HYDRA, ""), value); } } // Add metadata data.put("totalEstimate", fragment.getTotalSize()); data.put("itemsPerPage", fragment.getMaxPageSize()); // Add triples and datasources List<Statement> triples = fragment.getTriples().toList(); data.put("triples", triples); data.put("datasources", getDatasources()); // Calculate start and end triple number Long start = ((tpfRequest.getPageNumber() - 1) * fragment.getMaxPageSize()) + 1; data.put("start", start); data.put("end", start + (triples.size() < fragment.getMaxPageSize() ? triples.size() : fragment.getMaxPageSize())); // Compose query object Map query = new HashMap(); query.put("subject", !tpfRequest.getSubject().isVariable() ? tpfRequest.getSubject().asConstantTerm() : ""); query.put("predicate", !tpfRequest.getPredicate().isVariable() ? tpfRequest.getPredicate().asConstantTerm() : ""); query.put("object", !tpfRequest.getObject().isVariable() ? tpfRequest.getObject().asConstantTerm() : ""); data.put("query", query); // Get the template (uses cache internally) Template temp = datasource instanceof IndexDataSource ? indexTemplate : datasourceTemplate; // Merge data-model with template temp.process(data, new OutputStreamWriter(outputStream)); }
Example 5
Source File: RdfListUtils.java From RDFUnit with Apache License 2.0 | 4 votes |
public static boolean isList(RDFNode node) { return node.isAnon() && node.canAs(RDFList.class); }