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


Java ResultSetFormatter类代码示例

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


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

示例1: main

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的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

示例2: queryExecute

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public void queryExecute(Integer testNumber) throws Exception {
	String queryString = readFile(path + queryFolder + "/test" + testNumber + "/query.txt",
			Charset.defaultCharset());
	String queryResultString = readFile(path + queryFolder + "/test"+ testNumber + "/queryresult.txt",
			Charset.defaultCharset());
	
	RemediatorQuery query = RemediatorQueryFactory.create(queryString);
	RemediatorFederatedQuery federatedQuery = RemediatorFederatedQueryFactory.create(query, voidModel, false);
	
	QueryExecution  queryExecution = RemediatorQueryExecutionFactory.create(federatedQuery);
	
	try {
		ResultSet results = queryExecution.execSelect();
		String resultString = ResultSetFormatter.asText(results);
		writeFile(path + queryFolder + "/test"
				+ testNumber + "/queryresult.res.txt", resultString.toString() ); 
		assertEquals(resultString.toString(), queryResultString.replaceAll("\\s+",
				""), resultString.toString().replaceAll("\\s+", ""));
	} catch (Exception e) {
		fail(e.getMessage());
	} finally {
		queryExecution.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:25,代码来源:RemediatorQueryExecutionFactoryTest.java

示例3: queryExecute

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public void queryExecute(Integer testNumber) throws Exception {
	String rewrittenQueryString = readFile(path + queryFolder + "/test" + testNumber + "/rewrite.txt",
			Charset.defaultCharset());
	String queryResultString = readFile(path + queryFolder + "/test"+ testNumber + "/queryresult.txt",
			Charset.defaultCharset());
	
	QueryExecution  queryExecution = RemediatorQueryExecutionFactory.create(rewrittenQueryString);
	
	try {
		ResultSet results = queryExecution.execSelect();
		String resultString = ResultSetFormatter.asText(results);
		writeFile(path + queryFolder + "/test"
				+ testNumber + "/queryresult.res.txt", resultString.toString() ); 
		assertEquals(resultString.toString(), queryResultString.replaceAll("\\s+",
				""), resultString.toString().replaceAll("\\s+", ""));
	} catch (Exception e) {
		fail(e.getStackTrace().toString());
	} finally {
		queryExecution.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:22,代码来源:RemediatorQueryExecutionTest.java

示例4: main

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	try {
		SolRDF solrdf = SolRDF.newBuilder()
				.withEndpoint("http://127.0.0.1:8080/solr/store")
				.withGraphStoreProtocolEndpointPath("/rdf-graph-store")
				.withSPARQLEndpointPath("/sparql")
				.build();
		
		solrdf.add(new FileReader("/work/workspaces/solrdf/solrdf/solrdf/solrdf-integration-tests/src/test/resources/sample_data/faceting_test_dataset.nt"), "N-TRIPLES");
		
		solrdf.commit();
		
		CloseableResultSet rs = null;
		try {
			rs = solrdf.select("SELECT * WHERE {?s ?p ?o}");
			System.out.println(ResultSetFormatter.asText(rs));
			
			Model m = solrdf.construct("DESCRIBE <http://example.org/book4>");
			System.out.println(m);
		} finally {
			rs.close();
		}
	} catch (final UnableToBuildSolRDFClientException exception) {
		exception.printStackTrace();
	}
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:27,代码来源:SearchTestCase.java

示例5: main

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	Dataset memoryDataset = DatasetFactory.createMem();
	Model memoryModel = ModelFactory.createDefaultModel();
	memoryModel.read(new FileReader("/work/workspaces/rdf/SolRDF/solrdf/src/test/resources/sample_data/one_triple_1.ttl"), "http://e.org", "TTL");
	memoryDataset.addNamedModel("http://grapha.com", memoryModel);
	
	memoryModel = ModelFactory.createDefaultModel();
	memoryModel.read(new FileReader("/work/workspaces/rdf/SolRDF/solrdf/src/test/resources/sample_data/one_triple_2.ttl"), "http://e.org", "TTL");
	memoryDataset.addNamedModel("http://graphb.com", memoryModel);
	
	memoryModel = ModelFactory.createDefaultModel();
	memoryModel.read(new FileReader("/work/workspaces/rdf/SolRDF/solrdf/src/test/resources/sample_data/one_triple_3.ttl"), "http://e.org", "TTL");
	memoryDataset.addNamedModel("http://graphc.com", memoryModel);
	
	memoryModel = ModelFactory.createDefaultModel();
	memoryModel.read(new FileReader("/work/workspaces/rdf/SolRDF/solrdf/src/test/resources/sample_data/one_triple_4.ttl"), "http://e.org", "TTL");
	memoryDataset.addNamedModel("http://graphd.com", memoryModel);
	
	final Query query = QueryFactory.create(q2());//"SELECT ?s FROM <http://grapha.com> WHERE { ?s <http://example.org/title> ?o }");
	
	System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, memoryDataset).execSelect()));
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:23,代码来源:FromAndFromNamedClauses_ITCase.java

示例6: selectTest

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
/**
 * Executes a given SELECT query against a given dataset.
 * 
 * @param data the mistery guest containing test data (query and dataset)
 * @throws Exception never, otherwise the test fails.
 */
protected void selectTest(final MisteryGuest data) throws Exception {
	load(data);
	
	try {
		assertTrue(
				Arrays.toString(data.datasets) + ", " + data.query,
				ResultSetCompare.isomorphic(
						SOLRDF_CLIENT.select(queryString(data.query)),
						(inMemoryExecution = QueryExecutionFactory.create(
								QueryFactory.create(queryString(data.query)), 
								memoryDataset)).execSelect()));
	} catch (final Throwable error) {
		log.debug("JNS\n" + ResultSetFormatter.asText(SOLRDF_CLIENT.select(queryString(data.query))));
		
		QueryExecution debugExecution = null;
		log.debug("MEM\n" + ResultSetFormatter.asText(
				(debugExecution = (QueryExecutionFactory.create(
						QueryFactory.create(queryString(data.query)), 
						memoryDataset))).execSelect()));
		
		debugExecution.close();
		throw error;
	} 
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:31,代码来源:IntegrationTestSupertypeLayer.java

示例7: doit

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public void doit() {
	Dataset dataset = DatasetFactory.createMem();
	
	Model model = dataset.getDefaultModel();
	model.read("category_labels_en.nq");
	if (model.READ){
		System.out.println("right!!");
	}
	Query q = QueryFactory.create(query);
	QueryExecution qe = QueryExecutionFactory.create(q, model);
	ResultSet rs = qe.execSelect();
	ResultSetFormatter.out(rs);
	
	

}
 
开发者ID:SaudAljaloud,项目名称:RdfLiteralStats,代码行数:17,代码来源:NquadsTest.java

示例8: getCode

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
/**
 * Gets code assoctaied with the specified label.
 * @param label label
 * @param locale locale
 * @return code or empty string if no label found
 */
public String getCode(String label, Locale locale) {
  QueryExecution queryExecutor = null;

  try {

    Query query = createQuery(label, locale);
    queryExecutor = QueryExecutionFactory.create(query, model);

    ResultSet results = queryExecutor.execSelect();
    String codeList = ResultSetFormatter.toList(results).toString();

    return codeList.indexOf("<") >= 0 ?
      codeList.substring(codeList.indexOf("<") + 1, codeList.indexOf(">")) :
      "";

  } finally {
    if (queryExecutor != null) {
      queryExecutor.close();
    }
  }
}
 
开发者ID:mhogeweg,项目名称:OntologyService,代码行数:28,代码来源:OntModelUtil.java

示例9: out

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
private static void out(Map<String, String> commands, ResultSet rs) {
	if(commands.containsKey(SPARQL_QUERY_JSON_OUTPUT_FORMAT_COMMAND)) {
		ResultSetFormatter.outputAsJSON(System.out, rs);
	} else {
		ResultSetFormatter.out(System.out, rs);
	}
}
 
开发者ID:AKSW,项目名称:KBox,代码行数:8,代码来源:Main.java

示例10: getResult

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public List<String> getResult(InputStream in, String query){
	Model model=ModelFactory.createDefaultModel();
	model.read(in,null,"TTL");
	Query q = QueryFactory.create(query);
	QueryExecution qe = QueryExecutionFactory.create(q, model);
	ResultSet qresults = qe.execSelect();
	List<QuerySolution> solutions=ResultSetFormatter.toList(qresults);
	List<String> results=new ArrayList<String>();
	for(QuerySolution qs:solutions){
		results.add(qs.toString());
	}
	return results;
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:14,代码来源:Server.java

示例11: executeQuery

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public static void executeQuery(String query){
	System.out.println("Load model...");
	OntModel ontModel=loadDefaultModel();
	System.out.println("Start to query...");
	  long start=System.currentTimeMillis();
	Query q = QueryFactory.create(prefixes+query);
	QueryExecution qe = QueryExecutionFactory.create(q, ontModel);
	ResultSet qresults = qe.execSelect();
	ResultSetFormatter.out(qresults);
	  long end=System.currentTimeMillis();
        System.out.println("Query time: "+((float)(end-start))/1000+ " s");
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:13,代码来源:QueryFunctionTest.java

示例12: main

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public static void main(String[] args)
	throws ClassNotFoundException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
Model model = ModelFactory.createDefaultModel();
InputStream in = FireSeparationDistance.class.getClassLoader().getResourceAsStream("lifeline_final.ttl");
model.read(in, null, "TTL");
System.out.println(model.size());
Model geometryModel = ModelFactory.createDefaultModel();
InputStream ing = FireSeparationDistance.class.getClassLoader().getResourceAsStream("lifeline_final_geometry.ttl");
geometryModel.read(ing, null, "TTL");
System.out.println(geometryModel.size());
Model schema=loadModel("IFC2X3_TC1.ttl","TTL");
BimSPARQL.init(model, geometryModel);
Model ibcspin = ModelFactory.createDefaultModel();
addMagicProperty(ibcspin, IBC+"hasFireSeparationDistance", prefixes+hasFireSeparationDistance, 1);
addMagicProperty(ibcspin, IBC+"hasProtectedOpeningArea", prefixes+hasProtectedOpeningArea, 1);
addMagicProperty(ibcspin, IBC+"hasUnprotectedOpeningArea", prefixes+hasUnprotectedOpeningArea, 1);
addMagicProperty(ibcspin, IBC+"hasAp", prefixes+hasAp, 1);
addMagicProperty(ibcspin, IBC+"hasAu", prefixes+hasAu, 1);
Model ibc=loadIbcData();
SPINModuleRegistry.get().registerAll(ibc, null);
for (Function f:SPINModuleRegistry.get().getFunctions())
{
	System.out.println(f.getURI());
}
com.hp.hpl.jena.query.Query query = QueryFactory.create(prefixes + mainQuery);

OntModel union = ModelFactory.createOntologyModel();
union.add(schema);
union.add(model);
union.add(geometryModel);
union.add(ibc);
System.out.println(union.size());
QueryExecution qe = QueryExecutionFactory.create(query, union);
com.hp.hpl.jena.query.ResultSet result = qe.execSelect();
      ResultSetFormatter.out(result);

      }
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:38,代码来源:FireSeparationDistance.java

示例13: main

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
public static void main(String[] args) throws FileNotFoundException{
		Model model=ModelFactory.createDefaultModel();
		InputStream in=new FileInputStream("BimSPARQL_example.ttl");
		model.read(in,null,"TTL");
		String query=prefixes+"SELECT ?s\n"+ 
"WHERE{?s ?p ?o .}";
		Query q = QueryFactory.create(query);
		QueryExecution qe = QueryExecutionFactory.create(q, model);
		ResultSet qresults = qe.execSelect();
        ResultSetFormatter.out(qresults);
	}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:12,代码来源:JenaTest.java

示例14: getInstances

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
private void getInstances() {
	File metricFile = new File(
			System.getProperty("user.dir") + "/sparql/queries/getInstances.sparql");

	List<String> lines = null;

	try {
		lines = Files.readAllLines(metricFile.toPath());
	} catch (IOException ex) {
		Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
	}
	String queryString = "";
	for (String line : lines) {
		queryString += line + System.lineSeparator();
	}
	ParameterizedSparqlString pss = new ParameterizedSparqlString();
	pss.setCommandText(queryString);
	pss.setLiteral("typename", typename);
	data.begin(ReadWrite.READ);
	List<QuerySolution> rlist = null;
	try (QueryExecution qe = QueryExecutionFactory.create(pss.asQuery(), data)) {
		ResultSet results = qe.execSelect();
		rlist = ResultSetFormatter.toList(results);
	} catch (Exception e) {
		JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
		e.printStackTrace();
	}
	instances = new String[rlist.size()];
	for(int j = 0; j < rlist.size(); j++){
		instances[j] = rlist.get(j).getLiteral("iname").getString();
	}
	data.end();
}
 
开发者ID:MarcelH91,项目名称:WikiOnto,代码行数:34,代码来源:DissolveGUI.java

示例15: getSubtypes

import com.hp.hpl.jena.query.ResultSetFormatter; //导入依赖的package包/类
private void getSubtypes() {
	File metricFile = new File(
			System.getProperty("user.dir") + "/sparql/queries/getSubtypes.sparql");

	List<String> lines = null;

	try {
		lines = Files.readAllLines(metricFile.toPath());
	} catch (IOException ex) {
		Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
	}
	String queryString = "";
	for (String line : lines) {
		queryString += line + System.lineSeparator();
	}
	ParameterizedSparqlString pss = new ParameterizedSparqlString();
	pss.setCommandText(queryString);
	pss.setLiteral("typename", typename);
	data.begin(ReadWrite.READ);
	List<QuerySolution> rlist = null;
	try (QueryExecution qe = QueryExecutionFactory.create(pss.asQuery(), data)) {
		ResultSet results = qe.execSelect();
		rlist = ResultSetFormatter.toList(results);
	} catch (Exception e) {
		JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
		e.printStackTrace();
	}
	data.end();
	subtypes= new String[rlist.size()];
	for(int j = 0; j < rlist.size(); j++){
		subtypes[j] = rlist.get(j).getLiteral("sname").getString();
	}
}
 
开发者ID:MarcelH91,项目名称:WikiOnto,代码行数:34,代码来源:DissolveGUI.java


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