当前位置: 首页>>代码示例>>Java>>正文


Java QueryExecution.execSelect方法代码示例

本文整理汇总了Java中com.hp.hpl.jena.query.QueryExecution.execSelect方法的典型用法代码示例。如果您正苦于以下问题:Java QueryExecution.execSelect方法的具体用法?Java QueryExecution.execSelect怎么用?Java QueryExecution.execSelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.hp.hpl.jena.query.QueryExecution的用法示例。


在下文中一共展示了QueryExecution.execSelect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

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

示例3: main

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
public static void main(String[] args) {
	// populate SPARQL SELECT Query string
	StringBuilder sb = new StringBuilder();
	sb.append("PREFIX books:   <http://example.org/book/>").append(NEWLINE);
	sb.append("PREFIX dc:      <http://purl.org/dc/elements/1.1/>").append(NEWLINE);
	sb.append("SELECT ?book ?title").append(NEWLINE);
	sb.append("WHERE {").append(NEWLINE);
	sb.append("		?book dc:title ?title").append(NEWLINE);
	sb.append("}").append(NEWLINE);

	// query from remote service
	QueryExecution qexec = QueryExecutionFactory.sparqlService(SERVICE_URL, sb.toString());

	System.out.println("Plan to run remote SPARQL query: ");
	System.out.println(BOUNDARY);
	System.out.println(sb.toString());
	System.out.println(BOUNDARY);

	ResultSet rs = qexec.execSelect();

	// use result set formatter
	ResultSetFormatter.out(rs);

	qexec.close();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:26,代码来源:SelectQueryUsingRemoteService.java

示例4: queryYagoCategoryLabel

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
private static String queryYagoCategoryLabel(final String catUri) {
	String res = null;
	final Model model = DisambiguationMainService.getInstance()
			.getYagoCategoryLabels();

	final String query = "SELECT ?label WHERE{ <" + catUri
			+ "> <http://www.w3.org/2004/02/skos/core#> ?label. }";
	try {
		final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
		final QueryExecution qexec = QueryExecutionFactory.create(que,
				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;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:24,代码来源:RDFGraphOperations.java

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

示例6: getDbPediaLabel

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
public List<String> getDbPediaLabel(final String uri) throws QueryException, QueryParseException {
	final List<String> labellist = new LinkedList<String>();
	try {
		final String query = "SELECT ?label WHERE{ <" + uri
				+ "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
		ResultSet results = null;
		QueryExecution qexec = null;

		final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
		qexec = QueryExecutionFactory.create(cquery, this.labelmodel);
		results = qexec.execSelect();

		if (results != null) {
			while (results.hasNext()) {
				final QuerySolution sol = results.nextSolution();
				final String label = sol.getLiteral("label").getLexicalForm();
				labellist.add(label);
			}
			qexec.close();
		}
	} catch (QueryParseException e) {
		Logger.getRootLogger().info("Query parse Exception");
	}
	return labellist;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:26,代码来源:CreateDBpediaIndexV2.java

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

示例8: querySubCategories

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
public Set<String> querySubCategories(final String uri) {
	final Set<String> types = new HashSet<String>();
	final String query = "SELECT ?sub WHERE { <"+uri+"> <http://www.w3.org/2004/02/skos/core#broader> ?sub }";

	try {
		final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
		final QueryExecution qexec = QueryExecutionFactory.create(que,
				categorySkosModel);
		final ResultSet results = qexec.execSelect();

		while (results.hasNext()) {
			final QuerySolution sol = results.nextSolution();
			final String name = sol.getResource("sub").toString();
			types.add(new String(name));
		}
	} catch (final QueryException e) {
		Logger.getRootLogger().error(e.getStackTrace());
	}
	return types;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:21,代码来源:DBpediaCategoryCorrection.java

示例9: queryEntitiesFromCategory

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的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;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:27,代码来源:EvaluatePureDbpediaCategories.java

示例10: checkRedirects

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
private String checkRedirects(String resource) {
	String result = resource;
	try {

		Query query = QueryFactory
				.create("SELECT ?redirect WHERE{ <"
						+ resource
						+ "> <http://dbpedia.org/ontology/wikiPageRedirects> ?redirect. }");
		QueryExecution qe = QueryExecutionFactory.create(query, this.m);
		ResultSet results = qe.execSelect();
		while (results.hasNext()) {
			QuerySolution sol = results.nextSolution();
			result = sol.getResource("redirect").getURI();
		}
	} catch (Exception e) {
		return resource;
	}
	return result;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:20,代码来源:LimayeAnnotationParserWebTables.java

示例11: getRDFTypesFromEntity

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的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;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:24,代码来源:CreateDBpediaIndexV2.java

示例12: sparql

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * RDF Navigation using SPARQL Query
 * 
 * @param model
 *            the RDF model
 * @param query
 *            SPARQL Query String
 * @param field
 *            the placeholder of filed in parameter query
 */
private static void sparql(Model model, String query, String field) {
	Query q = QueryFactory.create(query);
	QueryExecution qexec = QueryExecutionFactory.create(q, model);
	System.out.println("Plan to run SPARQL query: ");
	System.out.println(BOUNDARY);
	System.out.println(query);
	System.out.println(BOUNDARY);
	ResultSet rs = qexec.execSelect();
	while (rs.hasNext()) {
		QuerySolution qs = rs.nextSolution();
		RDFNode name = qs.get(field);// using RDFNode currently
		if (name != null) {
			System.out.println("Hello to " + name);
		} else {
			System.out.println("No friends found!");
		}
	}
	qexec.close();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:30,代码来源:HelloSemanticWeb.java

示例13: queryRemote

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * RDF Navigation using remote SPARQL Query
 * 
 * @param service
 *            the SAPRQL end point URL
 * @param query
 *            SPARQL Query String
 * @param queryField
 *            the placeholder of filed in parameter query(sample: ?name)
 */
public static void queryRemote(final String service, final String query, String... queryFields) {
	if (queryFields == null || queryFields.length == 0) {
		return;
	}

	QueryExecution qexec = QueryExecutionFactory.sparqlService(service, query);

	System.out.println("Plan to run remote SPARQL query: ");
	System.out.println(BOUNDARY);
	System.out.println(query);
	System.out.println(BOUNDARY);

	ResultSet rs = qexec.execSelect();
	rendererResultSet(rs, queryFields);

	System.out.println(BOUNDARY);

	qexec.close();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:30,代码来源:SPARQLUtils.java

示例14: crm2AliadaClass

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
public String crm2AliadaClass(final String crmClass) {
	final Query query = QueryFactory.create(CRM_TO_ALIADA_CLASS_P1 + crmClass + CRM_TO_ALIADA_CLASS_P2);
	ARQ.getContext().setTrue(ARQ.useSAX);
       
	QueryExecution execution = null;
	try {
		execution = QueryExecutionFactory.sparqlService("http://172.25.5.15:8890/sparql", query);
		execution.setTimeout(2000, 5000);
		final ResultSet results = execution.execSelect();
		//Iterating over the SPARQL Query results
		while (results.hasNext()) {
			QuerySolution soln = results.nextSolution();
			//Printing DBpedia entries' abstract.
			System.out.println(soln.get("?abstract"));   
			return soln.get("?abstract").asResource().getURI();
		}
		return "NULL";
       } finally {
       	try {
       		execution.close();
		} catch (Exception exception) {
			// TODO: handle exception
		}
       }

}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:27,代码来源:AliadaRDFStoreDAO.java

示例15: loadVocabularies

import com.hp.hpl.jena.query.QueryExecution; //导入方法依赖的package包/类
@Override
public void loadVocabularies() {

	QuerySolutionMap binding = new QuerySolutionMap();
	binding.add("linkset", this.dataset);
	Query query = QueryFactory.create(linksetVocabularyQuery);
	QueryExecution qexec = QueryExecutionFactory.create(query, voidInstance.getVoidModel(),
			binding);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource vocabulary = soln.getResource("vocabulary").as(
					OntResource.class);
			vocabularies.add(vocabulary);
		}
	} catch (Exception e) {
		Log.debug(Linkset.class, "Failed linksetVocabularyQuery");
		Log.debug(Linkset.class, e.getStackTrace().toString());
	} finally {
		qexec.close();
	}

}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:26,代码来源:Linkset.java


注:本文中的com.hp.hpl.jena.query.QueryExecution.execSelect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。