/** Return true if this node has a datatype that looks like it is inlineable. * The node may still be out of range (e.g. very large integer). * Only inline(Node)->NodeId can determine that. */ public static boolean hasInlineDatatype(Node node) { RDFDatatype dtn = node.getLiteralDatatype() ; return datatypes.contains(dtn); }
/** * Return the datatype of the literal. This will be null in the * case of plain literals. */ @Override public RDFDatatype getDatatype() { return asNode().getLiteralDatatype(); }
/** * tests that a given Node represents a functor */ public static boolean isFunctor(Node n) { if (n == null) return false; return n.isLiteral() && n.getLiteralDatatype() == FunctorDatatype.theFunctorDatatype; }
/** * Return the datatype of the literal. This will be null in the * case of plain literals. */ @Override public RDFDatatype getDatatype() { return asNode().getLiteralDatatype(); }
/** Return true if this node has a datatype that look like it is inlineable. * The node may still be out of range (e.g. very large integer). * Only inline(Node){@literal ->}NodeId can determine that. */ public static boolean hasInlineDatatype(Node node) { if ( ! node.isLiteral() ) return false; RDFDatatype dtn = node.getLiteralDatatype(); return datatypes.contains(dtn); }
private static String simpleLiteralOrXSDString(Node n) { if ( !n.isLiteral() ) return null ; if ( n.getLiteralDatatype() == null ) { if ( n.getLiteralLanguage().equals("") ) return n.getLiteralLexicalForm() ; } else if ( n.getLiteralDatatype().equals(XSDDatatype.XSDstring) ) return n.getLiteralLexicalForm() ; return null ; }
protected static boolean equalsObjectOK( Triple t ) { Node o = t.getObject(); return o.isLiteral() ? o.getLiteralDatatype() == null : true; }
protected static boolean equalsObjectOK( Triple t ) { Node o = t.getObject(); return o.isLiteral() ? o.getLiteralDatatype() == null : true; }
protected Node stripSign(Node node) { if ( !node.isLiteral() ) return node ; String lex = node.getLiteralLexicalForm() ; String lang = node.getLiteralLanguage() ; RDFDatatype dt = node.getLiteralDatatype() ; if ( !lex.startsWith("-") && !lex.startsWith("+") ) throw new ARQInternalErrorException("Literal does not start with a sign: " + lex) ; lex = lex.substring(1) ; return NodeFactory.createLiteral(lex, lang, dt) ; }
/** * Return true if this is a "plain" (i.e. old style, not typed) literal. * For RDF 1.1, the most compatible choice is "xsd:string" or "rdf:langString". */ private boolean isPlainLiteral() { if ( JenaRuntime.isRDF11 ) return Util.isLangString(this) || Util.isSimpleString(this) ; else return asNode().getLiteralDatatype() == null; }
/** * Return true if this is a "plain" (i.e. old style, not typed) literal. * For RDF 1.1, the most compatible choice is "xsd:string" or "rdf:langString". */ private boolean isPlainLiteral() { if ( JenaRuntime.isRDF11 ) return Util.isLangString(this) || Util.isSimpleString(this) ; else return asNode().getLiteralDatatype() == null; }
public static boolean checkLiteral(Node node, ErrorHandler handler, long line, long col) { if ( !node.isLiteral() ) { handler.error("Not a literal: " + node, line, col) ; return false ; } return checkLiteral(node.getLiteralLexicalForm(), node.getLiteralLanguage(), node.getLiteralDatatype(), handler, line, col) ; }
private static void assertString(Node n) { RDFDatatype dt = n.getLiteralDatatype() ; assertEquals("", n.getLiteralLanguage() ) ; if ( JenaRuntime.isRDF11 ) assertEquals(XSDDatatype.XSDstring, dt) ; else assertEquals(null, dt) ; }
private static void normalize(String input, String expected) { Node n1 = NodeFactoryExtra.parseNode(input); assertTrue("Invalid lexical form", n1.getLiteralDatatype().isValid(n1.getLiteralLexicalForm())); Node n2 = CanonicalizeLiteral.get().apply(n1); Node n3 = NodeFactoryExtra.parseNode(expected); assertEquals("Different datatype", n3.getLiteralDatatype(), n2.getLiteralDatatype()); assertEquals("Invalid canonicalization (lex)", n3.getLiteralLexicalForm(), n2.getLiteralLexicalForm()); assertEquals("Invalid canonicalization (node)", n3, n2); }
private static void assertString(Node n) { RDFDatatype dt = n.getLiteralDatatype() ; assertEquals("", n.getLiteralLanguage() ) ; if ( JenaRuntime.isRDF11 ) assertEquals(XSDDatatype.XSDstring, dt) ; else assertEquals(null, dt) ; }
private static void assertLangString(Node n) { RDFDatatype dt = n.getLiteralDatatype() ; assertDiffer("", n.getLiteralLanguage() ) ; // "" is not legal. if ( JenaRuntime.isRDF11 ) assertEquals(RDF.dtLangString, dt) ; else assertEquals(null, dt) ; }
@Test public void factoryRDF_literal_01() { Node n = factory.createStringLiteral("hello") ; assertTrue(n.isLiteral()) ; assertEquals("hello", n.getLiteralLexicalForm()) ; assertEquals(XSDDatatype.XSDstring, n.getLiteralDatatype()) ; assertEquals("", n.getLiteralLanguage()) ; }
@Test public void factoryRDF_literal_03() { Node n = factory.createTypedLiteral("1", XSDDatatype.XSDinteger) ; assertTrue(n.isLiteral()) ; assertEquals("1", n.getLiteralLexicalForm()) ; assertEquals(XSDDatatype.XSDinteger, n.getLiteralDatatype()) ; assertEquals("", n.getLiteralLanguage()) ; }
@Test public void factoryRDF_literal_02() { Node n = factory.createLangLiteral("xyz", "en") ; assertTrue(n.isLiteral()) ; assertEquals("xyz", n.getLiteralLexicalForm()) ; assertEquals(RDF.dtLangString, n.getLiteralDatatype()) ; assertEquals("en", n.getLiteralLanguage()) ; }
@Test public void testBuildNode_06() { Item item = SSE.parseItem("true"); Node n = BuilderNode.buildNode(item); assertTrue(n.isLiteral()); assertEquals("true", n.getLiteralLexicalForm()); assertEquals(XSD.xboolean.getURI(), n.getLiteralDatatype().getURI()); }