public static Node toNode(NodeValue nv) { if ( nv == null ) return null ; return nv.asNode() ; }
@Override public boolean equals(Expr other, boolean bySyntax) { if ( other == null ) return false ; if ( this == other ) return true ; // This is the equality condition Jena uses - lang tags are different by case. if ( ! ( other instanceof NodeValue ) ) return false ; NodeValue nv = (NodeValue)other ; return asNode().equals(nv.asNode()) ; // Not NodeFunctions.sameTerm (which smooshes language tags by case) }
private void forceToNode() { if ( node == null ) node = asNode() ; if ( node == null ) raise(new ExprEvalException("Not a node: "+this)) ; }
public static NodeValue strUpperCase(NodeValue string) { Node n = checkAndGetStringLiteral("ucase", string) ; String lex = n.getLiteralLexicalForm() ; String lex2 = lex.toUpperCase() ; return calcReturn(lex2, string.asNode()) ; }
public static NodeValue strContains(NodeValue string, NodeValue match) { checkTwoArgumentStringLiterals("contains", string, match) ; String lex1 = string.asNode().getLiteralLexicalForm() ; String lex2 = match.asNode().getLiteralLexicalForm() ; boolean x = StrUtils.contains(lex1, lex2) ; return NodeValue.booleanReturn(x) ; }
public final String asQuotedString(SerializationContext context) { // If possible, make a node and use that as the formatted output. if ( node == null ) node = asNode() ; if ( node != null ) return FmtUtils.stringForNode(node, context) ; return toString() ; }
@Test public void nodeId_int_11() { Node n = NodeValue.makeInteger(X-1).asNode() ; test("\""+Long.toString(X-1)+"\"^^xsd:integer", n) ; }
@Test public void nodeId_int_13() { Node n = NodeValue.makeInteger(Y+1).asNode() ; test("\""+Long.toString(Y+1)+"\"^^xsd:integer", n) ; }
@Test public void nodeId_int_13() { Node n = NodeValue.makeInteger(Y+1).asNode() ; test("\""+Long.toString(Y+1)+"\"^^xsd:integer", n) ; }
private static NodeValue fixupDate(NodeValue nv) { DateTimeStruct dts = DateTimeStruct.parseDate(nv.asNode().getLiteralLexicalForm()) ; if ( dts.timezone != null ) return null ; dts.timezone = defaultTimezone ; nv = NodeValue.makeDate(dts.toString()) ; if ( !nv.isDate() ) throw new ARQInternalErrorException("Failed to reform an xsd:date") ; return nv ; }
@Override public NodeValue eval(NodeValue x, NodeValue y) { if ( ! x.isString() ) throw new ExprEvalException("cast: arg 2 is not a string: "+x) ; if ( ! y.isIRI() ) throw new ExprEvalException("cast: arg 2 is not a URI: "+y) ; String lex = x.getString() ; y.asNode().getURI() ; throw new ARQNotImplemented() ; }
public static NodeValue strDatatype(NodeValue v1, NodeValue v2) { if ( !v1.isString() ) throw new ExprEvalException("Not a string (arg 1): " + v1) ; if ( !v2.isIRI() ) throw new ExprEvalException("Not an IRI (arg 2): " + v2) ; String lex = v1.asString() ; Node dt = v2.asNode() ; // Check? Node n = NodeFactory.createLiteral(lex, NodeFactory.getType(dt.getURI())) ; return NodeValue.makeNode(n) ; }
public static NodeValue strEncodeForURI(NodeValue v) { Node n = v.asNode() ; if ( !n.isLiteral() ) throw new ExprEvalException("Not a literal") ; if ( ! Util.isSimpleString(n) && ! Util.isLangString(n) ) throw new ExprEvalException("Not a string literal") ; String str = n.getLiteralLexicalForm() ; String encStr = IRILib.encodeUriComponent(str) ; encStr = IRILib.encodeNonASCII(encStr) ; return NodeValue.makeString(encStr) ; }
@Test public void test_lang5() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("abc")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("xyz", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical form if one is plain", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue(Expr.CMP_LESS == x ) ; }
@Test public void test_lang7() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("abc", XSDDatatype.XSDstring)) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("xyz", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical form if other is XSD string", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue(Expr.CMP_LESS == x ) ; }
@Test public void test_lang3() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("ABC", "en")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("abc", "EN")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical if tags value-same", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue("Lang nodes should sort by case (syntactically)", Expr.CMP_LESS == y ) ; }
@Test public void testDatatype1() { NodeValue nv = NodeValue.makeInteger(5) ; Node n = nv.asNode() ; Node r = NodeFunctions.datatype(n) ; assertEquals(XSD.integer.asNode(), r) ; }
private static void test(String string, String result) { Expr expr = ExprUtils.parse(string, pmap) ; NodeValue nv = expr.eval(null, new FunctionEnvBase()) ; Node r = NodeFactoryExtra.parseNode(result) ; NodeValue nvr = NodeValue.makeNode(r) ; assertTrue("Not same value: Expected: "+nvr+" : Actual = "+nv, NodeValue.sameAs(nvr, nv)) ; // test result must be lexical form exact. assertEquals(r, nv.asNode()) ; }