當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryExecution類代碼示例

本文整理匯總了Java中com.hp.hpl.jena.query.QueryExecution的典型用法代碼示例。如果您正苦於以下問題:Java QueryExecution類的具體用法?Java QueryExecution怎麽用?Java QueryExecution使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


QueryExecution類屬於com.hp.hpl.jena.query包,在下文中一共展示了QueryExecution類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkContainment

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的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;
}
 
開發者ID:amritbhat786,項目名稱:DocIT,代碼行數:27,代碼來源:Containment.java

示例2: 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;
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:20,代碼來源:IndexingJob.java

示例3: 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;
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:19,代碼來源:IndexingJob.java

示例4: getTestListFromManifest

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的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;
	}
 
開發者ID:d2rq,項目名稱:r2rml-kit,代碼行數:23,代碼來源:ProcessorTestBase.java

示例5: getTestLists

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的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;
	}
 
開發者ID:d2rq,項目名稱:r2rml-kit,代碼行數:21,代碼來源:MappingGeneratorTest.java

示例6: runQueryOnInstance

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
/**
 * Runs a given Jena Query on a given instance and adds the inferred triples
 * to a given Model.
 * @param queryWrapper  the wrapper of the CONSTRUCT query to execute
 * @param queryModel  the query Model
 * @param newTriples  the Model to write the triples to
 * @param instance  the instance to run the inferences on
 * @param checkContains  true to only call add if a Triple wasn't there yet
 * @return true if changes were done (only meaningful if checkContains == true)
 */
public static boolean runQueryOnInstance(QueryWrapper queryWrapper, Model queryModel, Model newTriples, Resource instance, boolean checkContains) {
	boolean changed = false;
	QueryExecution qexec = ARQFactory.get().createQueryExecution(queryWrapper.getQuery(), queryModel);
	QuerySolutionMap bindings = new QuerySolutionMap();
	bindings.add(SPIN.THIS_VAR_NAME, instance);
	Map<String,RDFNode> initialBindings = queryWrapper.getTemplateBinding();
	if(initialBindings != null) {
		for(String varName : initialBindings.keySet()) {
			RDFNode value = initialBindings.get(varName);
			bindings.add(varName, value);
		}
	}
	qexec.setInitialBinding(bindings);
	Model cm = qexec.execConstruct();
	StmtIterator cit = cm.listStatements();
	while(cit.hasNext()) {
		Statement s = cit.nextStatement();
		if(!checkContains || !queryModel.contains(s)) {
			changed = true;
			newTriples.add(s);
		}
	}
	return changed;
}
 
開發者ID:BenzclyZhang,項目名稱:BimSPARQL,代碼行數:35,代碼來源:SPINInferencesWithoutConstructor.java

示例7: getTypesFromSPARQL

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
private Set<String> getTypesFromSPARQL(String sparqlQueryString) {

        Query query = QueryFactory.create(sparqlQueryString);
        QueryExecution qexec = QueryExecutionFactory.sparqlService(this.endpoint, query);
        Set<String> types = new HashSet<>();

        ResultSet results = qexec.execSelect();
        while(results.hasNext()) {
            QuerySolution qs = results.next();
            Resource type = qs.getResource("?type");
            types.add(type.getURI());
        }

        qexec.close();
        return types;
    }
 
開發者ID:freme-project,項目名稱:freme-ner,代碼行數:17,代碼來源:SPARQLProcessor.java

示例8: readOwlFile

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
static void readOwlFile (String pathToOwlFile) {
        OntModel ontologyModel =
                ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
        ontologyModel.read(pathToOwlFile, "RDF/XML-ABBREV");
       // OntClass myClass = ontologyModel.getOntClass("namespace+className");

        OntClass myClass = ontologyModel.getOntClass(ResourcesUri.nwr+"domain-ontology#Motion");
        System.out.println("myClass.toString() = " + myClass.toString());
        System.out.println("myClass.getSuperClass().toString() = " + myClass.getSuperClass().toString());

        //List list =
              //  namedHierarchyRoots(ontologyModel);


       Iterator i = ontologyModel.listHierarchyRootClasses()
                .filterDrop( new Filter() {
                    public boolean accept( Object o ) {
                        return ((Resource) o).isAnon();
                    }} ); ///get all top nodes and excludes anonymous classes

       // Iterator i = ontologyModel.listHierarchyRootClasses();
        while (i.hasNext()) {
            System.out.println(i.next().toString());
/*            OntClass ontClass = ontologyModel.getOntClass(i.next().toString());
            if (ontClass.hasSubClass()) {

            }*/
        }

        String q = createSparql("event", "<http://www.newsreader-project.eu/domain-ontology#Motion>");
        System.out.println("q = " + q);
        QueryExecution qe = QueryExecutionFactory.create(q,
                ontologyModel);
        for (ResultSet rs = qe.execSelect() ; rs.hasNext() ; ) {
            QuerySolution binding = rs.nextSolution();
            System.out.println("binding = " + binding.toString());
            System.out.println("Event: " + binding.get("event"));
        }

        ontologyModel.close();
    }
 
開發者ID:newsreader,項目名稱:StreamEventCoreference,代碼行數:42,代碼來源:OwlReader.java

示例9: testMetric_TotalBuilds

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
@Test
public void testMetric_TotalBuilds() {
	Query query =
		QueryFactory.
			create(
				loadResource("/metrics/total_builds.sparql"));
	QueryExecution queryExecution = null;
	try {
		queryExecution = QueryExecutionFactory.create(query, buildsDataSet());
		ResultSet results = queryExecution.execSelect();
		for(; results.hasNext();) {
			QuerySolution solution = results.nextSolution();
			long buildId = solution.getLiteral("total_builds").getLong();
			System.out.printf("Total builds: %d%n",buildId);
		}
	} finally {
		if (queryExecution != null) {
			queryExecution.close();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:22,代碼來源:VocabularyTest.java

示例10: testMetric_TotalExecutions_Global

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的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();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:22,代碼來源:VocabularyTest.java

示例11: 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();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:23,代碼來源:VocabularyTest.java

示例12: testMetric_TotalSuccesfulExecutions_Global

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
@Test
public void testMetric_TotalSuccesfulExecutions_Global() {
	Query query =
		QueryFactory.
			create(
				loadResource("/metrics/total_succesful_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 succesful executions: %d%n",total_executions);
		}
	} finally {
		if (queryExecution != null) {
			queryExecution.close();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:22,代碼來源:VocabularyTest.java

示例13: 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();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:23,代碼來源:VocabularyTest.java

示例14: testMetric_TotalSuccesfulExecutions_PerBuild

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
@Test
public void testMetric_TotalSuccesfulExecutions_PerBuild() {
	Query query =
		QueryFactory.
			create(
				loadResource("/metrics/total_succesful_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 succesful executions of build %s: %d%n",buildId,total_executions);
		}
	} finally {
		if (queryExecution != null) {
			queryExecution.close();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:23,代碼來源:VocabularyTest.java

示例15: testMetric_TotalBrokenExecutions_Global

import com.hp.hpl.jena.query.QueryExecution; //導入依賴的package包/類
@Test
public void testMetric_TotalBrokenExecutions_Global() {
	Query query =
		QueryFactory.
			create(
				loadResource("/metrics/total_broken_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 broken executions: %d%n",total_executions);
		}
	} finally {
		if (queryExecution != null) {
			queryExecution.close();
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:22,代碼來源:VocabularyTest.java


注:本文中的com.hp.hpl.jena.query.QueryExecution類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。