use of org.openrdf.query.IncompatibleOperationException in project QueryAnalysis by Wikidata.
the class StandardizingSPARQLParser method parseQuery.
/**
* @param qc The query container to be parsed
* @param baseURI The base URI to resolve any possible relative URIs against
* @return The parsed query
* @throws MalformedQueryException If the query was in any way malformed
*/
@SuppressWarnings("WeakerAccess")
public final ParsedQuery parseQuery(ASTQueryContainer qc, String baseURI) throws MalformedQueryException {
StringEscapesProcessor.process(qc);
BaseDeclProcessor.process(qc, baseURI);
Map<String, String> prefixes = StandardizingPrefixDeclProcessor.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(qc.getSourceString(), tupleExpr);
} else if (queryNode instanceof ASTConstructQuery) {
query = new ParsedGraphQuery(qc.getSourceString(), tupleExpr, prefixes);
} else if (queryNode instanceof ASTAskQuery) {
query = new ParsedBooleanQuery(qc.getSourceString(), tupleExpr);
} else if (queryNode instanceof ASTDescribeQuery) {
query = new ParsedGraphQuery(qc.getSourceString(), 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");
}
}
Aggregations