Search in sources :

Example 1 with SSEParseException

use of org.apache.jena.sparql.sse.SSEParseException in project jena by apache.

the class DatasetBuilderStd method chooseOptimizer.

public static ReorderTransformation chooseOptimizer(Location location) {
    if (location == null)
        return ReorderLib.identity();
    ReorderTransformation reorder = null;
    if (location.exists(Names.optStats)) {
        try {
            reorder = ReorderLib.weighted(location.getPath(Names.optStats));
            log.debug("Statistics-based BGP optimizer");
        } catch (SSEParseException ex) {
            log.warn("Error in stats file: " + ex.getMessage());
            reorder = null;
        }
    }
    if (reorder == null && location.exists(Names.optFixed)) {
        // Not as good but better than nothing.
        reorder = ReorderLib.fixed();
        log.debug("Fixed pattern BGP optimizer");
    }
    if (location.exists(Names.optNone)) {
        reorder = ReorderLib.identity();
        log.debug("Optimizer explicitly turned off");
    }
    if (reorder == null)
        reorder = SystemTDB.defaultReorderTransform;
    if (reorder == null && warnAboutOptimizer)
        ARQ.getExecLogger().warn("No BGP optimizer");
    return reorder;
}
Also used : ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) SSEParseException(org.apache.jena.sparql.sse.SSEParseException)

Example 2 with SSEParseException

use of org.apache.jena.sparql.sse.SSEParseException in project jena by apache.

the class NodecLib method decode.

private static /*public*/
Node decode(String s, PrefixMapping pmap) {
    if (s.startsWith("_:")) {
        s = s.substring(2);
        return NodeFactory.createBlankNode(s);
    }
    if (s.startsWith("<")) {
        s = s.substring(1, s.length() - 1);
        s = StrUtils.decodeHex(s, MarkerChar);
        return NodeFactory.createURI(s);
    }
    try {
        // SSE invocation is expensive (??).
        // Try TokenizerText?
        // Use for literals only.
        Node n = SSE.parseNode(s, pmap);
        return n;
    } catch (SSEParseException ex) {
        Log.error(NodeLib.class, "decode: Failed to parse: " + s);
        throw ex;
    }
}
Also used : NodeLib(org.apache.jena.tdb.lib.NodeLib) Node(org.apache.jena.graph.Node) SSEParseException(org.apache.jena.sparql.sse.SSEParseException)

Example 3 with SSEParseException

use of org.apache.jena.sparql.sse.SSEParseException in project jena by apache.

the class QueryUtils method checkOp.

public static void checkOp(Query query, boolean optimizeAlgebra) {
    IndentedLineBuffer buff = new IndentedLineBuffer();
    Op op = Algebra.compile(query);
    if (optimizeAlgebra)
        op = Algebra.optimize(op);
    WriterSSE.out(buff, op, query);
    String str = buff.toString();
    try {
        Op op2 = SSE.parseOp(str);
        if (op.hashCode() != op2.hashCode()) {
            op.hashCode();
            op2.hashCode();
            dump(op, op2);
            throw new QueryCheckException("reparsed algebra expression hashCode does not equal algebra from query");
        }
        if (!op.equals(op2)) {
            dump(op, op2);
            throw new QueryCheckException("reparsed algebra expression does not equal query algebra");
        }
    } catch (SSEParseException | BuildException ex) {
        System.err.println(str);
        throw ex;
    }
// Breakpoint
}
Also used : Op(org.apache.jena.sparql.algebra.Op) SSEParseException(org.apache.jena.sparql.sse.SSEParseException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) BuildException(org.apache.jena.sparql.sse.builders.BuildException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 4 with SSEParseException

use of org.apache.jena.sparql.sse.SSEParseException in project jena by apache.

the class SSE_Parser method term.

public static void term(Reader reader, ParseHandler handler) {
    SSE_ParserCore p = new SSE_ParserCore(reader);
    p.setHandler(handler);
    try {
        p.term();
    // Checks for EOF 
    //            //<EOF> test : EOF is always token 0.
    //            if ( p.token_source.getNextToken().kind != 0 )
    //                throw new SSEParseException("Trailing characters after "+item, item.getLine(), item.getColumn()) ;
    } catch (ParseException ex) {
        throw new SSEParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = p.token.endColumn;
        int line = p.token.endLine;
        throw new SSEParseException(tErr.getMessage(), line, col);
    }
//catch (JenaException ex)  { throw new TurtleParseException(ex.getMessage(), ex) ; }
}
Also used : SSEParseException(org.apache.jena.sparql.sse.SSEParseException) TokenMgrError(org.apache.jena.sparql.sse.lang.parser.TokenMgrError) ParseException(org.apache.jena.sparql.sse.lang.parser.ParseException) SSEParseException(org.apache.jena.sparql.sse.SSEParseException) SSE_ParserCore(org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore)

Example 5 with SSEParseException

use of org.apache.jena.sparql.sse.SSEParseException in project jena by apache.

the class SSE_Parser method parse.

public static void parse(Reader reader, ParseHandler handler) {
    SSE_ParserCore p = new SSE_ParserCore(reader);
    p.setHandler(handler);
    try {
        p.parse();
    } catch (ParseException ex) {
        throw new SSEParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = p.token.endColumn;
        int line = p.token.endLine;
        throw new SSEParseException(tErr.getMessage(), line, col);
    }
//catch (JenaException ex)  { throw new TurtleParseException(ex.getMessage(), ex) ; }
}
Also used : SSEParseException(org.apache.jena.sparql.sse.SSEParseException) TokenMgrError(org.apache.jena.sparql.sse.lang.parser.TokenMgrError) ParseException(org.apache.jena.sparql.sse.lang.parser.ParseException) SSEParseException(org.apache.jena.sparql.sse.SSEParseException) SSE_ParserCore(org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore)

Aggregations

SSEParseException (org.apache.jena.sparql.sse.SSEParseException)6 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)2 ParseException (org.apache.jena.sparql.sse.lang.parser.ParseException)2 SSE_ParserCore (org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore)2 TokenMgrError (org.apache.jena.sparql.sse.lang.parser.TokenMgrError)2 Node (org.apache.jena.graph.Node)1 Op (org.apache.jena.sparql.algebra.Op)1 QueryCheckException (org.apache.jena.sparql.core.QueryCheckException)1 ReorderTransformation (org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)1 BuildException (org.apache.jena.sparql.sse.builders.BuildException)1 NodeLib (org.apache.jena.tdb.lib.NodeLib)1