protected Query endSubSelect(int line, int column) { Query subQuery = query ; if ( ! subQuery.isSelectType() ) throwParseException("Subquery not a SELECT query", line, column) ; query = stack.pop(); return subQuery ; }
protected Query endSubSelect(int line, int column) { Query subQuery = query ; if ( ! subQuery.isSelectType() ) throwParseException("Subquery not a SELECT query", line, column) ; query = stack.pop(); return subQuery ; }
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); } }
public QueryResultTableImpl(Query query, Dataset jenaDataset) throws ModelRuntimeException { if(!query.isSelectType()) { throw new ModelRuntimeException("The given query is not a SELECT query"); } // else this.varnames = new ArrayList<String>(); for(Object o : query.getResultVars()) { this.varnames.add((String)o); } this.qexec = QueryExecutionFactory.create(query, jenaDataset); }
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; } public static Set<ConjunctiveQuery> getMembershipQuery(OWLOntology ont) {
public QueryResultTableImpl(Query query, Model jenaModel) throws ModelRuntimeException { if(!query.isSelectType()) { throw new ModelRuntimeException("The given query is not a SELECT query"); } // else this.varnames = new ArrayList<String>(); for(Object o : query.getResultVars()) { this.varnames.add((String)o); } this.qexec = QueryExecutionFactory.create(query, jenaModel); }
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; } public static List<Query> loadQueries(File queryFile) throws IOException {
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()); }
public QueryResultTableImpl(QueryExecution qe) { if(!qe.getQuery().isSelectType()) { throw new ModelRuntimeException("The given query execution is not a SELECT query"); } this.varnames = new ArrayList<String>(); for(Object o : qe.getQuery().getResultVars()) { this.varnames.add((String)o); } this.qexec = qe; }
private static QueryType getQueryType(Query query) { if( query.isSelectType() ) return QueryType.SELECT; if( query.isConstructType() ) return QueryType.CONSTRUCT; if( query.isDescribeType() ) return QueryType.DESCRIBE; if( query.isAskType() ) return QueryType.ASK; return null; }
public Set<Triple> extractTriplePattern(Query query, boolean ignoreOptionals){ triplePattern = new HashSet<Triple>(); candidates = new HashSet<Triple>(); query.getQueryPattern().visit(this); //postprocessing: triplepattern in OPTIONAL clause if(!ignoreOptionals){ if(query.isSelectType()){ for(Triple t : candidates){ if(ListUtils.intersection(new ArrayList<Var>(VarUtils.getVars(t)), query.getProjectVars()).size() >= 2){ triplePattern.add(t); } } } } return triplePattern; }
@Override public ResultSet execSelect() { if ( ! query.isSelectType() ) throw new QueryExecException("Attempt to have ResultSet from a "+labelForQuery(query)+" query") ; return execResultSet() ; }
public ResultSet execSelect() { if ( ! query.isSelectType() ) throw new QueryExecException("Attempt to have ResultSet from a "+labelForQuery(query)+" query") ; return execResultSet() ; }
static private String labelForQuery(Query q) { if ( q.isSelectType() ) return "SELECT" ; if ( q.isConstructType() ) return "CONSTRUCT" ; if ( q.isDescribeType() ) return "DESCRIBE" ; if ( q.isAskType() ) return "ASK" ; return "<<unknown>>" ; }
static private String labelForQuery(Query q) { if ( q.isSelectType() ) return "SELECT" ; if ( q.isConstructType() ) return "CONSTRUCT" ; if ( q.isDescribeType() ) return "DESCRIBE" ; if ( q.isAskType() ) return "ASK" ; return "<<unknown>>" ; }
private void execute(String queryString) { this.prefixes = new LinkedList<Prefix>(); List<Term> ans = new LinkedList<Term>(); Query sparql = QueryFactory.create(queryString); for (Map.Entry<String, String> e : sparql.getPrefixMapping().getNsPrefixMap().entrySet()) { this.prefixes.add(new Prefix(e.getKey(), e.getValue())); } if (sparql.isSelectType()) { for (String v : sparql.getResultVars()) { ans.add(DefaultTermFactory.instance().createVariable(v)); } } ElementVisitorImpl visitor = new ElementVisitorImpl(DefaultAtomSetFactory.instance().create()); sparql.getQueryPattern().visit(visitor); // check if answer variables appear in the query body Set<Variable> bodyVars = visitor.getAtomSet().getVariables(); for(Term t : ans) { if(t.isVariable() && !bodyVars.contains(t)) { throw new ParseError("The variable ["+ t +"] of the answer list does not appear in the query body."); } } this.query = DefaultConjunctiveQueryFactory.instance().create(visitor.getAtomSet(), ans); }
public static void executeQuery(Query query, QueryExecution queryExecution, ResultsFormat outputFormat) { if ( query.isSelectType() ) doSelectQuery(query, queryExecution, outputFormat) ; if ( query.isDescribeType() ) doDescribeQuery(query, queryExecution, outputFormat) ; if ( query.isConstructType() ) doConstructQuery(query, queryExecution, outputFormat) ; if ( query.isAskType() ) doAskQuery(query, queryExecution, outputFormat) ; queryExecution.close() ; }
public static void executeQuery(Query query, QueryExecution queryExecution, ResultsFormat outputFormat) { if ( query.isSelectType() ) doSelectQuery(query, queryExecution, outputFormat) ; if ( query.isDescribeType() ) doDescribeQuery(query, queryExecution, outputFormat) ; if ( query.isConstructType() ) doConstructQuery(query, queryExecution, outputFormat) ; if ( query.isAskType() ) doAskQuery(query, queryExecution, outputFormat) ; queryExecution.close() ; }
@Override public void visitSelectResultForm(Query query1) { check("Not both SELECT queries", query2.isSelectType()) ; check("DISTINCT modifier", query1.isDistinct() == query2.isDistinct()) ; check("SELECT *", query1.isQueryResultStar() == query2.isQueryResultStar()) ; check("Result variables", query1.getProject(), query2.getProject() ) ; }
public void visitSelectResultForm(Query query1) { check("Not both SELECT queries", query2.isSelectType()) ; check("DISTINCT modifier", query1.isDistinct() == query2.isDistinct()) ; check("SELECT *", query1.isQueryResultStar() == query2.isQueryResultStar()) ; check("Result variables", query1.getProject(), query2.getProject() ) ; }