use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class FunctionBase3 method exec.
@Override
public final NodeValue exec(List<NodeValue> args) {
if (args == null)
// The contract on the function interface is that this should not happen.
throw new ARQInternalErrorException(Lib.className(this) + ": Null args list");
if (args.size() != 3)
throw new ExprEvalException(Lib.className(this) + ": Wrong number of arguments: Wanted 3, got " + args.size());
NodeValue v1 = args.get(0);
NodeValue v2 = args.get(1);
NodeValue v3 = args.get(2);
return exec(v1, v2, v3);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class FunctionBase4 method exec.
@Override
public final NodeValue exec(List<NodeValue> args) {
if (args == null)
// The contract on the function interface is that this should not happen.
throw new ARQInternalErrorException(Lib.className(this) + ": Null args list");
if (args.size() != 4)
throw new ExprEvalException(Lib.className(this) + ": Wrong number of arguments: Wanted 4, got " + args.size());
NodeValue v1 = args.get(0);
NodeValue v2 = args.get(1);
NodeValue v3 = args.get(2);
NodeValue v4 = args.get(3);
return exec(v1, v2, v3, v4);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class NodeFunctions method checkTwoArgumentStringLiterals.
/**
* Check for string operations with primary first arg and second second arg
* (e.g. CONTAINS). The arguments are not used in the same way and the check
* operation is not symmetric.
* <li> "abc"@en is compatible with "abc"
* <li> "abc" is NOT compatible with "abc"@en
*/
public static void checkTwoArgumentStringLiterals(String label, NodeValue arg1, NodeValue arg2) {
/* Quote the spec:
* Compatibility of two arguments is defined as:
* The arguments are simple literals or literals typed as xsd:string
* The arguments are plain literals with identical language tags
* The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
*/
Node n1 = checkAndGetStringLiteral(label, arg1);
Node n2 = checkAndGetStringLiteral(label, arg2);
String lang1 = n1.getLiteralLanguage();
String lang2 = n2.getLiteralLanguage();
if (lang1 == null)
lang1 = "";
if (lang2 == null)
lang2 = "";
// Case 1
if (lang1.equals("")) {
if (lang2.equals(""))
return;
throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2);
}
// Case 2
if (lang1.equalsIgnoreCase(lang2))
return;
// Case 3
if (lang2.equals(""))
return;
throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2);
// ----------
// if ( lang1.equals("") && !lang2.equals("") )
// throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2) ;
//
//
//
// if ( n1.getLiteralDatatype() != null ) {
// // n1 is an xsd string by checkAndGetString
// if ( XSDDatatype.XSDstring.equals(n2.getLiteralDatatypeURI()) )
// return ;
// if ( n2.getLiteralLanguage().equals("") )
// return ;
// throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2) ;
// }
//
// // Incompatible?
// // arg1 simple or xsd:string, arg2 has a lang.
// // arg1 with lang, arg2 has a different lang.
// if ( !lang1.equals("") && (!lang2.equals("") && !lang1.equals(lang2)) )
// throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2) ;
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class NodeFunctions method checkAndGetStringLiteral.
// Helper functions
/**
* check and get a string (may be a simple literal, literal with language
* tag or an XSD string).
*/
public static Node checkAndGetStringLiteral(String label, NodeValue nv) {
Node n = nv.asNode();
if (!n.isLiteral())
throw new ExprEvalException(label + ": Not a literal: " + nv);
String lang = n.getLiteralLanguage();
if (NodeUtils.isLangString(n))
// Language tag. Legal.
return n;
if (nv.isString())
return n;
throw new ExprEvalException(label + ": Not a string literal: " + nv);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class AccStatBase method accumulate.
@Override
protected void accumulate(NodeValue nv, Binding binding, FunctionEnv functionEnv) {
// shifted_data_variance
if (nv.isNumber()) {
double d = nv.getDouble();
count++;
if (count == 1) {
K = d;
// == 0 of K set.
sum = (d - K);
// == 0
sumSquared = (d - K) * (d - K);
return;
} else {
double dk = (d - K);
double dk2 = dk * dk;
sum = sum + dk;
sumSquared = sumSquared + dk2;
}
} else
throw new ExprEvalException("Not a number: " + nv);
}
Aggregations