Search in sources :

Example 26 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class AccStatLib method calcVariance$.

// Engine.
private static double calcVariance$(double sumSquared, double sum, long N, long N1) {
    //        System.out.printf("sum = %f, sumSq = %f, N=%d\n", sum, sumSquared, N) ;
    if (N <= 0)
        throw new ExprEvalException("N= " + N);
    if (N1 == 0)
        throw new ExprEvalException("Sample size one");
    double x = sumSquared - (sum * sum) / N;
    x = x / N1;
    return x;
}
Also used : ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 27 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class NodeFunctions method strLang.

public static NodeValue strLang(NodeValue v1, NodeValue v2) {
    if (!v1.isString())
        throw new ExprEvalException("Not a string (arg 1): " + v1);
    if (!v2.isString())
        throw new ExprEvalException("Not a string (arg 2): " + v2);
    String lex = v1.asString();
    String lang = v2.asString();
    if (lang.isEmpty())
        throw new ExprEvalException("Empty lang tag");
    return NodeValue.makeLangString(lex, lang);
}
Also used : ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 28 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class NodeFunctions method rdfTermEquals.

// Exact as defined by SPARQL spec.
public static boolean rdfTermEquals(Node n1, Node n2) {
    if (n1.equals(n2))
        return true;
    if (n1.isLiteral() && n2.isLiteral()) {
        // Two literals, may be sameTerm by language tag case insensitivity.
        String lang1 = n1.getLiteralLanguage();
        String lang2 = n2.getLiteralLanguage();
        if (!lang1.equals("") && lang1.equalsIgnoreCase(lang2)) {
            // Two language tags, equal by case insensitivity.
            boolean b = n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm());
            if (b)
                return true;
        }
        // Two literals, different terms, different language tags.
        NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: " + n1 + ", " + n2));
    }
    // One or both not a literal.
    return false;
}
Also used : ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 29 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class NodeFunctions method strDatatype.

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);
}
Also used : Node(org.apache.jena.graph.Node) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 30 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class listIndex method execObjectList.

@Override
protected QueryIterator execObjectList(Binding binding, Var listVar, Node predicate, List<Node> objectArgs, ExecutionContext execCxt) {
    if (objectArgs.size() != 2)
        throw new ExprEvalException("ListIndex : object not a list of length 2");
    Node indexNode = objectArgs.get(0);
    Node memberNode = objectArgs.get(1);
    final Collection<Node> x;
    if (!Var.isVar(memberNode))
        // If memberNode is defined, find lists containing it.
        x = GraphList.listFromMember(new GNode(execCxt.getActiveGraph(), memberNode));
    else
        // Hard. Subject unbound, no fixed member. Find every list and use BFI.
        x = GraphList.findAllLists(execCxt.getActiveGraph());
    return super.allLists(binding, x, listVar, predicate, new PropFuncArg(objectArgs, null), execCxt);
}
Also used : GNode(org.apache.jena.sparql.util.graph.GNode) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode) PropFuncArg(org.apache.jena.sparql.pfunction.PropFuncArg) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Aggregations

ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)32 Node (org.apache.jena.graph.Node)14 NodeValue (org.apache.jena.sparql.expr.NodeValue)13 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)3 BigInteger (java.math.BigInteger)2 GNode (org.apache.jena.sparql.util.graph.GNode)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Duration (javax.xml.datatype.Duration)1 ArgDecl (jena.cmd.ArgDecl)1 CmdException (jena.cmd.CmdException)1 CmdLineArgs (jena.cmd.CmdLineArgs)1 TerminationException (jena.cmd.TerminationException)1 Graph (org.apache.jena.graph.Graph)1 IRI (org.apache.jena.iri.IRI)1 Violation (org.apache.jena.iri.Violation)1 QueryExecException (org.apache.jena.query.QueryExecException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 SortCondition (org.apache.jena.query.SortCondition)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1