本文整理汇总了Java中org.apache.jena.query.QueryExecutionFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Java QueryExecutionFactory.create方法的具体用法?Java QueryExecutionFactory.create怎么用?Java QueryExecutionFactory.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.query.QueryExecutionFactory
的用法示例。
在下文中一共展示了QueryExecutionFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listVocabularies
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static Set<String> listVocabularies() {
Set<String> tds = new HashSet<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
} finally {
dataset.end();
}
return tds;
}
示例2: getCount
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static int getCount(String q, Model m) {
Query query = QueryFactory.create(q);
QueryExecution queryExec = QueryExecutionFactory.create(query, m);
ResultSet rs = queryExec.execSelect();
String vName = "";
for (String v: rs.getResultVars()) {
if (v.contains("count")) {
vName = v;
break;
}
}
while (rs.hasNext()) {
QuerySolution s = rs.nextSolution();
Literal c = s.getLiteral(vName);
queryExec.close();
return c.getInt();
}
queryExec.close();
return 0;
}
示例3: getLabel
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Return the label for this object in the selected language
* @param language - the language for which the label is requested
* @return - the label in the requested language.
* @throws ModelException - thrown if there are multiple labels present for this object in this language
*/
public Label getLabel(Language language) throws ModelException {
String sparql = "SELECT ?label WHERE { ?objectURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(language.getCode(), ""));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet resultSet = qexec.execSelect();
if (!resultSet.hasNext()) return null;
QuerySolution querySolution = resultSet.next();
Label label = new Label(querySolution.getLiteral("label"));
if (!resultSet.hasNext()) return label;
throw new ModelException("%s has more than one label in language '%s'", resource.getURI(), language.getCode());
}
示例4: get
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
if (result.hasNext()) {
resource.contentType = "application/ld+json";
resource.content = result.next().get("str").asLiteral().getLexicalForm();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例5: listThingDescriptions
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例6: getThingDescriptionIdFromUri
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Returns the ID of a thing description stored in the database given its URI.
* @param uri URI of the thing description we want to return.
* @return the ID of the thing description.
*/
public static String getThingDescriptionIdFromUri(String uri) {
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> <" + uri + ">";
String id = "NOT FOUND";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?g_id WHERE { GRAPH ?g_id { " + query + " }}";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
id = result.next().get("g_id").toString();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dataset.end();
}
return id;
}
示例7: listThingDescriptionsUri
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
* Returns a list of the thing descriptions URIs.
* @return a list of URIs stored in the database.
*/
public static List<String> listThingDescriptionsUri() {
List<String> tds = new ArrayList<>();
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> ?uri";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?uri WHERE { GRAPH ?g_id { " + query + " }}";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("uri").toString());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例8: queryData
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static List<String> queryData(String query){
Dataset db = TDBFactory.createDataset("temp/dataset");
db.begin(ReadWrite.READ);
Model model = db.getDefaultModel();
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
List<String> answer = new ArrayList<String>();
while(results.hasNext()){
QuerySolution t = results.nextSolution();
RDFNode x = t.get("x");
String s = x.toString();
System.out.println(s);
answer.add(s.substring(7));
}
qexec.close();
db.close();
return answer;
}
示例9: mboxForAgent
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
private static Resource mboxForAgent(Resource agentResource) {
logger.fine("Finding mbox of " + agentResource);
String queryStr = sparqlPrefixes + "SELECT ?mbox WHERE { \n"
+ " { ?agent foaf:mbox ?mbox } \n" + " UNION \n"
+ " { ?agent vcard:hasEmail ?mbox } \n" + " UNION \n"
+ " { ?agent vcard:email ?email . \n"
+ " BIND(IRI(CONCAT(\"mbox:\", ?email)) AS ?mbox) \n" // legacy
+ " } \n" + "} \n";
logger.finer(QueryFactory.create(queryStr).toString());
QueryExecution qexec = QueryExecutionFactory.create(queryStr,
agentResource.getModel());
QuerySolutionMap binding = new QuerySolutionMap();
binding.add("agent", agentResource);
qexec.setInitialBinding(binding);
ResultSet select = qexec.execSelect();
if (select.hasNext()) {
Resource mbox = select.next().getResource("mbox");
logger.fine("Found mbox: " + mbox);
return mbox;
}
logger.fine("mbox not found");
return null;
}
示例10: testStructuredQuery
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Test
public void testStructuredQuery() {
// reversing neg and pos for diversity.
StructuredQueryBuilder qb = new StructuredQueryBuilder();
QueryDefinition structuredDef = qb.build(qb.term("Second"));
dsg.setConstrainingQueryDefinition(structuredDef);
String posQuery = "ASK WHERE {<http://example.org/r9929> ?p ?o .}";
String negQuery = "ASK WHERE {<http://example.org/r9928> ?p ?o .}";
QueryExecution queryExec = QueryExecutionFactory.create(posQuery, ds);
assertTrue(queryExec.execAsk());
queryExec = QueryExecutionFactory.create(negQuery, ds);
assertFalse(queryExec.execAsk());
// set to null
dsg.setConstrainingQueryDefinition(null);
queryExec = QueryExecutionFactory.create(posQuery, ds);
assertTrue(queryExec.execAsk());
queryExec = QueryExecutionFactory.create(negQuery, ds);
assertTrue(queryExec.execAsk());
}
示例11: fixOntModel
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public OntModel fixOntModel(OntModel ontModel)
{
if (ontModel == null) throw new IllegalArgumentException("Model cannot be null");
OntModel fixedModel = ModelFactory.createOntologyModel(ontModel.getSpecification());
Query fix = QueryFactory.create("CONSTRUCT\n" +
"{\n" +
" ?s ?p ?o\n" +
"}\n" +
"WHERE\n" +
"{\n" +
" ?s ?p ?o\n" +
" FILTER (!(?p = <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?o = <https://www.w3.org/ns/ldt#Constraint>))\n" +
"}");
try (QueryExecution qex = QueryExecutionFactory.create(fix, ontModel))
{
fixedModel.add(qex.execConstruct());
}
return fixedModel;
}
示例12: testRulesets
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Test
public void testRulesets() {
MarkLogicDatasetGraph infTestDsg = getMarkLogicDatasetGraph();
Dataset ds = DatasetFactory.wrap(infTestDsg);
String query = "prefix : <http://example.org/> select ?o where { :r3 a ?o }";
QueryExecution exec = QueryExecutionFactory.create(query, ds);
ResultSet results = exec.execSelect();
List<String> subjects = project(results, "o");
assertEquals("No inference, got back list of size 1", 1,
subjects.size());
infTestDsg.withRulesets(SPARQLRuleset.RDFS);
// MarkLogicQuery inferringQuery = MarkLogicQuery.create(query);
// inferringQuery.setRulesets(SPARQLRuleset.RDFS);
exec = QueryExecutionFactory.create(query, ds);
results = exec.execSelect();
subjects = project(results, "o");
System.out.println(subjects);
assertEquals("Using RDFs got back two class assertions", 2,
subjects.size());
}
示例13: get
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
if (result.hasNext()) {
resource.contentType = "application/ld+json";
resource.content = result.next().get("str").asLiteral().getLexicalForm();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例14: testStringAskQuery
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Test
public void testStringAskQuery() {
String file = datasource + "tigers.ttl";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraph, file);
markLogicDatasetGraph.sync();
dataSet = DatasetFactory.create(markLogicDatasetGraph);
String query1 = "PREFIX bb: <http://marklogic.com/baseball/players#>" + " ASK " + " WHERE" + " {" + " ?id bb:lastname ?name ."
+ " FILTER EXISTS { ?id bb:country ?countryname }" + " }";
QueryExecution queryExec = QueryExecutionFactory.create(query1, dataSet);
Boolean result = queryExec.execAsk();
assertFalse(result);
String query2 = "PREFIX bb: <http://marklogic.com/baseball/players#>" + "PREFIX r: <http://marklogic.com/baseball/rules#>"
+ " ASK WHERE" + " {" + " ?id bb:team r:Tigers." + " ?id bb:position \"pitcher\"." + " }";
queryExec = QueryExecutionFactory.create(query2, dataSet);
assertTrue(queryExec.execAsk());
markLogicDatasetGraph.close();
markLogicDatasetGraph = MarkLogicDatasetGraphFactory.createDatasetGraph(writerClient);
}
示例15: getSenseLabel
import org.apache.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Override
public String getSenseLabel(QName ref) {
ParameterizedSparqlString stmt = new ParameterizedSparqlString(
"SELECT ?word WHERE {\n"
+ "?sense wordnet-ontology:synset_member ?word\n"
+ "}", model);
stmt.setIri("sense", this.asRef(ref));
final String sparql = stmt.toString();
log.trace("getSenseLabel SPARQL: {}", sparql);
Query verbTxQuery = QueryFactory.create(sparql);
QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
String wordLocalName = soln.get("word").asResource().getLocalName();
return wordLocalName;
}
log.warn("No wordnet-ontology:synset_member for sense " + ref);
return shortQName(ref);
} finally {
qexec.close();
}
}