/** * Execute, returning all matches, which may be zero. */ public static List<RDFNode> getAll(QueryExecution qExec, String varname) { ResultSet rs = qExec.execSelect() ; List<RDFNode> matches = new ArrayList<>(); rs.forEachRemaining(qs->{ RDFNode r = qs.get(varname) ; if ( r != null ) matches.add(r); }); return matches ; } }
private Collection<String> getReferenceSet(QueryExecutionFactory model, String query) { Collection<String> references = new ArrayList<>(); Query q = QueryFactory.create(query); try (QueryExecution qe = model.createQueryExecution(q)) { qe.execSelect().forEachRemaining( row -> references.add("<" + row.get("reference").toString() + ">") ); } return references; }
/** * Execute a SELECT query and process the rows of the results with the handler code. * @param query * @param rowAction */ @Override public default void querySelect(String query, Consumer<QuerySolution> rowAction) { Txn.executeRead(this, ()->{ try ( QueryExecution qExec = query(query) ) { qExec.execSelect().forEachRemaining(rowAction); } } ); }
private Collection<String> getReferenceSet(QueryExecutionFactory model, String query) { Collection<String> references = new ArrayList<>(); Query q = QueryFactory.create(query); try (QueryExecution qe = model.createQueryExecution(q)) { qe.execSelect().forEachRemaining( row -> references.add("<" + row.get("reference").toString() + ">") ); } return references; }
/** * Execute a SELECT query and process the rows of the results with the handler code. * @param query * @param rowAction */ @Override public default void querySelect(String query, Consumer<QuerySolution> rowAction) { Txn.executeRead(this, ()->{ try ( QueryExecution qExec = query(query) ) { qExec.execSelect().forEachRemaining(rowAction); } } ); }
public Set<PrefixDeclaration> getPrefixDeclarations(Resource resource) { ImmutableSet.Builder<PrefixDeclaration> prefixes = ImmutableSet.builder(); try ( QueryExecutionFactory qef = new QueryExecutionFactoryModel(resource.getModel()); QueryExecution qe = qef.createQueryExecution(sparqlQuery)) { qe.execSelect().forEachRemaining(solution -> { PrefixDeclaration pr = PrefixDeclarationReader.create().read(solution.getResource("declare")); prefixes.add(pr); }); } catch (Exception e) { e.printStackTrace(); } return prefixes.build(); }
public Set<PrefixDeclaration> getPrefixDeclarations(Resource resource) { ImmutableSet.Builder<PrefixDeclaration> prefixes = ImmutableSet.builder(); try ( QueryExecutionFactory qef = new QueryExecutionFactoryModel(resource.getModel()); QueryExecution qe = qef.createQueryExecution(sparqlQuery)) { qe.execSelect().forEachRemaining(solution -> { PrefixDeclaration pr = PrefixDeclarationReader.create().read(solution.getResource("declare")); prefixes.add(pr); }); } catch (Exception e) { e.printStackTrace(); } return prefixes.build(); }
private Set<TestCase> generate(QueryExecutionFactoryModel qef, SchemaSource source, TestGenerator testGenerator) { Set<TestCase> tests = new HashSet<>(); Pattern tgPattern = testGenerator.getPattern(); Query q = QueryFactory.create(PrefixNSService.getSparqlPrefixDecl() + testGenerator.getQuery()); try (QueryExecution qe = qef.createQueryExecution(q) ) { qe.execSelect().forEachRemaining(result -> { Optional<TestCase> tc = generateTestFromResult(testGenerator, tgPattern, result, source); tc.ifPresent(tests::add); }); } return tests; }
private Set<TestCase> generate(QueryExecutionFactoryModel qef, SchemaSource source, TestGenerator testGenerator) { Set<TestCase> tests = new HashSet<>(); Pattern tgPattern = testGenerator.getPattern(); Query q = QueryFactory.create(PrefixNSService.getSparqlPrefixDecl() + testGenerator.getQuery()); try (QueryExecution qe = qef.createQueryExecution(q) ) { qe.execSelect().forEachRemaining(result -> { Optional<TestCase> tc = generateTestFromResult(testGenerator, tgPattern, result, source); tc.ifPresent(tests::add); }); } return tests; }
@Override public SPARQLExecutionResult call() { Map<String, Set<String>> resultSet = new HashMap<>(); markers.forEach(marker -> resultSet.put(marker, new HashSet<>())); Model unionModel = ModelFactory.createDefaultModel(); SPARQLServiceConverter converter = new SPARQLServiceConverter(schema); String sparqlQuery = converter.getSelectQuery(query, inputSubset, rootType); logger.info(sparqlQuery); Query jenaQuery = QueryFactory.create(sparqlQuery); QueryExecution qexec = QueryExecutionFactory.create(jenaQuery, model); ResultSet results = qexec.execSelect(); results.forEachRemaining(solution -> { markers.forEach(marker ->{ if(solution.contains(marker)) { resultSet.get(marker).add(solution.get(marker).asResource().getURI()); } }); Model model = this.sparqlEndpointService.getModelFromResults(query, solution, schema); unionModel.add(model); }); return new SPARQLExecutionResult(resultSet, unionModel); }
public static Collection<ResultAnnotation> getResultAnnotations(QueryExecutionFactory queryFactory, String uri) { Collection<ResultAnnotation> annotations = new ArrayList<>(); String sparql = org.aksw.rdfunit.services.PrefixNSService.getSparqlPrefixDecl() + " SELECT ?annotationProperty ?annotationValue WHERE {" + " <" + uri + "> rut:resultAnnotation ?annotation . " + " ?annotation a rut:ResultAnnotation ; " + " rut:annotationProperty ?annotationProperty ; " + " rut:annotationValue ?annotationValue . } "; try (QueryExecution qe = queryFactory.createQueryExecution(sparql)) { qe.execSelect().forEachRemaining(qs -> { String annotationProperty = qs.get("annotationProperty").toString(); RDFNode annotationValue = qs.get("annotationValue"); annotations.add(new ResultAnnotationImpl.Builder(uri, annotationProperty).setValueRDFUnit(annotationValue).build()); }); } catch (Exception e) { log.error("Error in sparql query",e); log.debug(sparql); } return annotations; }
public static Collection<ResultAnnotation> getResultAnnotations(QueryExecutionFactory queryFactory, String uri) { Collection<ResultAnnotation> annotations = new ArrayList<>(); String sparql = org.aksw.rdfunit.services.PrefixNSService.getSparqlPrefixDecl() + " SELECT ?annotationProperty ?annotationValue WHERE {" + " <" + uri + "> rut:resultAnnotation ?annotation . " + " ?annotation a rut:ResultAnnotation ; " + " rut:annotationProperty ?annotationProperty ; " + " rut:annotationValue ?annotationValue . } "; try (QueryExecution qe = queryFactory.createQueryExecution(sparql)) { qe.execSelect().forEachRemaining(qs -> { String annotationProperty = qs.get("annotationProperty").toString(); RDFNode annotationValue = qs.get("annotationValue"); annotations.add(new ResultAnnotationImpl.Builder(uri, annotationProperty).setValueRDFUnit(annotationValue).build()); }); } catch (Exception e) { log.error("Error in sparql query",e); log.debug(sparql); } return annotations; }
private Map<String, Long> getStats(String sparqlQuery, QueryExecutionFactory qef) { Map<String, Long> stats = new HashMap<>(); try (QueryExecution qe = qef.createQueryExecution(sparqlQuery)) { qe.execSelect().forEachRemaining( qs -> { String s = qs.get("stats").toString(); int c = 0; if (qs.contains("count")) { c = qs.get("count").asLiteral().getInt(); } stats.put(s, (long) c); }); } return stats; } }
/** * Execute a SELECT query and process the rows of the results with the handler code. * @param query * @param rowAction */ @Override public default void querySelect(Query query, Consumer<QuerySolution> rowAction) { if ( ! query.isSelectType() ) throw new JenaConnectionException("Query is not a SELECT query"); Txn.executeRead(this, ()->{ try ( QueryExecution qExec = query(query) ) { qExec.execSelect().forEachRemaining(rowAction); } } ); }
private Map<String, Long> getStats(String sparqlQuery, QueryExecutionFactory qef) { Map<String, Long> stats = new HashMap<>(); try (QueryExecution qe = qef.createQueryExecution(sparqlQuery)) { qe.execSelect().forEachRemaining( qs -> { String s = qs.get("stats").toString(); int c = 0; if (qs.contains("count")) { c = qs.get("count").asLiteral().getInt(); } stats.put(s, (long) c); }); } return stats; } }
/** * Execute a SELECT query and process the rows of the results with the handler code. * @param query * @param rowAction */ @Override public default void querySelect(Query query, Consumer<QuerySolution> rowAction) { if ( ! query.isSelectType() ) throw new JenaConnectionException("Query is not a SELECT query"); Txn.executeRead(this, ()->{ try ( QueryExecution qExec = query(query) ) { qExec.execSelect().forEachRemaining(rowAction); } } ); }
/** * Execute a SELECT query and process the rows of the results with the handler code. * @param query * @param rowAction */ @Override public default void querySelect(Query query, Consumer<QuerySolution> rowAction) { if ( ! query.isSelectType() ) throw new JenaConnectionException("Query is not a SELECT query"); Txn.executeRead(this, ()->{ try ( QueryExecution qExec = query(query) ) { qExec.execSelect().forEachRemaining(rowAction); } } ); }
public List<MappingDomainError> getErrorListFromModel(Model model) { List<MappingDomainError> mappingDomainErrors = new ArrayList<>(); try ( QueryExecution qe = QueryExecutionFactory.create(SPARQL_QUERY, model)) { qe.execSelect().forEachRemaining( qs -> { String mapping = qs.get("mapping").toString(); String error = qs.get("error").toString(); String missing = qs.get("missing").toString(); String predicate = qs.get("predicate").toString(); mappingDomainErrors.add(new MappingDomainError(mapping, predicate, error, missing)); } ); } return mappingDomainErrors; }
@Override protected Collection<TestCaseResult> executeSingleTest(TestSource testSource, TestCase testCase) throws TestCaseExecutionException { Collection<TestCaseResult> testCaseResults = new ArrayList<>(); try (QueryExecution qe = testSource.getExecutionFactory().createQueryExecution(queryGenerationFactory.getSparqlQuery(testCase))) { qe.execSelect().forEachRemaining( qs -> { RDFNode focusNode = qs.get("this"); String message = testCase.getResultMessage(); if (qs.contains("message")) { message = qs.get("message").toString(); } RLOGLevel logLevel = testCase.getLogLevel(); testCaseResults.add(new ShaclLiteTestCaseResultImpl(testCase.getTestURI(), logLevel, message, focusNode)); }); } catch (QueryExceptionHTTP e) { checkQueryResultStatus(e); } return testCaseResults; }
@Override protected Collection<TestCaseResult> executeSingleTest(TestSource testSource, TestCase testCase) throws TestCaseExecutionException { Collection<TestCaseResult> testCaseResults = new ArrayList<>(); try (QueryExecution qe = testSource.getExecutionFactory().createQueryExecution(queryGenerationFactory.getSparqlQuery(testCase))) { qe.execSelect().forEachRemaining( qs -> { RDFNode focusNode = qs.get("this"); String message = testCase.getResultMessage(); if (qs.contains("message")) { message = qs.get("message").toString(); } RLOGLevel logLevel = testCase.getLogLevel(); testCaseResults.add(new ShaclLiteTestCaseResultImpl(testCase.getTestURI(), logLevel, message, focusNode)); }); } catch (QueryExceptionHTTP e) { checkQueryResultStatus(e); } return testCaseResults; }