本文整理汇总了Java中org.apache.jena.query.QueryExecutionFactory.sparqlService方法的典型用法代码示例。如果您正苦于以下问题:Java QueryExecutionFactory.sparqlService方法的具体用法?Java QueryExecutionFactory.sparqlService怎么用?Java QueryExecutionFactory.sparqlService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.query.QueryExecutionFactory
的用法示例。
在下文中一共展示了QueryExecutionFactory.sparqlService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProperties
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
private static List<Pair<String, String>> getProperties(String uri) {
List<Pair<String, String>> results = new ArrayList<>();
String sparqlQuery = "select ?r ?y where {<" + uri + "> ?r ?y}";
//System.out.println(sparqlQuery);
QueryExecution e = QueryExecutionFactory.sparqlService(ENDPOINT, sparqlQuery);
ResultSet rs = e.execSelect();
while (rs.hasNext()) {
QuerySolution nextSolution = rs.nextSolution();
RDFNode ynode = nextSolution.get("y");
if (ynode.isResource()) {
results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getResource("y").getURI()));
} else {
results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getLiteral("y").getString().replaceAll("\\n+", " ")));
}
}
e.close();
return results;
}
示例2: runSelectQuery
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
static ResultSet runSelectQuery(String queryString, String service, String... defaultGraphs) throws Exception {
QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(service, queryString);
qExec.addDefaultGraph(Constants.DBPEDIA_URL);
if (defaultGraphs != null) {
for (String defaultGraph : defaultGraphs) {
qExec.addDefaultGraph(defaultGraph);
}
}
qExec.addParam("timeout", Constants.TIMEOUT_VALUE); //100 sec
ResultSet set = null;
try {
set = qExec.execSelect();
set = ResultSetFactory.copyResults(set);
} catch (Exception e) {
QGenLogger.severe("Exception in SELECT\n" + queryString + "\n" + e.getMessage());
} finally {
qExec.close();
}
return set;
}
示例3: generateIndividual
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Override
public void generateIndividual(VirtualEntity virtualEntity) {
Model model = createIndividual(new VirtualEntity());
String id = UUID.randomUUID().toString();
System.out.println(String.format("Adding %s", id));
UpdateProcessor upp = UpdateExecutionFactory.createRemote(
UpdateFactory.create(String.format(UPDATE_TEMPLATE, id)),
"http://localhost:3030/pswot/update");
upp.execute();
//Query the collection, dump output
QueryExecution qe = QueryExecutionFactory.sparqlService(
"http://localhost:3030/pswot/query",
"SELECT * WHERE {?x ?r ?y}");
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results);
qe.close();
}
示例4: getClasses
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Retrieves all nodes from the endpoint that are classes
*
* @param endpoint
* @return Set of all nodes that are classes
*/
private Set<Node> getClasses(String endpoint, Model model) {
Set<Node> result = new HashSet<Node>();
try {
String query = "SELECT DISTINCT ?y WHERE { ?s a ?y }";
Query sparqlQuery = QueryFactory.create(query);
QueryExecution qexec;
if(model == null)
qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
else
qexec = QueryExecutionFactory.create(sparqlQuery, model);
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
result.add(soln.get("y").asNode());
}
} catch (Exception e) {
logger.warn("Error while processing classes");
}
return result;
}
示例5: getProperties
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Retrieves all nodes from the endpoint that are classes.
* @param endpoint
* @param classExpression
* @param model
* @return Set of all nodes that are classes
*/
private Set<Node> getProperties(String endpoint, String classExpression, Model model) {
Set<Node> result = new HashSet<Node>();
try {
String query = "SELECT DISTINCT ?p WHERE { ?s ?p ?y. ?s a <" + classExpression + "> }";
Query sparqlQuery = QueryFactory.create(query);
QueryExecution qexec;
if(model == null)
qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
else
qexec = QueryExecutionFactory.create(sparqlQuery, model);
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
result.add(soln.get("p").asNode());
}
} catch (Exception e) {
logger.warn("Error while processing classes");
}
return result;
}
示例6: queryExecution
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* creates a new object of QueryExecution
* @param query query
* @param graph graph
* @param endpoint endpoint
* @param model model
* @return QueryExecution object
*/
public static QueryExecution queryExecution(String query, String graph, String endpoint, Model model) {
ARQ.setNormalMode();
Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ);
QueryExecution qexec;
// take care of graph issues. Only takes one graph. Seems like some sparql endpoint do
// not like the FROM option.
// it is important to
if (model == null) {
if (graph != null) {
qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery, graph);
} //
else {
qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
}
} else {
logger.info("Query to Model...");
qexec = QueryExecutionFactory.create(sparqlQuery, model);
}
return qexec;
}
示例7: getTimeForQueryMs
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Override
public Long getTimeForQueryMs(String query, String queryID) {
QueryExecution exec = QueryExecutionFactory.sparqlService(service, query);
// Set query timeout
exec.setTimeout(this.timeOut, this.timeOut);
try {
long start = System.currentTimeMillis();
// Execute Query
ResultSet res = exec.execSelect();
// check ResultSet.
int size = ResultSetFormatter.consume(res);
long end = System.currentTimeMillis();
LOGGER.debug("Worker[{{}} : {{}}]: Query with ID {{}} took {{}} and has {{}} results.", this.workerType,
this.workerID, queryID, end - start, size);
// Return time
return end - start;
} catch (Exception e) {
LOGGER.warn("Worker[{{}} : {{}}]: Could not execute the following query\n{{}}\n due to", this.workerType,
this.workerID, query, e);
}
// Exception was thrown, return error
return -1L;
}
示例8: listMembers
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Enumerate all members of the delegated register
* @return
*/
public List<Resource> listMembers() {
log.debug("Fetch delegation members from " + getTarget());
String query =
subject == null ?
String.format("SELECT ?m WHERE {?m <%s> <%s>}", predicate.getURI(), object.getURI())
: String.format("SELECT ?m WHERE {<%s> <%s> ?m}", subject.getURI(), predicate.getURI());
QueryExecution exec = QueryExecutionFactory.sparqlService(getTarget(), query + " ORDER BY ?m");
try {
List<Resource> members = new ArrayList<>();
ResultSet results = exec.execSelect();
while (results.hasNext()) {
members.add( results.next().getResource("m") );
}
return members;
} finally {
exec.close();
}
}
示例9: fetchMembers
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Add a description of all of the list members to the given model.
*/
public void fetchMembers(Model model, List<Resource> members) {
StringBuffer query = new StringBuffer();
query.append("DESCRIBE ");
for (Resource member : members) {
query.append(" <");
query.append(member.getURI());
query.append(">");
}
QueryExecution exec = QueryExecutionFactory.sparqlService(getTarget(), query.toString());
try {
exec.execDescribe(model);
} finally {
exec.close();
}
}
示例10: sparql
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public String sparql(String subject) {
// First query takes the most specific class from a given resource.
String ontology_service = endpoint;
String endpointsSparql = "select ?label where {<" + subject
+ "> <http://www.w3.org/2000/01/rdf-schema#label> ?label FILTER (lang(?label) = 'en')} LIMIT 100";
Query sparqlQuery = QueryFactory.create(endpointsSparql, Syntax.syntaxARQ);
QueryEngineHTTP qexec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(ontology_service, sparqlQuery);
qexec.setModelContentType(WebContent.contentTypeRDFXML);
ResultSet results = qexec.execSelect();
String property = null;
while (results.hasNext()) {
QuerySolution qs = results.next();
property = qs.getLiteral("?label").getLexicalForm();
}
return property;
}
示例11: mostGenericClass
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public String mostGenericClass(String uri) {
// First query takes the most specific class from a given resource.
String ontology_service = "http://pt.dbpedia.org/sparql";
//String ontology_service = "http://dbpedia.org/sparql";
String sparqlQuery = " PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ " PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ " PREFIX dbr: <http://dbpedia.org/resource/>" + " PREFIX dbo: <http://dbpedia.org/ontology/>"
+ " PREFIX owl: <http://www.w3.org/2002/07/owl#>" + "SELECT DISTINCT ?type WHERE {" + "<" + uri
+ "> rdf:type ?type." + "?type rdfs:subClassOf ?genericType. "
+ "?genericType rdfs:subClassOf owl:Thing ;"
+ "FILTER ( strstarts(str(?type), 'http://dbpedia.org/ontology' ) )}";
QueryExecution query = QueryExecutionFactory.sparqlService(ontology_service, String.format(sparqlQuery));
ResultSet results = null;
try {
results = query.execSelect();
} catch (Exception e) {
return "";
}
String property = "";
while (results.hasNext()) {
QuerySolution qs = results.next();
property = qs.getResource("type").toString();
}
return property;
}
示例12: mostSpecificClass
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public String mostSpecificClass(String uri) {
// First query takes the most specific class from a given resource.
String ontology_service = "http://pt.dbpedia.org/sparql";
//String ontology_service = "http://dbpedia.org/sparql";
String sparqlQuery = " PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ " PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ " PREFIX dbr: <http://dbpedia.org/resource/>" + " PREFIX dbo: <http://dbpedia.org/ontology/>"
+ " PREFIX owl: <http://www.w3.org/2002/07/owl#>" + "SELECT DISTINCT ?lcs WHERE {"
+ "?lcs ^rdf:type/rdfs:subClassOf* <" + uri + ">;" + " a owl:Class ." + " filter not exists {"
+ " ?llcs ^(rdf:type/rdfs:subClassOf*) <" + uri + "> ;" + " a owl:Class ;"
+ " rdfs:subClassOf+ ?lcs ." + " }"
+ "FILTER ( !strstarts(str(?lcs), 'http://www.wikidata.org/entity/' ) )}";
QueryExecution query = QueryExecutionFactory.sparqlService(ontology_service, String.format(sparqlQuery));
ResultSet results = null;
try {
results = query.execSelect();
} catch (Exception e) {
return "";
}
String property = null;
while (results.hasNext()) {
QuerySolution qs = results.next();
property = qs.getResource("lcs").toString();
}
// System.out.println(property);
return property;
}
示例13: getTripleCount
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static final void getTripleCount() throws Exception {
String serviceURI = Utils.getSdaProperty("com.pineone.icbms.sda.knowledgebase.sparql.endpoint");
String queryString = "select (count(?s) as ?count) where {?s ?p ?o }";
QueryExecution queryExec = QueryExecutionFactory.sparqlService(serviceURI, queryString);
ResultSet rs = queryExec.execSelect();
// 값을 console에 출력함
ResultSetFormatter.out(rs);
}
示例14: getTripleAll
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static final void getTripleAll() throws Exception {
String serviceURI = Utils.getSdaProperty("com.pineone.icbms.sda.knowledgebase.sparql.endpoint");
String queryString = "select ?s ?p ?o {?s ?p ?o}";
QueryExecution queryExec = QueryExecutionFactory.sparqlService(serviceURI, queryString);
ResultSet rs = queryExec.execSelect();
ResultSetFormatter.out(rs);
}
示例15: getSubscribeUri
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public List<String> getSubscribeUri() {
List<String> result = new ArrayList<String>();
String query = this.makeQueryString();
String serviceURI = Utils.getSdaProperty("com.pineone.icbms.sda.knowledgebase.sparql.endpoint");
String baseuri = Utils.getSdaProperty("com.pineone.icbms.sda.knowledgebase.uri");
QueryExecution queryExec = QueryExecutionFactory.sparqlService(serviceURI, query);
ResultSet rs = queryExec.execSelect();
for (; rs.hasNext();) {
QuerySolution qs = rs.nextSolution();
result.add(getProperContainerType(
new String(qs.get("uri").toString().replaceAll(baseuri, ""))));
}
return result;
}