本文整理匯總了Java中com.hp.hpl.jena.query.QueryExecutionFactory.createServiceRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryExecutionFactory.createServiceRequest方法的具體用法?Java QueryExecutionFactory.createServiceRequest怎麽用?Java QueryExecutionFactory.createServiceRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.QueryExecutionFactory
的用法示例。
在下文中一共展示了QueryExecutionFactory.createServiceRequest方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initIndividuals
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
/**
* This method finds all individuals (= instances of owl:Class)
*
* @param dataset
*/
private void initIndividuals(SparqlifyDataset dataset) {
String indivQueryStr =
"SELECT distinct ?indiv {" +
"?indiv a ?cls . ?cls a <" + OWL.Class.getURI() + "> }";
Query indivQuery = QueryFactory.create(indivQueryStr);
QueryExecution indivQe;
if (dataset.isSparqlService() && dataset.getSparqlServiceUri()!=null) {
indivQe = QueryExecutionFactory.createServiceRequest(
dataset.getSparqlServiceUri(), indivQuery);
} else {
indivQe = QueryExecutionFactory.create(indivQuery, dataset);
}
ResultSet indivRes = indivQe.execSelect();
while (indivRes.hasNext()) {
QuerySolution sol = indivRes.next();
Node indiv = sol.get("indiv").asNode();
individuals.add(indiv);
}
}
示例2: doInBackground
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
@Override
protected ResultSet doInBackground(Void... params) {
String queryString = "" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"SELECT DISTINCT * WHERE {\n" +
"?s a owl:Class.\n" +
"?s rdfs:label ?label\n" +
"FILTER ( lang(?label) = \"en\" )\n" +
"} ORDER BY ?label LIMIT 1000\n";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.createServiceRequest("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
return results;
}
示例3: findMarkings
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private List<Marking> findMarkings(String[] text, File annFile) throws GerbilException {
List<Marking> markings = new ArrayList<Marking>();
try (BufferedReader breader = new BufferedReader(new InputStreamReader(
new FileInputStream(annFile), Charset.forName("UTF-8")))) {
String line;
while ((line = breader.readLine()) != null) {
if(line.isEmpty()){
continue;
}
String[] annotation = line.split("\t");
int searchID = getTrecID(text[0]);
int annoID = getTrecID(annotation[0]);
if(searchID == annoID){
int start = text[1].indexOf(annotation[3]);
int length = annotation[3].length();
//FIXME time consuming!
String freebaseID = annotation[2].substring(1, annotation[2].length()).replace("/",".");
Query query = QueryFactory.create(queryTemp.replace("%%v%%", freebaseID));
QueryExecution qexec = QueryExecutionFactory.createServiceRequest(DBPEDIA_SERVICE, query);
String uri = qexec.execSelect().next().getResource("s").getURI();
markings.add(new NamedEntity(start, length, uri));
}
else if(annoID > searchID){
//There is no annotation for the given text
break;
}
}
} catch (IOException e) {
throw new GerbilException("Exception while reading dataset.", e,
ErrorTypes.DATASET_LOADING_ERROR);
}
return markings;
}
示例4: ckeckLeadingZeros
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private void ckeckLeadingZeros(SparqlifyDataset dataset)
throws NotImplementedException, SQLException {
// http://www.w3.org/TR/2003/WD-rdf-syntax-grammar-20030123/#rdf-ns-uri
String queryStr =
"Prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"SELECT * { " +
"?s ?p ?o . " +
"FILTER(regex(str(?p), \"^http://www.w3.org/1999/02/22-rdf-syntax-ns#_0\")) " +
"}";
Query query = QueryFactory.create(queryStr);
QueryExecution qe;
if (dataset.isSparqlService() && dataset.getSparqlServiceUri()!=null) {
qe = QueryExecutionFactory.createServiceRequest(
dataset.getSparqlServiceUri(), query);
} else {
qe = QueryExecutionFactory.create(query, dataset);
}
ResultSet res = qe.execSelect();
List<Triple> leadingZeroTriples = new ArrayList<Triple>();
while(res.hasNext())
{
QuerySolution solution = res.nextSolution();
Resource subj = solution.getResource("s");
Resource pred = solution.getResource("p");
RDFNode obj = solution.get("o");
Triple leadingzeroTriple = new Triple(subj.asNode(), pred.asNode(), obj.asNode());
leadingZeroTriples.add(leadingzeroTriple);
}
qe.close();
for (Triple triple : leadingZeroTriples) {
Set<ViewQuad<ViewDefinition>> viewQuads = pinpointer.getViewCandidates(triple);
writeTripleMeasureToSink(leadingZeroVal, triple, viewQuads);
}
}
示例5: getQueryExecution
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private QueryExecution getQueryExecution(String queryStr, SparqlifyDataset dataset) {
Query query = QueryFactory.create(queryStr);
QueryExecution qe;
if (dataset.isSparqlService() && dataset.getSparqlServiceUri() != null) {
qe = QueryExecutionFactory.createServiceRequest(
dataset.getSparqlServiceUri(), query);
} else {
qe = QueryExecutionFactory.create(query, dataset);
}
return qe;
}
示例6: checkResourceInterpretability
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private void checkResourceInterpretability(Node node,
TriplePosition pos, Triple triple, SparqlifyDataset dataset)
throws NotImplementedException, SQLException {
boolean ontPropStatementFound = false;
// check if resource is further described using one of the proposed
// properties
for (Property ontProp : ontDefProperties) {
String queryStr = "ASK { <" + node.getURI() + "> <" + ontProp.getURI() + "> ?o }";
Query query = QueryFactory.create(queryStr);
QueryExecution qe;
if (dataset.isSparqlService() && dataset.getSparqlServiceUri()!=null) {
qe = QueryExecutionFactory.createServiceRequest(
dataset.getSparqlServiceUri(), query);
} else {
qe = QueryExecutionFactory.create(query, dataset);
}
ontPropStatementFound = qe.execAsk();
qe.close();
if (ontPropStatementFound) break;
}
if (!ontPropStatementFound) {
Set<ViewQuad<ViewDefinition>> viewQuads = pinpointer
.getViewCandidates(triple.asTriple());
writeNodeTripleMeasureToSink(0, pos, triple.asTriple(), viewQuads);
}
}
示例7: getClasses
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
/**
* @param dataset
* @return
*/
private Set<Node> getClasses(Model dataset) {
if (dataset instanceof SparqlifyDataset) {
dataset = (SparqlifyDataset) dataset;
}
Set<Node> classes = new HashSet<Node>();
// ont model approach
OntModel ontDataset =
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_TRANS_INF, dataset);
ExtendedIterator<OntClass> ontClassesIt = ontDataset.listClasses();
while (ontClassesIt.hasNext()) {
OntClass cls = ontClassesIt.next();
classes.add(cls.asNode());
}
// explicit query approach
String queryStr =
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
+ "SELECT distinct ?cls {"
+ "{?cls a rdfs:Class} "
+ "UNION {?cls a owl:Class} "
+ "UNION {[] a ?cls} }";
Query query = QueryFactory.create(queryStr);
QueryExecution qe;
if (dataset instanceof SparqlifyDataset
&& ((SparqlifyDataset) dataset).isSparqlService()
&& ((SparqlifyDataset) dataset).getSparqlServiceUri() != null) {
String serviceUri = ((SparqlifyDataset) dataset).getSparqlServiceUri();
qe = QueryExecutionFactory.createServiceRequest(serviceUri, query);
} else {
qe = QueryExecutionFactory.create(query, dataset);
}
ResultSet res = qe.execSelect();
while(res.hasNext()) {
QuerySolution solution = res.nextSolution();
RDFNode solNode = solution.get("cls");
classes.add(solNode.asNode());
}
qe.close();
return classes;
}
示例8: execute
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private ResultSet execute(String endPoint, String queryString) throws Exception {
Query query = QueryFactory.create(queryString) ;
QueryEngineHTTP qexec = QueryExecutionFactory.createServiceRequest(endPoint, query);
ResultSet results = qexec.execSelect() ;
return results;
}