本文整理匯總了Java中com.hp.hpl.jena.query.QueryExecution.execSelect方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryExecution.execSelect方法的具體用法?Java QueryExecution.execSelect怎麽用?Java QueryExecution.execSelect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.QueryExecution
的用法示例。
在下文中一共展示了QueryExecution.execSelect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: expandSubClasses
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
private List<Statement> expandSubClasses(Model model){
List<Statement> stmts = new ArrayList<Statement>();
String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
+ "SELECT DISTINCT ?class ?synonym "
+ "WHERE { "
+ "?class rdfs:subClassOf+ ?subClass . "
+ "?subClass <" + synonym + "> ?synonym"
+ "}";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
ResultSet resultSet = queryExecution.execSelect();
resultSet.forEachRemaining(querySolution -> {
stmts.add(new StatementImpl(querySolution.getResource("class"), synonym, querySolution.getLiteral("synonym")));
});
return stmts;
}
示例2: expandSubProperties
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
private List<Statement> expandSubProperties(Model model){
List<Statement> stmts = new ArrayList<Statement>();
String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
+ "SELECT DISTINCT ?property ?synonym "
+ "WHERE { "
+ "?property rdfs:subPropertyOf+ ?subProperty . "
+ "?subProperty <" + synonym + "> ?synonym"
+ "}";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
ResultSet resultSet = queryExecution.execSelect();
resultSet.forEachRemaining(querySolution -> {
stmts.add(new StatementImpl(querySolution.getResource("property"), synonym, querySolution.getLiteral("synonym")));
});
return stmts;
}
示例3: main
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
public static void main(String[] args) {
// populate SPARQL SELECT Query string
StringBuilder sb = new StringBuilder();
sb.append("PREFIX books: <http://example.org/book/>").append(NEWLINE);
sb.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>").append(NEWLINE);
sb.append("SELECT ?book ?title").append(NEWLINE);
sb.append("WHERE {").append(NEWLINE);
sb.append(" ?book dc:title ?title").append(NEWLINE);
sb.append("}").append(NEWLINE);
// query from remote service
QueryExecution qexec = QueryExecutionFactory.sparqlService(SERVICE_URL, sb.toString());
System.out.println("Plan to run remote SPARQL query: ");
System.out.println(BOUNDARY);
System.out.println(sb.toString());
System.out.println(BOUNDARY);
ResultSet rs = qexec.execSelect();
// use result set formatter
ResultSetFormatter.out(rs);
qexec.close();
}
開發者ID:zhoujiagen,項目名稱:Jena-Based-Semantic-Web-Tutorial,代碼行數:26,代碼來源:SelectQueryUsingRemoteService.java
示例4: queryYagoCategoryLabel
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
private static String queryYagoCategoryLabel(final String catUri) {
String res = null;
final Model model = DisambiguationMainService.getInstance()
.getYagoCategoryLabels();
final String query = "SELECT ?label WHERE{ <" + catUri
+ "> <http://www.w3.org/2004/02/skos/core#> ?label. }";
try {
final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
final QueryExecution qexec = QueryExecutionFactory.create(que,
model);
final ResultSet results = qexec.execSelect(); // NOPMD by quh on
// 18.02.14 15:05
while (results.hasNext()) {
final QuerySolution sol = results.nextSolution();
final String name = sol.getLiteral("label").getLexicalForm();
res = name;
}
} catch (final QueryException e) {
Logger.getRootLogger().error(e.getStackTrace());
}
return res;
}
示例5: testMetric_TotalExecutions_PerBuild
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
@Test
public void testMetric_TotalExecutions_PerBuild() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_executions_per_build.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long total_executions = solution.getLiteral("total_executions").getLong();
String buildId = shorten(solution.getResource("build").getURI());
System.out.printf("Total executions of build %s: %d%n",buildId,total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例6: getDbPediaLabel
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
public List<String> getDbPediaLabel(final String uri) throws QueryException, QueryParseException {
final List<String> labellist = new LinkedList<String>();
try {
final String query = "SELECT ?label WHERE{ <" + uri
+ "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
ResultSet results = null;
QueryExecution qexec = null;
final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
qexec = QueryExecutionFactory.create(cquery, this.labelmodel);
results = qexec.execSelect();
if (results != null) {
while (results.hasNext()) {
final QuerySolution sol = results.nextSolution();
final String label = sol.getLiteral("label").getLexicalForm();
labellist.add(label);
}
qexec.close();
}
} catch (QueryParseException e) {
Logger.getRootLogger().info("Query parse Exception");
}
return labellist;
}
示例7: testMetric_TotalSuccesfulExecutions_Global_Period
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
@Test
public void testMetric_TotalSuccesfulExecutions_Global_Period() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_succesful_executions_global_period.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long total_executions = solution.getLiteral("total_executions").getLong();
String day = solution.getLiteral("day").getString();
System.out.printf("Total succesful executions [%s]: %d%n",day,total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例8: querySubCategories
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
public Set<String> querySubCategories(final String uri) {
final Set<String> types = new HashSet<String>();
final String query = "SELECT ?sub WHERE { <"+uri+"> <http://www.w3.org/2004/02/skos/core#broader> ?sub }";
try {
final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
final QueryExecution qexec = QueryExecutionFactory.create(que,
categorySkosModel);
final ResultSet results = qexec.execSelect();
while (results.hasNext()) {
final QuerySolution sol = results.nextSolution();
final String name = sol.getResource("sub").toString();
types.add(new String(name));
}
} catch (final QueryException e) {
Logger.getRootLogger().error(e.getStackTrace());
}
return types;
}
示例9: queryEntitiesFromCategory
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
private String queryEntitiesFromCategory(final String catUri) {
String res = null;
final String query = "SELECT ?entities WHERE{ ?entities <http://purl.org/dc/terms/subject> <"
+ catUri + ">. }";
try {
final com.hp.hpl.jena.query.Query cquery = QueryFactory
.create(query);
final QueryExecution qexec = QueryExecutionFactory
.create(cquery, m);
final ResultSet results = qexec.execSelect();
List<String> entities = new LinkedList<String>();
while (results.hasNext()) {
final QuerySolution sol = results.nextSolution();
entities.add(sol.getResource("entities").getURI());
}
if (entities.size() != 0) {
int randomNr = this.random.nextInt(entities.size());
return entities.get(randomNr);
}
} catch (final QueryException e) {
Logger.getRootLogger().error(e.getStackTrace());
}
return res;
}
示例10: checkRedirects
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
private String checkRedirects(String resource) {
String result = resource;
try {
Query query = QueryFactory
.create("SELECT ?redirect WHERE{ <"
+ resource
+ "> <http://dbpedia.org/ontology/wikiPageRedirects> ?redirect. }");
QueryExecution qe = QueryExecutionFactory.create(query, this.m);
ResultSet results = qe.execSelect();
while (results.hasNext()) {
QuerySolution sol = results.nextSolution();
result = sol.getResource("redirect").getURI();
}
} catch (Exception e) {
return resource;
}
return result;
}
示例11: getRDFTypesFromEntity
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
public Set<String> getRDFTypesFromEntity(final String entityUri) {
Set<String> set = new HashSet<String>();
final String query = "SELECT ?types WHERE{ <" + entityUri
+ "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?types. }";
ResultSet results = null;
QueryExecution qexec = null;
try {
final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
qexec = QueryExecutionFactory.create(cquery, instancemappingtypes);
results = qexec.execSelect();
} catch (final QueryException e) {
Logger.getRootLogger().error(e.getStackTrace());
} finally {
if (results != null) {
while (results.hasNext()) {
final QuerySolution sol = results.nextSolution();
final String type = sol.getResource("types").toString();
set.add(type);
}
}
}
return set;
}
示例12: sparql
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* RDF Navigation using SPARQL Query
*
* @param model
* the RDF model
* @param query
* SPARQL Query String
* @param field
* the placeholder of filed in parameter query
*/
private static void sparql(Model model, String query, String field) {
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(q, model);
System.out.println("Plan to run SPARQL query: ");
System.out.println(BOUNDARY);
System.out.println(query);
System.out.println(BOUNDARY);
ResultSet rs = qexec.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
RDFNode name = qs.get(field);// using RDFNode currently
if (name != null) {
System.out.println("Hello to " + name);
} else {
System.out.println("No friends found!");
}
}
qexec.close();
}
示例13: queryRemote
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* RDF Navigation using remote SPARQL Query
*
* @param service
* the SAPRQL end point URL
* @param query
* SPARQL Query String
* @param queryField
* the placeholder of filed in parameter query(sample: ?name)
*/
public static void queryRemote(final String service, final String query, String... queryFields) {
if (queryFields == null || queryFields.length == 0) {
return;
}
QueryExecution qexec = QueryExecutionFactory.sparqlService(service, query);
System.out.println("Plan to run remote SPARQL query: ");
System.out.println(BOUNDARY);
System.out.println(query);
System.out.println(BOUNDARY);
ResultSet rs = qexec.execSelect();
rendererResultSet(rs, queryFields);
System.out.println(BOUNDARY);
qexec.close();
}
示例14: crm2AliadaClass
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
public String crm2AliadaClass(final String crmClass) {
final Query query = QueryFactory.create(CRM_TO_ALIADA_CLASS_P1 + crmClass + CRM_TO_ALIADA_CLASS_P2);
ARQ.getContext().setTrue(ARQ.useSAX);
QueryExecution execution = null;
try {
execution = QueryExecutionFactory.sparqlService("http://172.25.5.15:8890/sparql", query);
execution.setTimeout(2000, 5000);
final ResultSet results = execution.execSelect();
//Iterating over the SPARQL Query results
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
//Printing DBpedia entries' abstract.
System.out.println(soln.get("?abstract"));
return soln.get("?abstract").asResource().getURI();
}
return "NULL";
} finally {
try {
execution.close();
} catch (Exception exception) {
// TODO: handle exception
}
}
}
示例15: loadVocabularies
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
@Override
public void loadVocabularies() {
QuerySolutionMap binding = new QuerySolutionMap();
binding.add("linkset", this.dataset);
Query query = QueryFactory.create(linksetVocabularyQuery);
QueryExecution qexec = QueryExecutionFactory.create(query, voidInstance.getVoidModel(),
binding);
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext();) {
QuerySolution soln = results.nextSolution();
OntResource vocabulary = soln.getResource("vocabulary").as(
OntResource.class);
vocabularies.add(vocabulary);
}
} catch (Exception e) {
Log.debug(Linkset.class, "Failed linksetVocabularyQuery");
Log.debug(Linkset.class, e.getStackTrace().toString());
} finally {
qexec.close();
}
}