Search in sources :

Example 11 with ExprEvalException

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

Example 12 with ExprEvalException

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

Example 13 with ExprEvalException

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

Example 14 with ExprEvalException

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

Example 15 with ExprEvalException

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);
}
Also used : 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