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


Java QueryFactory.create方法代碼示例

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


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

示例1: checkContainment

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的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.QueryFactory; //導入方法依賴的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.QueryFactory; //導入方法依賴的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: main

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
	ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
	String sparql = 
		"PREFIX dc: <http://purl.org/dc/elements/1.1/>" +
		"PREFIX foaf: <http://xmlns.com/foaf/0.1/>" +
		"SELECT ?paperTitle ?authorName WHERE {" +
		"    ?paper dc:title ?paperTitle . " +
		"    ?paper dc:creator ?author ." +
		"    ?author foaf:name ?authorName ." +
		"}";
	Query q = QueryFactory.create(sparql); 
	ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
	while (rs.hasNext()) {
		QuerySolution row = rs.nextSolution();
		System.out.println("Title: " + row.getLiteral("paperTitle").getString());
		System.out.println("Author: " + row.getLiteral("authorName").getString());
	}
	m.close();
}
 
開發者ID:d2rq,項目名稱:r2rml-kit,代碼行數:20,代碼來源:SPARQLExample.java

示例5: checkRedirects

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

示例6: checkAvailability

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的package包/類
private String checkAvailability(String resource) {
	try {
		Query query = QueryFactory
				.create("SELECT ?label WHERE{ <"
						+ resource
						+ "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }");
		QueryExecution qe = QueryExecutionFactory.create(query, this.m_l);
		ResultSet results = qe.execSelect();
		if (results.hasNext()) {
			return resource;
		}
	} catch (Exception e) {
		return "";
	}
	return "";
}
 
開發者ID:quhfus,項目名稱:DoSeR,代碼行數:17,代碼來源:LimayeAnnotationParserWebTables.java

示例7: querySubCategories

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

示例8: getDbPediaLabel

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

示例9: queryConstruct

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

示例10: sparql

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

示例11: queryEntitiesFromCategory

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的package包/類
private Set<String> queryEntitiesFromCategory(final String catUri) {
	Set<String> set = new HashSet<String>();
	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();
		while (results.hasNext()) {
			final QuerySolution sol = results.nextSolution();
			set.add(sol.getResource("entities").getURI()
					.replaceAll("http://dbpedia.org/resource/", ""));
		}

	} catch (final QueryException e) {
		Logger.getRootLogger().error(e.getStackTrace());
	}
	return set;
}
 
開發者ID:quhfus,項目名稱:DoSeR,代碼行數:22,代碼來源:FullyEvaluateCategories.java

示例12: testMetric_TotalExecutions_Global

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

示例13: getRedirect

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的package包/類
private String getRedirect(String uri) {
	final Model model = DisambiguationMainService.getInstance().getDBpediaRedirects();
	final String query = "SELECT ?label WHERE{ <" + uri
			+ "> <http://dbpedia.org/ontology/wikiPageRedirects> ?label. }";
	ResultSet results = null;
	QueryExecution qexec = null;
	String redirect = null;
	try {
		final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
		qexec = QueryExecutionFactory.create(cquery, model);
		results = qexec.execSelect();
	} catch (final QueryException e) {
		Logger.getRootLogger().error(e.getStackTrace());
	} finally {
		if (results.hasNext()) {
			final QuerySolution sol = results.nextSolution();
			redirect = sol.getResource("label").getURI();
		}
	}
	return redirect;
}
 
開發者ID:quhfus,項目名稱:DoSeR,代碼行數:22,代碼來源:TimeNumberDisambiguation.java

示例14: sparqlDescribe

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的package包/類
/**
 * @return opened result Model
 */
@Override
public ClosableIterable<Statement> sparqlDescribe(String queryString)
        throws ModelRuntimeException {
	assertModel();
	Query query = QueryFactory.create(queryString);
	QueryExecution qexec = QueryExecutionFactory.create(query, this.jenaModel);
	
	if(query.isDescribeType()) {
		com.hp.hpl.jena.rdf.model.Model m = qexec.execDescribe();
		Model resultModel = new ModelImplJena(null, m, Reasoning.none);
		resultModel.open();
		return resultModel;
	} else {
		throw new RuntimeException("Cannot handle this type of queries! Please use DESCRIBE.");
	}
	
}
 
開發者ID:semweb4j,項目名稱:semweb4j,代碼行數:21,代碼來源:ModelImplJena.java

示例15: queryDbPediaCategoryLabel

import com.hp.hpl.jena.query.QueryFactory; //導入方法依賴的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;
}
 
開發者ID:quhfus,項目名稱:DoSeR,代碼行數:25,代碼來源:RDFGraphOperations.java


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