use of org.eclipse.rdf4j.query.parser.ParsedQuery in project rdf4j by eclipse.
the class SPARQLParserTest method testSES1927UnequalLiteralValueConstants2.
@Test
public void testSES1927UnequalLiteralValueConstants2() throws Exception {
StringBuilder qb = new StringBuilder();
qb.append("ASK {?a <foo:bar> \"test\". ?a <foo:foo> \"test\"^^<foo:bar> .} ");
ParsedQuery q = parser.parseQuery(qb.toString(), null);
TupleExpr te = q.getTupleExpr();
assertNotNull(te);
assertTrue(te instanceof Slice);
Slice s = (Slice) te;
assertTrue(s.getArg() instanceof Join);
Join j = (Join) s.getArg();
assertTrue(j.getLeftArg() instanceof StatementPattern);
assertTrue(j.getRightArg() instanceof StatementPattern);
StatementPattern leftArg = (StatementPattern) j.getLeftArg();
StatementPattern rightArg = (StatementPattern) j.getRightArg();
assertFalse(leftArg.getObjectVar().equals(rightArg.getObjectVar()));
assertNotEquals(leftArg.getObjectVar().getName(), rightArg.getObjectVar().getName());
}
use of org.eclipse.rdf4j.query.parser.ParsedQuery in project rdf4j by eclipse.
the class SPARQLParserTest method testOrderByWithAliases1.
@Test
public void testOrderByWithAliases1() throws Exception {
String queryString = " SELECT ?x (SUM(?v1)/COUNT(?v1) as ?r) WHERE { ?x <urn:foo> ?v1 } GROUP BY ?x ORDER BY ?r";
ParsedQuery query = parser.parseQuery(queryString, null);
assertNotNull(query);
TupleExpr te = query.getTupleExpr();
assertTrue(te instanceof Projection);
te = ((Projection) te).getArg();
assertTrue(te instanceof Order);
te = ((Order) te).getArg();
assertTrue(te instanceof Extension);
}
use of org.eclipse.rdf4j.query.parser.ParsedQuery in project rdf4j by eclipse.
the class SPARQLParser method parseQuery.
@Override
public ParsedQuery parseQuery(String queryStr, String baseURI) throws MalformedQueryException {
try {
ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(queryStr);
StringEscapesProcessor.process(qc);
BaseDeclProcessor.process(qc, baseURI);
Map<String, String> prefixes = PrefixDeclProcessor.process(qc);
WildcardProjectionProcessor.process(qc);
BlankNodeVarProcessor.process(qc);
if (qc.containsQuery()) {
// handle query operation
TupleExpr tupleExpr = buildQueryModel(qc);
ParsedQuery query;
ASTQuery queryNode = qc.getQuery();
if (queryNode instanceof ASTSelectQuery) {
query = new ParsedTupleQuery(queryStr, tupleExpr);
} else if (queryNode instanceof ASTConstructQuery) {
query = new ParsedGraphQuery(queryStr, tupleExpr, prefixes);
} else if (queryNode instanceof ASTAskQuery) {
query = new ParsedBooleanQuery(queryStr, tupleExpr);
} else if (queryNode instanceof ASTDescribeQuery) {
query = new ParsedDescribeQuery(queryStr, tupleExpr, prefixes);
} else {
throw new RuntimeException("Unexpected query type: " + queryNode.getClass());
}
// Handle dataset declaration
Dataset dataset = DatasetDeclProcessor.process(qc);
if (dataset != null) {
query.setDataset(dataset);
}
return query;
} else {
throw new IncompatibleOperationException("supplied string is not a query operation");
}
} catch (ParseException e) {
throw new MalformedQueryException(e.getMessage(), e);
} catch (TokenMgrError e) {
throw new MalformedQueryException(e.getMessage(), e);
}
}
use of org.eclipse.rdf4j.query.parser.ParsedQuery in project rdf4j by eclipse.
the class SeRQLParser method parseQuery.
public ParsedQuery parseQuery(String queryStr, String baseURI) throws MalformedQueryException {
try {
ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(queryStr);
// Replace deprecated NULL nodes with semantically equivalent
// alternatives
NullProcessor.process(qc);
StringEscapesProcessor.process(qc);
Map<String, String> namespaces = NamespaceDeclProcessor.process(qc);
ProjectionProcessor.process(qc);
qc.jjtAccept(new ProjectionAliasProcessor(), null);
qc.jjtAccept(new AnonymousVarGenerator(), null);
// TODO: check use of unbound variables?
TupleExpr tupleExpr = QueryModelBuilder.buildQueryModel(qc, SimpleValueFactory.getInstance());
ASTQuery queryNode = qc.getQuery();
ParsedQuery query;
if (queryNode instanceof ASTTupleQuery) {
query = new ParsedTupleQuery(tupleExpr);
} else if (queryNode instanceof ASTGraphQuery) {
query = new ParsedGraphQuery(tupleExpr, namespaces);
} else {
throw new RuntimeException("Unexpected query type: " + queryNode.getClass());
}
return query;
} catch (ParseException e) {
throw new MalformedQueryException(e.getMessage(), e);
} catch (TokenMgrError e) {
throw new MalformedQueryException(e.getMessage(), e);
} catch (VisitorException e) {
throw new MalformedQueryException(e.getMessage(), e);
}
}
use of org.eclipse.rdf4j.query.parser.ParsedQuery in project rdf4j by eclipse.
the class SPARQLParserTest method testSourceStringAssignment.
/**
* Test method for
* {@link org.eclipse.rdf4j.query.parser.sparql.SPARQLParser#parseQuery(java.lang.String, java.lang.String)}
* .
*/
@Test
public void testSourceStringAssignment() throws Exception {
String simpleSparqlQuery = "SELECT * WHERE {?X ?P ?Y }";
ParsedQuery q = parser.parseQuery(simpleSparqlQuery, null);
assertNotNull(q);
assertEquals(simpleSparqlQuery, q.getSourceString());
}
Aggregations