org.eclipse.rdf4j.query.QueryEvaluationException Java Examples
The following examples show how to use
org.eclipse.rdf4j.query.QueryEvaluationException.
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: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doBooleanLinksAndStylesheetAndNamespaces(BooleanQueryResultFormat format, boolean input, List<String> links, String stylesheetUrl, Map<String, String> namespaces) throws IOException, QueryResultHandlerException, QueryResultParseException, UnsupportedQueryResultFormatException, QueryEvaluationException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); BooleanQueryResultWriter writer = QueryResultIO.createBooleanWriter(format, out); for (String nextPrefix : namespaces.keySet()) { writer.handleNamespace(nextPrefix, namespaces.get(nextPrefix)); } writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); writer.handleBoolean(input); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); boolean output = QueryResultIO.parseBoolean(in, format); assertEquals(output, input); }
Example #2
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final Difference difference, final BindingSet bindings) throws QueryEvaluationException { Iteration<BindingSet, QueryEvaluationException> leftArg, rightArg; leftArg = new DelayedIteration<BindingSet, QueryEvaluationException>() { @Override protected Iteration<BindingSet, QueryEvaluationException> createIteration() throws QueryEvaluationException { return evaluate(difference.getLeftArg(), bindings); } }; rightArg = new DelayedIteration<BindingSet, QueryEvaluationException>() { @Override protected Iteration<BindingSet, QueryEvaluationException> createIteration() throws QueryEvaluationException { return evaluate(difference.getRightArg(), bindings); } }; return new SPARQLMinusIteration<>(leftArg, rightArg); }
Example #3
Source File: JoinIterator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected BindingSet getNextElement() throws QueryEvaluationException { try { while (rightIter.hasNext() || leftIter.hasNext()) { if (rightIter.hasNext()) { return rightIter.next(); } // Right iteration exhausted rightIter.close(); if (leftIter.hasNext()) { TupleExpr rightArg = join.getRightArg(); rightIter = strategy.evaluate(rightArg, leftIter.next()); } } } catch (NoSuchElementException ignore) { // probably, one of the iterations has been closed concurrently in // handleClose() } return null; }
Example #4
Source File: SailTripleSource.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> getStatements(RepositoryConnection conn, Resource subj, IRI pred, Value obj, Resource... contexts) throws RepositoryException, MalformedQueryException, QueryEvaluationException { // TODO add handling for contexts RepositoryResult<Statement> repoResult = conn.getStatements(subj, pred, obj, true); // XXX implementation remark and TODO taken from Sesame // The same variable might have been used multiple times in this // StatementPattern, verify value equality in those cases. return new ExceptionConvertingIteration<Statement, QueryEvaluationException>(repoResult) { @Override protected QueryEvaluationException convert(Exception arg0) { return new QueryEvaluationException(arg0); } }; }
Example #5
Source File: ConceptTreePanel.java From inception with Apache License 2.0 | 6 votes |
@Override public Iterator<? extends KBObject> getChildren(KBObject aNode) { try { // If the KB is read-only, then we cache the values and re-use the cached values. if (kbModel.getObject().isReadOnly()) { List<KBHandle> children = childrensCache.get(aNode); if (children == null) { children = kbService.listChildConcepts(kbModel.getObject(), aNode.getIdentifier(), preferences.getObject().showAllConcepts); childrensCache.put(aNode, children); } return children.iterator(); } else { return kbService.listChildConcepts(kbModel.getObject(), aNode.getIdentifier(), preferences.getObject().showAllConcepts).iterator(); } } catch (QueryEvaluationException e) { error(getString("listChildConceptsErrorMsg") + ": " + e.getLocalizedMessage()); LOG.error("Unable to list child concepts.", e); return Collections.emptyIterator(); } }
Example #6
Source File: DirectTypeHierarchyInferencer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void evaluateIntoStatements(ParsedGraphQuery query, Collection<Statement> statements) throws SailException, RDFHandlerException, QueryEvaluationException { try (CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter = getWrappedConnection() .evaluate(query.getTupleExpr(), null, EmptyBindingSet.getInstance(), true)) { ValueFactory vf = getValueFactory(); while (bindingsIter.hasNext()) { BindingSet bindings = bindingsIter.next(); Value subj = bindings.getValue("subject"); Value pred = bindings.getValue("predicate"); Value obj = bindings.getValue("object"); if (subj instanceof Resource && pred instanceof IRI && obj != null) { statements.add(vf.createStatement((Resource) subj, (IRI) pred, obj)); } } } }
Example #7
Source File: LimitedSizeEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Join join, BindingSet bindings) throws QueryEvaluationException { // efficient computation of a SERVICE join using vectored evaluation // TODO maybe we can create a ServiceJoin node already in the parser? if (join.getRightArg() instanceof Service) { CloseableIteration<BindingSet, QueryEvaluationException> leftIter = evaluate(join.getLeftArg(), bindings); return new ServiceJoinIterator(leftIter, (Service) join.getRightArg(), bindings, this); } if (TupleExprs.containsSubquery(join.getRightArg())) { return new LimitedSizeHashJoinIteration(this, join, bindings, used, maxSize); } else { return new JoinIterator(this, join, bindings); } }
Example #8
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Value evaluate(Label node, BindingSet bindings) throws QueryEvaluationException { // FIXME: deprecate Label in favour of Str(?) Value argValue = evaluate(node.getArg(), bindings); if (argValue instanceof Literal) { Literal literal = (Literal) argValue; if (QueryEvaluationUtil.isSimpleLiteral(literal)) { return literal; } else { return tripleSource.getValueFactory().createLiteral(literal.getLabel()); } } else { throw new ValueExprEvaluationException(); } }
Example #9
Source File: SailFederationEvalStrategy.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
@Override public CloseableIteration<BindingSet, QueryEvaluationException> evaluateIndependentJoinGroup( IndependentJoinGroup joinGroup, List<BindingSet> bindings) throws QueryEvaluationException { String preparedQuery = QueryStringUtil.selectQueryStringIndependentJoinGroup(joinGroup, bindings); try { List<StatementSource> statementSources = joinGroup.getMembers().get(0).getStatementSources(); // TODO this is only correct for the prototype (=> different endpoints) CloseableIteration<BindingSet, QueryEvaluationException> result = evaluateAtStatementSources(preparedQuery, statementSources, joinGroup.getQueryInfo()); // return only those elements which evaluated positively at the endpoint // result = new IndependentJoingroupBindingsIteration2(result, bindings); result = new IndependentJoingroupBindingsIteration3(result, bindings); return result; } catch (Exception e) { throw new QueryEvaluationException(e); } }
Example #10
Source File: HalyardExport.java From Halyard with Apache License 2.0 | 6 votes |
@Override public void writeGraphQueryResult(GraphQueryResult queryResult) throws ExportException { try { writer.startRDF(); for (Map.Entry<String, String> me : queryResult.getNamespaces().entrySet()) { writer.handleNamespace(me.getKey(), me.getValue()); } while (queryResult.hasNext()) { writer.handleStatement(queryResult.next()); tick(); } writer.endRDF(); } catch (QueryEvaluationException | RDFHandlerException e) { throw new ExportException(e); } }
Example #11
Source File: GroupIterator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public GroupIterator(EvaluationStrategy strategy, Group group, BindingSet parentBindings, long iterationCacheSyncThreshold) throws QueryEvaluationException { this.strategy = strategy; this.group = group; this.parentBindings = parentBindings; this.iterationCacheSyncThreshold = iterationCacheSyncThreshold; if (this.iterationCacheSyncThreshold > 0) { try { this.tempFile = File.createTempFile("group-eval", null); } catch (IOException e) { throw new QueryEvaluationException("could not initialize temp db", e); } this.db = DBMaker.newFileDB(tempFile).deleteFilesAfterClose().closeOnJvmShutdown().make(); } else { this.tempFile = null; this.db = null; } }
Example #12
Source File: ConstantOptimizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Determines if the provided zero-arg function is a function that should return a constant value for the entire * query execution (e.g NOW()), or if it should generate a new value for every call (e.g. RAND()). * * @param functionCall a zero-arg function call. * @return <code>true<code> iff the provided function returns a constant value for the query execution, <code>false</code> * otherwise. */ private boolean isConstantZeroArgFunction(FunctionCall functionCall) { Function function = FunctionRegistry.getInstance() .get(functionCall.getURI()) .orElseThrow(() -> new QueryEvaluationException( "Unable to find function with the URI: " + functionCall.getURI())); // we treat constant functions as the 'regular case' and make // exceptions for specific SPARQL built-in functions that require // different treatment. if (function instanceof Rand || function instanceof UUID || function instanceof STRUUID) { return false; } return true; }
Example #13
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Value evaluate(Datatype node, BindingSet bindings) throws QueryEvaluationException { Value v = evaluate(node.getArg(), bindings); if (v instanceof Literal) { Literal literal = (Literal) v; if (literal.getDatatype() != null) { // literal with datatype return literal.getDatatype(); } else if (literal.getLanguage().isPresent()) { return RDF.LANGSTRING; } else { // simple literal return XMLSchema.STRING; } } throw new ValueExprEvaluationException(); }
Example #14
Source File: RepositoryFederatedServiceIntegrationTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Before public void before() { serviceRepo = new SailRepository(new MemoryStore()); serviceRepo.init(); federatedService = new RepositoryFederatedService(serviceRepo); localRepo = new SailRepository(new MemoryStore()); localRepo.setFederatedServiceResolver(new FederatedServiceResolver() { @Override public FederatedService getService(String serviceUrl) throws QueryEvaluationException { return federatedService; } }); localRepo.init(); }
Example #15
Source File: AbstractLuceneSailGeoSPARQLTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testIntersectionQuery() throws RepositoryException, MalformedQueryException, QueryEvaluationException { try (RepositoryConnection connection = repository.getConnection()) { String queryStr = "prefix geo: <" + GEO.NAMESPACE + ">" + "prefix geof: <" + GEOF.NAMESPACE + ">" + "select ?matchUri ?match where { ?matchUri geo:asWKT ?match. filter(geof:sfIntersects(?pattern, ?match)) }"; TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SPARQL, queryStr); query.setBinding("pattern", TEST_POLY); try (TupleQueryResult result = query.evaluate()) { // check the results Map<IRI, Literal> expected = new HashMap<>(); expected.put(SUBJECT_4, POLY1); expected.put(SUBJECT_5, POLY2); while (result.hasNext()) { BindingSet bindings = result.next(); IRI subj = (IRI) bindings.getValue("matchUri"); Literal location = expected.remove(subj); assertNotNull(location); assertEquals(location, bindings.getValue("match")); } assertTrue(expected.isEmpty()); } } }
Example #16
Source File: DelegateFederatedServiceResolver.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public FederatedService getService(String serviceUrl) throws QueryEvaluationException { if (isFedXEndpoint(serviceUrl)) { return super.getService(serviceUrl); } else { return delegate.getService(serviceUrl); } }
Example #17
Source File: BackgroundTupleResult.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void handleClose() throws QueryEvaluationException { try { super.handleClose(); } finally { queue.done(); } try { finishedParsing.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { queue.checkException(); } }
Example #18
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Value evaluate(ListMemberOperator node, BindingSet bindings) throws QueryEvaluationException { List<ValueExpr> args = node.getArguments(); Value leftValue = evaluate(args.get(0), bindings); boolean result = false; ValueExprEvaluationException typeError = null; for (int i = 1; i < args.size(); i++) { ValueExpr arg = args.get(i); try { Value rightValue = evaluate(arg, bindings); result = leftValue == null && rightValue == null; if (!result) { result = QueryEvaluationUtil.compare(leftValue, rightValue, CompareOp.EQ); } if (result) { break; } } catch (ValueExprEvaluationException caught) { typeError = caught; } } if (typeError != null && !result) { // cf. SPARQL spec a type error is thrown if the value is not in the // list and one of the list members caused a type error in the // comparison. throw typeError; } return BooleanLiteral.valueOf(result); }
Example #19
Source File: TupleAndGraphQueryEvaluator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Evaluate SPARQL or SERQL tuple query and send the output to a writer. If writer is null, the console will be used * for output. * * @param queryLn query language * @param queryString query string * @param writer result writer or null * @throws UnsupportedQueryLanguageException * @throws MalformedQueryException * @throws QueryEvaluationException * @throws RepositoryException */ protected void evaluateTupleQuery(QueryLanguage queryLn, String queryString, QueryResultWriter writer) throws UnsupportedQueryLanguageException, MalformedQueryException, QueryEvaluationException, RepositoryException { Repository repository = state.getRepository(); consoleIO.writeln("Evaluating " + queryLn.getName() + " query..."); int resultCount = 0; long startTime = System.nanoTime(); try (RepositoryConnection con = repository.getConnection(); TupleQueryResult res = con.prepareTupleQuery(queryLn, queryString).evaluate()) { List<String> bindingNames = res.getBindingNames(); if (bindingNames.isEmpty()) { while (res.hasNext()) { res.next(); resultCount++; } } else { writer.startDocument(); writer.startHeader(); writer.startQueryResult(bindingNames); writer.endHeader(); while (res.hasNext()) { writer.handleSolution(res.next()); resultCount++; } writer.endQueryResult(); } } long endTime = System.nanoTime(); consoleIO.writeln(resultCount + " result(s) (" + (endTime - startTime) / 1_000_000 + " ms)"); }
Example #20
Source File: GroupIteratorTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testAvgEmptySet() throws QueryEvaluationException { Group group = new Group(EMPTY_ASSIGNMENT); group.addGroupElement(new GroupElem("avg", new Avg(new Var("a")))); GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance()); assertThat(gi.next().getBinding("avg").getValue()) .describedAs("AVG on empty set should result in 0") .isEqualTo(vf.createLiteral("0", XMLSchema.INTEGER)); }
Example #21
Source File: IndependentJoingroupBindingsIteration.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
@Override protected BindingSet getNextElement() throws QueryEvaluationException { if (result==null) { result = computeResult(); } if (currentIdx>=result.size()) return null; return result.get(currentIdx++); }
Example #22
Source File: SailTripleSource.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean hasStatements(StatementPattern stmt, RepositoryConnection conn, BindingSet bindings) throws RepositoryException, MalformedQueryException, QueryEvaluationException { Value subjValue = QueryAlgebraUtil.getVarValue(stmt.getSubjectVar(), bindings); Value predValue = QueryAlgebraUtil.getVarValue(stmt.getPredicateVar(), bindings); Value objValue = QueryAlgebraUtil.getVarValue(stmt.getObjectVar(), bindings); return conn.hasStatement((Resource)subjValue, (IRI)predValue, objValue, true, new Resource[0]); }
Example #23
Source File: GraphToBindingSetConversionIteration.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void remove() throws QueryEvaluationException { try { graph.remove(); } catch (UnsupportedOperationException | IllegalStateException e) { throw e; } }
Example #24
Source File: RegexTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEvaluate3() throws QueryEvaluationException { Literal pattern = vf.createLiteral("FooBar"); Literal startIndex = vf.createLiteral(4); try { evaluate(pattern, startIndex, startIndex, startIndex); fail("illegal number of parameters"); } catch (ValueExprEvaluationException e) { // do nothing, expected } }
Example #25
Source File: SPARQLTSVTupleBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void assertQueryResultsEqual(TupleQueryResult expected, TupleQueryResult output) throws QueryEvaluationException, TupleQueryResultHandlerException, QueryResultHandlerException, UnsupportedEncodingException { MutableTupleQueryResult r1 = new MutableTupleQueryResult(expected); MutableTupleQueryResult r2 = new MutableTupleQueryResult(output); if (!QueryResults.equals(r1, r2)) { r1.beforeFirst(); r2.beforeFirst(); assertEquals(toString(r1), toString(r2)); r2.beforeFirst(); fail(toString(r2)); } }
Example #26
Source File: TupleAndGraphQueryEvaluator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Evaluate SPARQL or SERQL graph query * * @param queryLn query language * @param queryString query string * @param writer RDFWriter to write the results to * @param namespaces namespaces to write to the RDFWriter * @throws UnsupportedQueryLanguageException * @throws MalformedQueryException * @throws QueryEvaluationException * @throws RepositoryException */ protected void evaluateGraphQuery(QueryLanguage queryLn, String queryString, RDFWriter writer, Collection<Namespace> namespaces) throws UnsupportedQueryLanguageException, MalformedQueryException, QueryEvaluationException, RepositoryException { Repository repository = state.getRepository(); consoleIO.writeln("Evaluating " + queryLn.getName() + " query..."); int resultCount = 0; long startTime = System.nanoTime(); try (RepositoryConnection con = repository.getConnection(); GraphQueryResult res = con.prepareGraphQuery(queryLn, queryString).evaluate()) { con.setParserConfig(nonVerifyingParserConfig); writer.startRDF(); namespaces.forEach(ns -> writer.handleNamespace(ns.getPrefix(), ns.getName())); while (res.hasNext()) { writer.handleStatement(res.next()); resultCount++; } writer.endRDF(); } long endTime = System.nanoTime(); consoleIO.writeln(resultCount + " results (" + (endTime - startTime) / 1_000_000 + " ms)"); }
Example #27
Source File: QueryContextIteration.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public BindingSet next() throws QueryEvaluationException { if (isClosed()) { throw new NoSuchElementException("The iteration has been closed."); } queryContext.begin(); try { return iter.next(); } finally { queryContext.end(); } }
Example #28
Source File: QueueIteration.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
@Override public void callAsync(CloseableIteration<E, QueryEvaluationException> res) { /* optimization: avoid adding empty results */ if (res instanceof EmptyIteration<?,?>) { resultQueue.onRemoveIterator(); return; } //log.info("queue: " + res.getClass().toString()); if (res instanceof org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult) { resultQueue.add_release(new BufferedCloseableIterator<E, QueryEvaluationException>(res)); } else { resultQueue.add_release(res); } }
Example #29
Source File: RootConceptsPanel.java From inception with Apache License 2.0 | 5 votes |
public boolean isConceptValid(KnowledgeBase kb, IRI conceptIRI, boolean aAll) throws QueryEvaluationException { return kbService .readConcept(kbModel.getObject().getKb(), conceptIRI.stringValue(), true) .isPresent() && !concepts.contains(conceptIRI); }
Example #30
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsOnePredicate() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, null)) { List<Statement> list = Iterations.asList(statements); assertEquals(8, list.size()); } }