本文整理匯總了Java中com.hp.hpl.jena.query.QueryExecutionFactory.create方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryExecutionFactory.create方法的具體用法?Java QueryExecutionFactory.create怎麽用?Java QueryExecutionFactory.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.QueryExecutionFactory
的用法示例。
在下文中一共展示了QueryExecutionFactory.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkContainment
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
public static boolean checkContainment(CompanyModel c){
String queryString =
"ASK" +
// check whether any manager is an employee in any other department
"{?dept1" + " <" + c.MANAGER + "> " + "?manager" + ". " +
" ?dept2" + " <" + c.EMPLOYEES + "> " + "?employees1" + ". " +
" ?employees1" + " <" + RDFS.member + "> " + "?employee1" + ". " +
" FILTER (?manager = ?employee1) " +
// check whether any employee occurs more than once
" ?dept3 " + " <" + c.EMPLOYEES + "> " + "?employees2" + ". " +
" ?employees2" + " <" + RDFS.member + "> " + "?employee2" + ". " +
" FILTER (?employee1 = ?employee2)" +
// check whether any department occurs more than once
" ?upperDept1" + " <" + c.DEPTS + "> " + "?dept4" + ". " +
" ?upperDept2" + " <" + c.DEPTS + "> " + "?dept5" + ". " +
" FILTER (?dept4 = ?dept5) " +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, c.getModel());
boolean out = qe.execAsk();
qe.close();
return !out;
}
示例2: expandSubClasses
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的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;
}
示例3: expandSubProperties
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的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;
}
示例4: getTestListFromManifest
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
public static Collection<Object[]> getTestListFromManifest(String manifestFileURL) {
// We'd like to use FileManager.loadModel() but it doesn't work on jar: URLs
// Model m = FileManager.get().loadModel(manifestFileURL);
Model m = ModelFactory.createDefaultModel();
m.read(manifestFileURL, "TURTLE");
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource mapping = qs.getResource("mapping");
Resource schema = qs.getResource("schema");
// if (!mapping.getLocalName().equals("constant-object.ttl")) continue;
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
qe.setInitialBinding(qs);
Model expectedTriples = qe.execConstruct();
result.add(new Object[]{baseIRI.relativize(mapping.getURI()).toString(), mapping.getURI(),
schema.getURI(), expectedTriples});
}
return result;
}
示例5: getTestLists
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
@Parameters(name="{index}: {0}")
public static Collection<Object[]> getTestLists() {
Model m = D2RQTestUtil.loadTurtle(MANIFEST_FILE);
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource testCase = qs.getResource("case");
// if (!case.getLocalName().equals("expression")) continue;
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
qe.setInitialBinding(qs);
Model expectedTriples = qe.execConstruct();
result.add(new Object[]{
baseIRI.relativize(testCase.getURI()).toString(),
qs.getLiteral("sql").getLexicalForm(),
expectedTriples});
}
return result;
}
示例6: getDbPediaLongDescription
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
public String getDbPediaLongDescription(final String uri) throws QueryException, QueryParseException {
String labellist = "";
try {
final String query = "SELECT ?comment WHERE{ <" + uri
+ "> <http://dbpedia.org/ontology/abstract> ?comment. }";
ResultSet results = null;
QueryExecution qexec = null;
final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
qexec = QueryExecutionFactory.create(cquery, this.longdescmodel);
results = qexec.execSelect();
if (results != null) {
while (results.hasNext()) {
final QuerySolution sol = results.nextSolution();
final String desc = sol.getLiteral("comment").getLexicalForm();
labellist = desc;
}
qexec.close();
}
} catch (QueryParseException e) {
Logger.getRootLogger().info("Query parse Exception");
}
return labellist;
}
示例7: testMetric_TotalExecutions_Global
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
@Test
public void testMetric_TotalExecutions_Global() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_executions_global.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();
System.out.printf("Total executions: %d%n",total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例8: getRDFTypesFromEntity
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的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;
}
示例9: testMetric_TotalSuccesfulExecutions_Global_Period
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的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();
}
}
}
示例10: queryDbPediaCategoryLabel
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private static String queryDbPediaCategoryLabel(final String catUri) {
String res = null;
final Model model = DisambiguationMainService.getInstance()
.getDBPediaCategoryLabels();
final String query = "SELECT ?label WHERE{ <" + catUri
+ "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
try {
final com.hp.hpl.jena.query.Query cquery = QueryFactory
.create(query);
final QueryExecution qexec = QueryExecutionFactory.create(cquery,
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;
}
示例11: sparqlConstruct
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
@Override
public ClosableIterable<Statement> sparqlConstruct(String query)
throws ModelRuntimeException, MalformedQueryException {
Query jenaQuery = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(jenaQuery,
this.dataset);
if (jenaQuery.isConstructType()) {
com.hp.hpl.jena.rdf.model.Model m = qexec.execConstruct();
Model resultModel = new ModelImplJena(null, m, Reasoning.none);
resultModel.open();
return resultModel;
} else {
throw new RuntimeException(
"Cannot handle this type of query! Please use CONSTRUCT.");
}
}
示例12: queryEntitiesFromCategory
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的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;
}
示例13: getNumberOfDimensionsInCategory
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
public static Map<String, Integer> getNumberOfDimensionsInCategory(){
Map<String, Integer> dimensionPerCategory = new HashMap<String, Integer>();
Model m = InternalModelConf.getFlatModel();
String whereClause = "?categoryURI a " + SPARQLHelper.toSPARQL(DAQ.Category) +
" . ?categoryURI ?hasDimensionProperty ?dimensionURI . " +
"?hasMetricProperty " + SPARQLHelper.toSPARQL(RDFS.subPropertyOf) + SPARQLHelper.toSPARQL(DAQ.hasDimension) + " .";
String variables = "?categoryURI COUNT(?dimensionURI) as ?count";
String query = SPARQLHelper.SELECT_STATEMENT.replace("[variables]", variables).replace("[whereClauses]", whereClause);
Query qry = QueryFactory.create(query);
QueryExecution qe = QueryExecutionFactory.create(qry, m);
ResultSet rs = qe.execSelect();
while (rs.hasNext()){
QuerySolution qs = rs.next();
String cat = qs.get("categoryURI").asResource().getURI();
Integer count = qs.get("count").asLiteral().getInt();
dimensionPerCategory.put(cat, count);
}
return dimensionPerCategory;
}
示例14: getCountResult
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
private int getCountResult(String queryStr, SparqlifyDataset dataset) {
int count = 0;
Query query = QueryFactory.create(queryStr);
QueryExecution qe;
if (dataset.isSparqlService() && dataset.getSparqlServiceUri() != null) {
qe = QueryExecutionFactory.sparqlService(dataset.getSparqlServiceUri(), query);
} else {
qe = QueryExecutionFactory.create(query, dataset);
}
ResultSet res = qe.execSelect();
while(res.hasNext())
{
QuerySolution solution = res.nextSolution();
RDFNode solNode = solution.get("count");
count += solNode.asLiteral().getInt();
}
qe.close();
return count;
}
示例15: askcontainsStatement
import com.hp.hpl.jena.query.QueryExecutionFactory; //導入方法依賴的package包/類
public boolean askcontainsStatement(Statement st, Model m)
{
String q = "ASK{?subject ?predicate ?object.";
if (st.getSubject().isAnon())
q += " FILTER isBlank(?subject)";
if (st.getObject().isAnon())
q += " FILTER isBlank(?object)";
q += "}";
QuerySolutionMap args = new QuerySolutionMap();
if (!st.getSubject().isAnon())
args.add("subject", st.getSubject());
if (!st.getObject().isAnon())
args.add("object", st.getObject());
// QueryExecution qe = QueryExecutionFactory.create(q, m, args);
Query query = QueryFactory.create(q);
QueryExecution qe = QueryExecutionFactory.create(query, m, args);
return qe.execAsk();
}