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);
}
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();
}
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();
}
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);
}
}
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();
}
Aggregations