Search in sources :

Example 1 with SPARQLParser11

use of org.apache.jena.sparql.lang.sparql_11.SPARQLParser11 in project jena by apache.

the class UserDefinedFunctionFactory method add.

/**
 * Adds a function
 * <p>
 * This method will build the expression to use based on the expression
 * string given, strings must match the SPARQL expression syntax e.g.
 * </p>
 *
 * <pre>
 * (?x * ?y) + 5
 * </pre>
 *
 * @param uri
 *            URI
 * @param expr
 *            Expression String (in SPARQL syntax)
 * @param args
 *            Arguments
 * @throws ParseException
 *             Thrown if the expression string is not valid syntax
 */
public void add(String uri, String expr, List<Var> args) throws ParseException {
    Expr e = new SPARQLParser11(new StringReader(expr)).Expression();
    if (!preserveDependencies) {
        // If not allowing dependencies expand expression fully
        e = ExprTransformer.transform(new ExprTransformExpand(this.definitions), e);
    }
    UserDefinedFunctionDefinition def = new UserDefinedFunctionDefinition(uri, e, args);
    this.definitions.put(uri, def);
    FunctionRegistry.get().put(uri, this);
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) Expr(org.apache.jena.sparql.expr.Expr) StringReader(java.io.StringReader)

Example 2 with SPARQLParser11

use of org.apache.jena.sparql.lang.sparql_11.SPARQLParser11 in project jena by apache.

the class ParserSPARQL11 method parseElement.

public static Element parseElement(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser11 parser) throws Exception {
            Element el = parser.GroupGraphPattern();
            query.setQueryPattern(el);
        }
    };
    perform(query, string, action);
    return query.getQueryPattern();
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) Query(org.apache.jena.query.Query) Element(org.apache.jena.sparql.syntax.Element)

Example 3 with SPARQLParser11

use of org.apache.jena.sparql.lang.sparql_11.SPARQLParser11 in project jena by apache.

the class SolutionModifierHandler method addHaving.

/**
 * Add a having expression.
 *
 * @param expression The expression to add
 * @throws ParseException If the expression can not be parsed.
 */
public void addHaving(String expression) throws ParseException {
    String havingClause = "HAVING (" + expression + " )";
    SPARQLParser11 parser = new SPARQLParser11(new ByteArrayInputStream(havingClause.getBytes()));
    parser.setQuery(query);
    parser.HavingClause();
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 4 with SPARQLParser11

use of org.apache.jena.sparql.lang.sparql_11.SPARQLParser11 in project jena by apache.

the class ParserSPARQL11Update method _parse.

private void _parse(UpdateSink sink, Reader r) {
    SPARQLParser11 parser = null;
    try {
        parser = new SPARQLParser11(r);
        parser.setUpdateSink(sink);
        parser.UpdateUnit();
    } catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (UpdateException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.error(this, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 5 with SPARQLParser11

use of org.apache.jena.sparql.lang.sparql_11.SPARQLParser11 in project jena by apache.

the class ParserSPARQL11 method parseTemplate.

public static Template parseTemplate(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser11 parser) throws Exception {
            Template t = parser.ConstructTemplate();
            query.setConstructTemplate(t);
        }
    };
    perform(query, string, action);
    return query.getConstructTemplate();
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) Query(org.apache.jena.query.Query) Template(org.apache.jena.sparql.syntax.Template)

Aggregations

SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)7 QueryException (org.apache.jena.query.QueryException)3 QueryParseException (org.apache.jena.query.QueryParseException)3 JenaException (org.apache.jena.shared.JenaException)3 StringReader (java.io.StringReader)2 Query (org.apache.jena.query.Query)2 UpdateException (org.apache.jena.update.UpdateException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Reader (java.io.Reader)1 Expr (org.apache.jena.sparql.expr.Expr)1 Element (org.apache.jena.sparql.syntax.Element)1 Template (org.apache.jena.sparql.syntax.Template)1