use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class FBRuleInfGraph method checkLiteral.
/**
* Check a given literal value for a property against the set of
* known range constraints for it.
* @param prop the property node whose range is under scrutiny
* @param triple the statement whose object value is to be checked.
* @return null if the range is legal, otherwise a ValidityReport.Report
* which describes the problem.
*/
public ValidityReport.Report checkLiteral(Node prop, Triple triple) {
Node value = triple.getObject();
List<RDFDatatype> range = getDTRange().get(prop);
if (range != null) {
if (value.isBlank())
return null;
if (!value.isLiteral()) {
return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value);
}
LiteralLabel ll = value.getLiteral();
for (RDFDatatype dt : range) {
if (!dt.isValidLiteral(ll)) {
return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range " + dt + "that is not compatible with " + value, triple);
}
}
}
return null;
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class ConvertersTest method makeNodeOrPathTest.
@Test
public void makeNodeOrPathTest() {
PrefixMapping pMap = PrefixMapping.Factory.create();
pMap.setNsPrefixes(PrefixMapping.Standard);
Object n = Converters.makeNodeOrPath(null, pMap);
assertEquals(Node.ANY, n);
n = Converters.makeNodeOrPath(RDF.type, pMap);
assertEquals(RDF.type.asNode(), n);
Node n2 = NodeFactory.createBlankNode();
n = Converters.makeNodeOrPath(n2, pMap);
assertEquals(n2, n);
pMap.setNsPrefix("demo", "http://example.com/");
n = Converters.makeNodeOrPath("demo:type", pMap);
assertEquals(NodeFactory.createURI("http://example.com/type"), n);
n = Converters.makeNodeOrPath("<one>", pMap);
assertEquals(NodeFactory.createURI("one"), n);
UUID uuid = UUID.randomUUID();
try {
Converters.makeNodeOrPath(uuid, pMap);
fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException expected) {
// do nothing
}
TypeMapper.getInstance().registerDatatype(new UuidDataType());
n = Converters.makeNodeOrPath(uuid, pMap);
LiteralLabel ll = LiteralLabelFactory.createTypedLiteral(uuid);
assertEquals(NodeFactory.createLiteral(ll), n);
n = Converters.makeNodeOrPath(NodeFactory.createVariable("foo"), pMap);
assertTrue(n instanceof Var);
Node node = (Node) n;
assertTrue(node.isVariable());
assertEquals("foo", node.getName());
n = Converters.makeNodeOrPath("'text'@en", pMap);
assertTrue(n instanceof Node);
node = (Node) n;
assertEquals("text", node.getLiteralLexicalForm());
assertEquals("en", node.getLiteralLanguage());
n = Converters.makeNodeOrPath("<one>/<two>", pMap);
assertTrue(n instanceof Path);
Path pth = (Path) n;
assertEquals("<one>/<two>", pth.toString());
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class ConvertersTest method makeNodeTest.
@Test
public void makeNodeTest() {
PrefixMapping pMap = PrefixMapping.Factory.create();
pMap.setNsPrefixes(PrefixMapping.Standard);
Node n = Converters.makeNode(null, pMap);
assertEquals(Node.ANY, n);
n = Converters.makeNode(RDF.type, pMap);
assertEquals(RDF.type.asNode(), n);
Node n2 = NodeFactory.createBlankNode();
n = Converters.makeNode(n2, pMap);
assertEquals(n2, n);
pMap.setNsPrefix("demo", "http://example.com/");
n = Converters.makeNode("demo:type", pMap);
assertEquals(NodeFactory.createURI("http://example.com/type"), n);
n = Converters.makeNode("<one>", pMap);
assertEquals(NodeFactory.createURI("one"), n);
UUID uuid = UUID.randomUUID();
try {
Converters.makeNode(uuid, pMap);
fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException expected) {
// do nothing
}
TypeMapper.getInstance().registerDatatype(new UuidDataType());
n = Converters.makeNode(uuid, pMap);
LiteralLabel ll = LiteralLabelFactory.createTypedLiteral(uuid);
assertEquals(NodeFactory.createLiteral(ll), n);
n = Converters.makeNode(NodeFactory.createVariable("foo"), pMap);
assertTrue(n.isVariable());
assertEquals("foo", n.getName());
assertTrue(n instanceof Var);
n = Converters.makeNode("'text'@en", pMap);
assertEquals("text", n.getLiteralLexicalForm());
assertEquals("en", n.getLiteralLanguage());
}
Aggregations