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


Java QueryExecution.execConstruct方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: sparqlConstruct

import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
@Override
public ClosableIterable<Statement> sparqlConstruct(String queryString)
        throws ModelRuntimeException {
	assertModel();
	Query query = QueryFactory.create(queryString);
	QueryExecution qexec = QueryExecutionFactory.create(query, this.jenaModel);
	
	if(query.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 queries! Please use CONSTRUCT.");
	}
}
 
開發者ID:semweb4j,項目名稱:semweb4j,代碼行數:17,代碼來源:ModelImplJena.java

示例5: queryConstruct

import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
@Override
public ClosableIterable<Statement> queryConstruct(String query,
		String querylanguage) throws QueryLanguageNotSupportedException,
		MalformedQueryException, ModelRuntimeException {

	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.");
	}
}
 
開發者ID:semweb4j,項目名稱:semweb4j,代碼行數:20,代碼來源:ModelSetImplJena.java

示例6: sparqlConstruct

import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的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.");
	}

}
 
開發者ID:semweb4j,項目名稱:semweb4j,代碼行數:19,代碼來源:ModelSetImplJena.java

示例7: createIndex

import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
	 * @param type fully qualified type without prefixes, e.g. http://www.w3.org/2002/07/owl#Class
	 */
	static SPARQLModelIndex createIndex(org.aksw.jena_sparql_api.core.QueryExecutionFactory qef,List<Resource> types,float minSimilarity)
	{
		// filter for the label properties
		List<Property> labelProperties = Lists.newArrayList(RDFS.label);
		String labelValues = "<" + labelProperties.get(0) + ">";
		for (int i = 1; i < labelProperties.size(); i++) {
			labelValues += "," + "<" + labelProperties.get(i) + ">";
		}

		String typeValues = "<" + types.get(0) + ">";
		for (int i = 1; i < types.size(); i++) {
			typeValues += "," + "<" + types.get(i) + ">";
		}

		// filter for the languages
		List<String> languages = Lists.newArrayList("en");
		String languagesFilter = "FILTER(";
		languagesFilter += "LANGMATCHES(LANG(?l),'" + languages.get(0) + "') ";
		for (int i = 1; i < labelProperties.size(); i++) {
			languagesFilter += "|| LANGMATCHES(LANG(?l),'" + languages.get(i) + "') ";
		}
		languagesFilter += ")";

		//SPARQL 1.1 VALUES based
//		String languageValues = "VALUES ?lang {";
//		for (String lang : languages) {
//			languageValues += "\"" + lang + "\" ";
//		}
//		languageValues += "}";
		//		languagesFilter = languageValues + " FILTER(LANGMATCHES(LANG(?l), ?lang))";

		String query = "CONSTRUCT {?s a ?type .?s ?p_label ?l .}"
				+ " WHERE "
				+ "{?s a ?type . FILTER(?type IN ("+typeValues+"))"
				+ "OPTIONAL{?s ?p_label ?l . FILTER(?p_label IN (" + labelValues + "))"
				+ languagesFilter + "}}";
		System.out.println(QueryFactory.create(query));

		QueryExecution qe = qef.createQueryExecution(query);
		Model model = qe.execConstruct();
		qe.close();

		return new SPARQLModelIndex(model,minSimilarity);
	}
 
開發者ID:AKSW,項目名稱:rdfindex,代碼行數:48,代碼來源:SPARQLModelIndex.java


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