本文整理了Java中org.apache.jena.query.ResultSet.forEachRemaining
方法的一些代码示例,展示了ResultSet.forEachRemaining
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResultSet.forEachRemaining
方法的具体详情如下:
包路径:org.apache.jena.query.ResultSet
类名称:ResultSet
方法名:forEachRemaining
暂无
代码示例来源:origin: apache/jena
/**
* 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 ;
}
}
代码示例来源:origin: org.aksw.rdfunit/rdfunit-core
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;
}
代码示例来源:origin: apache/jena
/**
* 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);
}
} );
}
代码示例来源:origin: AKSW/RDFUnit
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;
}
代码示例来源:origin: org.apache.jena/jena-rdfconnection
/**
* 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);
}
} );
}
代码示例来源:origin: org.aksw.rdfunit/rdfunit-model
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();
}
代码示例来源:origin: AKSW/RDFUnit
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();
}
代码示例来源:origin: org.aksw.rdfunit/rdfunit-core
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;
}
代码示例来源:origin: AKSW/RDFUnit
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;
}
代码示例来源:origin: semantic-integration/hypergraphql
@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);
}
代码示例来源:origin: org.aksw.rdfunit/rdfunit-core
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;
}
代码示例来源:origin: AKSW/RDFUnit
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;
}
代码示例来源:origin: org.aksw.rdfunit/rdfunit-core
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;
}
}
代码示例来源:origin: apache/jena
/**
* 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);
}
} );
}
代码示例来源:origin: AKSW/RDFUnit
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;
}
}
代码示例来源:origin: org.apache.jena/jena-rdfconnection
/**
* 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);
}
} );
}
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
/**
* 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);
}
} );
}
代码示例来源:origin: AKSW/RDFUnit
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;
}
代码示例来源:origin: org.aksw.rdfunit/rdfunit-core
@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;
}
代码示例来源:origin: AKSW/RDFUnit
@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;
}
内容来源于网络,如有侵权,请联系作者删除!