Java Code Examples for org.apache.jena.query.Query#isSelectType()
The following examples show how to use
org.apache.jena.query.Query#isSelectType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TriplePatternExtractor.java From NLIWOD with GNU Affero General Public License v3.0 | 6 votes |
public Set<Triple> extractTriplePattern(final Query query, final boolean ignoreOptionals) { triplePattern = new HashSet<>(); optionalTriplePattern = new HashSet<>(); query.getQueryPattern().visit(this); // postprocessing: triplepattern in OPTIONAL clause if (!ignoreOptionals && query.isSelectType()) { for (Triple t : optionalTriplePattern) { if (!ListUtils.intersection(new ArrayList<>(VarUtils.getVars(t)), query.getProjectVars()).isEmpty()) { triplePattern.add(t); } } } return triplePattern; }
Example 2
Source File: SelectExtractionVisitor.java From sparql-generate with Apache License 2.0 | 6 votes |
@Override public void visitGroupBy(final Query query) { if (query.hasGroupBy()) { isDummyQuery = false; if (!query.getGroupBy().isEmpty()) { VarExprList namedExprs = query.getGroupBy(); for (Var var : namedExprs.getVars()) { Expr expr = namedExprs.getExpr(var); if (expr != null) { output.addGroupBy(var, expr); if (!query.isSelectType()) { output.addResultVar(var); } } else { output.addGroupBy(var.getVarName()); if (!query.isSelectType()) { output.addResultVar(var); } } } } } }
Example 3
Source File: QueryStatistics.java From IGUANA with GNU Affero General Public License v3.0 | 6 votes |
public void getStatistics(Query q) { if(q.isSelectType()) { size++; offset+=q.hasOffset()?1:0; aggr+=q.hasAggregators()?1:0; groupBy+=q.hasGroupBy()?1:0; having+=q.hasHaving()?1:0; orderBy+=q.hasOrderBy()?1:0; StatisticsVisitor visitor = new StatisticsVisitor(); visitor.setElementWhere(q.getQueryPattern()); ElementWalker.walk(q.getQueryPattern(), visitor); union+=visitor.union?1:0; optional+=visitor.optional?1:0; filter+=visitor.filter?1:0; triples += visitor.bgps; } }
Example 4
Source File: OCUtils.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public static List<ConjunctiveQuery> loadConjunctiveQueries(File queryFile) throws IOException { List<ConjunctiveQuery> ret = new ArrayList<ConjunctiveQuery>(); Reader in = new FileReader(queryFile); for (String queryText: SPARQLFileParser.readQueries(in)) { queryText= queryText.trim(); if (queryText.startsWith("#")) { continue; } Query query= QueryFactory.create(queryText, Syntax.syntaxSPARQL_11); if (!query.isSelectType()) { logger.debug("Ignoring non select query: {}",query.toString()); continue; } logger.debug("Query: {}"+query); ret.add(new ConjunctiveQuery(query)); } in.close(); return ret; }
Example 5
Source File: OCUtils.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public static List<Query> loadQueries(File queryFile) throws IOException { List<Query> ret = new ArrayList<Query>(); Reader in = new FileReader(queryFile); for (String queryText: SPARQLFileParser.readQueries(in)) { queryText= queryText.trim(); if (queryText.startsWith("#")) { continue; } Query query= QueryFactory.create(queryText, Syntax.syntaxSPARQL_11); if (!query.isSelectType()) { logger.debug("Ignoring non select query: {}",query.toString()); continue; } logger.debug("Query: {}"+query); ret.add(query); } in.close(); return ret; }
Example 6
Source File: SelectQueryPartialCopyVisitor.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void startVisit(final Query query) { asSPARQLExtQuery(query); if(!query.isSelectType()) { throw new SPARQLExtException("Expecting a SELECT query:" + query); } }
Example 7
Source File: ConjunctiveQuery.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public ConjunctiveQuery(Query q) { if (!q.isSelectType()) { throw new RuntimeException("A conjunctive query can only be created from a select query: "+q.serialize(Syntax.syntaxSPARQL_11)); } query = q; setQueryPattern(q.getQueryPattern()); }
Example 8
Source File: OCUtils.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public static ConjunctiveQuery parse(String sparqlQuery) { try { Query query= QueryFactory.create(sparqlQuery, Syntax.syntaxSPARQL_11); if (!query.isSelectType()) { throw new RuntimeException("Non select query: "+sparqlQuery.toString()); } return new ConjunctiveQuery(query); } catch (Exception e) { throw new RuntimeException(e); } }
Example 9
Source File: TarqlParser.java From tarql with BSD 2-Clause "Simplified" License | 5 votes |
private void parseDo(SPARQLParser11 parser) throws ParseException { do { int beginLine = parser.getToken(1).beginLine; int beginColumn = parser.getToken(1).beginColumn; Query query = new Query(result.getPrologue()); // You'd assume that a query initialized via "new Query(prologue)" // has the IRI resolver from prologue.getResolver(), but that doesn't // appear to be the case in Jena 2.12.0, so we set it manually query.getPrologue().setResolver(result.getPrologue().getResolver()); result.addQuery(query); parser.setQuery(query); parser.Query(); if (query.isSelectType() || query.isAskType()) { seenSelectOrAsk = true; } if (seenSelectOrAsk && result.getQueries().size() > 1) { throw new QueryParseException("" + "Multiple queries per file are only supported for CONSTRUCT", beginLine, beginColumn); } // From Parser.validateParsedQuery, which we can't call directly SyntaxVarScope.check(query); result.getPrologue().usePrologueFrom(query); if (log.isDebugEnabled()) { log.debug(query.toString()); } } while (parser.getToken(1).kind != SPARQLParser11.EOF); removeBuiltInPrefixes(); }
Example 10
Source File: TarqlQueryExecution.java From tarql with BSD 2-Clause "Simplified" License | 4 votes |
/** * Modifies a query so that it operates onto a table. This is achieved * by appending the table as a VALUES block to the end of the main * query pattern. * * @param query Original query; will be modified in place * @param table Data table to be added into the query */ private void modifyQuery(Query query, final Table table) { ElementData tableElement = new ElementData() { @Override public Table getTable() { return table; } }; for (Var var: table.getVars()) { // Skip ?ROWNUM for "SELECT *" queries -- see further below if (query.isSelectType() && query.isQueryResultStar() && var.equals(TarqlQuery.ROWNUM)) continue; tableElement.add(var); } ElementGroup groupElement = new ElementGroup(); groupElement.addElement(tableElement); if (query.getQueryPattern() instanceof ElementGroup) { for (Element element: ((ElementGroup) query.getQueryPattern()).getElements()) { groupElement.addElement(element); } } else { groupElement.addElement(query.getQueryPattern()); } query.setQueryPattern(groupElement); // For SELECT * queries, we don't want to include pseudo // columns such as ?ROWNUM that may exist in the table. // That's why we skipped ?ROWNUM further up. if (query.isSelectType() && query.isQueryResultStar()) { // Force expansion of "SELECT *" to actual projection list query.setResultVars(); // Tell ARQ that it actually needs to pay attention to // the projection list query.setQueryResultStar(false); // And now we can add ?ROWNUM to the table, as the "*" // has already been expanded. tableElement.add(TarqlQuery.ROWNUM); } // Data can only be added to table after we've finished the // ?ROWNUM shenangians /*for (Binding binding: table.getRows()) { tableElement.add(binding); }*/ }