当前位置: 首页>>代码示例>>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;未经允许,请勿转载。