@Test public void testEvaluate10() { Literal leftArg = f.createLiteral("foobar", "en"); Literal rightArg = f.createLiteral("b", XMLSchema.STRING); try { Literal result = strBeforeFunc.evaluate(f, leftArg, rightArg); assertEquals("foo", result.getLabel()); assertEquals(RDF.LANGSTRING, result.getDatatype()); assertEquals("en", result.getLanguage().orElse(null)); } catch (ValueExprEvaluationException e) { fail(e.getMessage()); } }
@Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 2) { throw new ValueExprEvaluationException("Incorrect number of arguments for STRBEFORE: " + args.length); } Value leftArg = args[0]; Value rightArg = args[1]; if (leftArg instanceof Literal && rightArg instanceof Literal) { Literal leftLit = (Literal) leftArg; Literal rightLit = (Literal) rightArg; if (QueryEvaluationUtil.compatibleArguments(leftLit, rightLit)) { Optional<String> leftLanguage = leftLit.getLanguage(); IRI leftDt = leftLit.getDatatype(); String lexicalValue = leftLit.getLabel(); String substring = rightLit.getLabel(); int index = lexicalValue.indexOf(substring); String substringBefore = ""; if (index > -1) { substringBefore = lexicalValue.substring(0, index); } else { leftLanguage = Optional.empty(); leftDt = null; } if (leftLanguage.isPresent()) { return valueFactory.createLiteral(substringBefore, leftLanguage.get()); } else if (leftDt != null) { return valueFactory.createLiteral(substringBefore, leftDt); } else { return valueFactory.createLiteral(substringBefore); } } else { throw new ValueExprEvaluationException( "incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } } else { throw new ValueExprEvaluationException("incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } }
StrBefore implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 2) { throw new ValueExprEvaluationException("Incorrect number of arguments for STRBEFORE: " + args.length); } Value leftArg = args[0]; Value rightArg = args[1]; if (leftArg instanceof Literal && rightArg instanceof Literal) { Literal leftLit = (Literal) leftArg; Literal rightLit = (Literal) rightArg; if (QueryEvaluationUtil.compatibleArguments(leftLit, rightLit)) { Optional<String> leftLanguage = leftLit.getLanguage(); IRI leftDt = leftLit.getDatatype(); String lexicalValue = leftLit.getLabel(); String substring = rightLit.getLabel(); int index = lexicalValue.indexOf(substring); String substringBefore = ""; if (index > -1) { substringBefore = lexicalValue.substring(0, index); } else { leftLanguage = Optional.empty(); leftDt = null; } if (leftLanguage.isPresent()) { return valueFactory.createLiteral(substringBefore, leftLanguage.get()); } else if (leftDt != null) { return valueFactory.createLiteral(substringBefore, leftDt); } else { return valueFactory.createLiteral(substringBefore); } } else { throw new ValueExprEvaluationException( "incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } } else { throw new ValueExprEvaluationException("incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } } }
StrBefore implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 2) { throw new ValueExprEvaluationException("Incorrect number of arguments for STRBEFORE: " + args.length); } Value leftArg = args[0]; Value rightArg = args[1]; if (leftArg instanceof Literal && rightArg instanceof Literal) { Literal leftLit = (Literal) leftArg; Literal rightLit = (Literal) rightArg; if (QueryEvaluationUtil.compatibleArguments(leftLit, rightLit)) { Optional<String> leftLanguage = leftLit.getLanguage(); IRI leftDt = leftLit.getDatatype(); String lexicalValue = leftLit.getLabel(); String substring = rightLit.getLabel(); int index = lexicalValue.indexOf(substring); String substringBefore = ""; if (index > -1) { substringBefore = lexicalValue.substring(0, index); } else { leftLanguage = Optional.empty(); leftDt = null; } if (leftLanguage.isPresent()) { return valueFactory.createLiteral(substringBefore, leftLanguage.get()); } else if (leftDt != null) { return valueFactory.createLiteral(substringBefore, leftDt); } else { return valueFactory.createLiteral(substringBefore); } } else { throw new ValueExprEvaluationException( "incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } } else { throw new ValueExprEvaluationException("incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } }  }
StrBefore implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 2) { throw new ValueExprEvaluationException("Incorrect number of arguments for STRBEFORE: " + args.length); } Value leftArg = args[0]; Value rightArg = args[1]; if (leftArg instanceof Literal && rightArg instanceof Literal) { Literal leftLit = (Literal) leftArg; Literal rightLit = (Literal) rightArg; if (QueryEvaluationUtil.compatibleArguments(leftLit, rightLit)) { Optional<String> leftLanguage = leftLit.getLanguage(); IRI leftDt = leftLit.getDatatype(); String lexicalValue = leftLit.getLabel(); String substring = rightLit.getLabel(); int index = lexicalValue.indexOf(substring); String substringBefore = ""; if (index > -1) { substringBefore = lexicalValue.substring(0, index); } else { leftLanguage = Optional.empty(); leftDt = null; } if (leftLanguage.isPresent()) { return valueFactory.createLiteral(substringBefore, leftLanguage.get()); } else if (leftDt != null) { return valueFactory.createLiteral(substringBefore, leftDt); } else { return valueFactory.createLiteral(substringBefore); } } else { throw new ValueExprEvaluationException( "incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } } else { throw new ValueExprEvaluationException("incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args); }
StrBefore implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 2) { throw new ValueExprEvaluationException("Incorrect number of arguments for STRBEFORE: " + args.length); } Value leftArg = args[0]; Value rightArg = args[1]; if (leftArg instanceof Literal && rightArg instanceof Literal) { Literal leftLit = (Literal) leftArg; Literal rightLit = (Literal) rightArg; if (QueryEvaluationUtil.compatibleArguments(leftLit, rightLit)) { Optional<String> leftLanguage = leftLit.getLanguage(); IRI leftDt = leftLit.getDatatype(); String lexicalValue = leftLit.getLabel(); String substring = rightLit.getLabel(); int index = lexicalValue.indexOf(substring); String substringBefore = ""; if (index > -1) { substringBefore = lexicalValue.substring(0, index); } else { leftLanguage = Optional.empty(); leftDt = null; } if (leftLanguage.isPresent()) { return valueFactory.createLiteral(substringBefore, leftLanguage.get()); } else if (leftDt != null) { return valueFactory.createLiteral(substringBefore, leftDt); } else { return valueFactory.createLiteral(substringBefore); } } else { throw new ValueExprEvaluationException( "incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } } else { throw new ValueExprEvaluationException("incompatible operands for STRBEFORE: " + leftArg + ", " + rightArg); } }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args);  }