Java Code Examples for org.apache.jena.graph.NodeFactory#getType()
The following examples show how to use
org.apache.jena.graph.NodeFactory#getType() .
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: RDFPatchReaderBinary.java From rdf-delta with Apache License 2.0 | 6 votes |
public static Node fromThrift(RDF_Term term) { if ( term.isSetIri() ) return NodeFactory.createURI(term.getIri().getIri()); if ( term.isSetBnode() ) return NodeFactory.createBlankNode(term.getBnode().getLabel()); if ( term.isSetLiteral() ) { RDF_Literal lit = term.getLiteral(); String lex = lit.getLex(); String dtString = null; if ( lit.isSetDatatype() ) dtString = lit.getDatatype(); RDFDatatype dt = NodeFactory.getType(dtString); String lang = lit.getLangtag(); return NodeFactory.createLiteral(lex, lang, dt); } throw new PatchException("No conversion to a Node: "+term.toString()); }
Example 2
Source File: RDFNodeFactory.java From Processor with Apache License 2.0 | 6 votes |
public static final RDFNode createTyped(String value, Resource valueType) { if (value == null) throw new IllegalArgumentException("Param value cannot be null"); // without value type, return default xsd:string value if (valueType == null) return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring); // if value type is from XSD namespace, value is treated as typed literal with XSD datatype if (valueType.getNameSpace().equals(XSD.getURI())) { RDFDatatype dataType = NodeFactory.getType(valueType.getURI()); return ResourceFactory.createTypedLiteral(value, dataType); } // otherwise, value is treated as URI resource else return ResourceFactory.createResource(value); }
Example 3
Source File: DatatypeConstraintExecutor.java From shacl with Apache License 2.0 | 5 votes |
@Override public void executeConstraint(Constraint constraint, ValidationEngine engine, Collection<RDFNode> focusNodes) { long startTime = System.currentTimeMillis(); RDFNode datatypeNode = constraint.getParameterValue(); String datatypeURI = datatypeNode.asNode().getURI(); RDFDatatype datatype = NodeFactory.getType(datatypeURI); String message = "Value must be a valid literal of type " + ((Resource)datatypeNode).getLocalName(); for(RDFNode focusNode : focusNodes) { for(RDFNode valueNode : engine.getValueNodes(constraint, focusNode)) { validate(constraint, engine, message, datatypeURI, datatype, focusNode, valueNode); } engine.checkCanceled(); } addStatistics(constraint, startTime); }