Search in sources :

Example 16 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class QueryTransformOps method transformVarExprList.

private static VarExprList transformVarExprList(VarExprList varExprList, ExprTransform exprTransform) {
    VarExprList varExprList2 = new VarExprList();
    boolean changed = false;
    for (Var v : varExprList.getVars()) {
        Expr e = varExprList.getExpr(v);
        // Transform variable.
        ExprVar ev = new ExprVar(v);
        Expr ev2 = exprTransform.transform(ev);
        if (ev != ev2)
            changed = true;
        if (e == null) {
            // Variable only.
            if (ev2.isConstant()) {
                // Skip or old var, assign so it become (?old AS substitute)
                // Skip .
                // Require transform to add back substitutions "for the record";
                varExprList2.remove(v);
                varExprList2.add(v, ev2);
            } else if (ev2.isVariable()) {
                varExprList2.add(ev2.asVar());
            } else {
                throw new ARQException("Can't substitute " + v + " because it's not a simple value: " + ev2);
            }
            continue;
        }
        // There was an expression.
        Expr e2 = ExprTransformer.transform(exprTransform, e);
        if (e2 != e)
            changed = true;
        if (!ev2.isVariable())
            throw new ARQException("Can't substitute (" + v + ", " + e + ") as (" + ev2 + ", " + e2 + ")");
        varExprList2.add(ev.asVar(), e2);
    }
    return varExprList2;
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) ARQException(org.apache.jena.sparql.ARQException) ExprVar(org.apache.jena.sparql.expr.ExprVar)

Example 17 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class AssemblerUtils method readAssemblerFile.

public static Model readAssemblerFile(String assemblerFile) {
    Model spec = null;
    try {
        spec = RDFDataMgr.loadModel(assemblerFile);
    } catch (Exception ex) {
        throw new ARQException("Failed reading assembler description: " + ex.getMessage());
    }
    addRegistered(spec);
    return spec;
}
Also used : ARQException(org.apache.jena.sparql.ARQException) Model(org.apache.jena.rdf.model.Model) TypeNotUniqueException(org.apache.jena.sparql.util.TypeNotUniqueException) ARQException(org.apache.jena.sparql.ARQException)

Example 18 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class ReorderProcIndexes method reorder.

/**
 * Return a new basic pattern with the same triples as the input,
 *  but ordered as per the index list of this reorder processor.
 */
@Override
public BasicPattern reorder(BasicPattern bgp) {
    if (indexes.length != bgp.size()) {
        String str = String.format("Expected size = %d : actual basic pattern size = %d", indexes.length, bgp.size());
        Log.error(this, str);
        throw new ARQException(str);
    }
    BasicPattern bgp2 = new BasicPattern();
    for (int idx : indexes) {
        Triple t = bgp.get(idx);
        bgp2.add(t);
    }
    return bgp2;
}
Also used : Triple(org.apache.jena.graph.Triple) ARQException(org.apache.jena.sparql.ARQException) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 19 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class ReorderTransformationSubstitution method reorder.

protected ReorderProc reorder(List<Triple> triples, List<PatternTriple> components) {
    int N = components.size();
    // Maybe choose 4, say, and copy over the rest.
    int numReorder = N;
    int[] indexes = new int[N];
    if (DEBUG)
        log.debug("Reorder: " + formatted(components));
    int idx = 0;
    for (; idx < numReorder; idx++) {
        int j = chooseNext(components);
        if (j < 0)
            break;
        Triple triple = triples.get(j);
        indexes[idx] = j;
        update(triple, components);
        components.set(j, null);
    }
    // Copy over the remainder (if any)
    for (int i = 0; i < components.size(); i++) {
        if (components.get(i) != null)
            indexes[idx++] = i;
    }
    if (triples.size() != idx)
        throw new ARQException(String.format("Inconsistency: number of triples (%d) does not equal to number of indexes processed (%d)", triples.size(), idx));
    ReorderProc proc = new ReorderProcIndexes(indexes);
    return proc;
}
Also used : Triple(org.apache.jena.graph.Triple) ARQException(org.apache.jena.sparql.ARQException)

Example 20 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class StatsMatcher method init.

private void init(Item stats) {
    if (!stats.isTagged(STATS))
        throw new ARQException("Not a tagged '" + STATS + "'");
    // Skip tag
    ItemList list = stats.getList().cdr();
    if (list.car().isTagged(META)) {
        // Process the meta tag.
        Item elt1 = list.car();
        // Move list on
        list = list.cdr();
        // Get count.
        Item x = Item.find(elt1.getList(), COUNT);
        if (x != null)
            count = x.getList().get(1).asInteger();
    }
    while (!list.isEmpty()) {
        Item elt = list.car();
        list = list.cdr();
        onePattern(elt);
    }
}
Also used : Item(org.apache.jena.sparql.sse.Item) ARQException(org.apache.jena.sparql.ARQException) ItemList(org.apache.jena.sparql.sse.ItemList)

Aggregations

ARQException (org.apache.jena.sparql.ARQException)48 IOException (java.io.IOException)11 Var (org.apache.jena.sparql.core.Var)7 ArrayList (java.util.ArrayList)5 Lang (org.apache.jena.riot.Lang)5 BufferedReader (java.io.BufferedReader)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 Node (org.apache.jena.graph.Node)4 Syntax (org.apache.jena.query.Syntax)4 RDFNode (org.apache.jena.rdf.model.RDFNode)4 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Triple (org.apache.jena.graph.Triple)2 Query (org.apache.jena.query.Query)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 RiotException (org.apache.jena.riot.RiotException)2 HttpParams (org.apache.jena.sparql.engine.http.HttpParams)2 Item (org.apache.jena.sparql.sse.Item)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 BufferedWriter (java.io.BufferedWriter)1