本文整理汇总了Java中com.hp.hpl.jena.query.ResultSetFormatter.out方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSetFormatter.out方法的具体用法?Java ResultSetFormatter.out怎么用?Java ResultSetFormatter.out使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.query.ResultSetFormatter
的用法示例。
在下文中一共展示了ResultSetFormatter.out方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
}
示例4: 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");
}
示例5: 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);
}
示例6: 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);
}
示例7: run
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
@Override
public void run() {
dataset.begin(ReadWrite.READ);
System.out.println("------------------");
System.out.println(query);
Op op = Algebra.compile(query);
op = Algebra.optimize(op);
System.out.println(op);
System.out.println("------------------");
System.out.println(query);
long time = System.currentTimeMillis();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qe.execSelect();
if(pretty){
System.out.println("Output as pretty printed text");
ResultSetFormatter.out(stream, results, query);
}else{
System.out.println("Output as CSV");
ResultSetFormatter.outputAsCSV(stream, results);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
e.printStackTrace();
}
time = System.currentTimeMillis() - time;
String timeString = "\n Performed query in: "+time+"ms";
try {
stream.write(timeString.getBytes());
stream.showText();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
}
System.out.println(time);
System.out.println("Finished query");
dataset.end();
}
示例8: main
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
public static void main(String[] args) {
ParameterizedSparqlString qs = new ParameterizedSparqlString(""
+ "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n"
+ "prefix dbpprop: <http://dbpedia.org/property/>\n"
+ "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+
"SELECT DISTINCT * \n" + "WHERE { \n"
+ " ?resource rdfs:label ?label ;\n"
+ " dbpedia-owl:abstract ?abstract .\n"
+ "FILTER ( lang(?abstract) = 'en' ) \n" + "}");
Literal london = ResourceFactory.createLangLiteral("London", "en");
qs.setParam("label", london);
System.out.println(qs);
QueryExecution exec = QueryExecutionFactory.sparqlService(
"http://dbpedia.org/sparql", qs.asQuery());
ResultSet results = ResultSetFactory.copyResults(exec.execSelect());
while (results.hasNext()) {
QuerySolution sol = (QuerySolution) results.next();
RDFNode node = sol.get("resource");
System.out.println(sol.get("?abstract"));
System.out.println(node);
}
// A simpler way of printing the results.
ResultSetFormatter.out(results);
}
示例9: dump
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
private void dump(Table table)
{
Log.debug(this,"Table: "+Utils.className(table)) ;
QueryIterator qIter = table.iterator(null) ;
ResultSet rs = new ResultSetStream(table.getVarNames(), null, table.iterator(null)) ;
ResultSetFormatter.out(rs) ;
}
示例10: showQueryResults
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
private void showQueryResults(String queryString, HttpServletRequest request, HttpServletResponse response)
throws IOException {
Query query = QueryFactory.create(queryString);
if(query.isSelectType() || query.isDescribeType()) {
Config config = new Config(request);
ResultsFormat fmt = ResultsFormat.lookup(request.getParameter("format"));
Dataset tdbstore = TDBFactory.createDataset(config.getTripleStoreDir());
QueryExecution qexec = QueryExecutionFactory.create(query, tdbstore);
qexec.getContext().set(TDB.symUnionDefaultGraph, true);
if(query.isSelectType()) {
ResultSet results = qexec.execSelect();
if(fmt == null) {
out.print(queryString+"\n");
ResultSetFormatter.out(out, results, query);
}
else
ResultSetFormatter.output(out, results, fmt);
}
else {
Model model = qexec.execDescribe();
RDFWriter rdfWriter = model.getWriter("RDF/XML-ABBREV");
rdfWriter.setProperty("showXmlDeclaration", "true");
rdfWriter.setProperty("tab", "6");
rdfWriter.write(model, out, null);
}
}
else {
out.print("Only select or describe queries allowed");
}
}
示例11: getWikidataLabelById
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
/**
* Sample query: "https://www.wikidata.org/wiki/Q6607" for guitar
* @param id
* @return DBPedia response
*/
public String getWikidataLabelById(String id) {
String res = "";
ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"prefix wd: <http://www.wikidata.org/entity/>\n" +
"\n" +
"select *\n" +
"where {\n" +
" wd:Q" + id + " rdfs:label ?label .\n" +
" FILTER (LANG(?label) = 'en') .\n" +
" }\n" +
"LIMIT 1"
);
// Literal labelLiteral = ResourceFactory.createLangLiteral( label, "en" );
// qs.setParam("label", labelLiteral);
log.debug( qs );
QueryExecution exec = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, qs.asQuery());
ResultSet resultSet = exec.execSelect();
// Normally you'd just do results = exec.execSelect(), but I want to
// use this ResultSet twice, so I'm making a copy of it.
ResultSet results = ResultSetFactory.copyResults( resultSet );
while ( results.hasNext() ) {
// As RobV pointed out, don't use the `?` in the variable
// name here. Use *just* the name of the variable.
// System.out.println( results.next().get( "resource" ));
QuerySolution resQs = results.next();
res = res + resQs.get( "resource" ) + "#";
res = res + resQs.get( "description" );
// System.out.println( resQs.get( "resource" ));
// System.out.println( resQs.get( "description" ));
}
// A simpler way of printing the results.
ResultSetFormatter.out( results );
// return results.toString();
if (res.equals(""))
res = "#";
return res;
}
示例12: queryDBPedia
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
/**
* Sample query: "http://dbpedia.org/page/Chicago_blues"
* @param label
* @return DBPedia response
*/
public String queryDBPedia(String label) {
String res = "";
ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"\n" +
"select ?resource ?description where {\n" +
// " ?resource rdfs:label \"" + label + "\"@en .\n" +
" ?resource rdfs:label ?label .\n" +
" ?resource rdfs:comment ?description .\n" +
" FILTER (LANG(?description) = 'en') .\n" +
// "select ?resource where {\n" +
// " ?resource rdfs:label ?label\n" +
"}" );
Literal labelLiteral = ResourceFactory.createLangLiteral( label, "en" );
qs.setParam("label", labelLiteral);
System.out.println( qs );
QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());
// Normally you'd just do results = exec.execSelect(), but I want to
// use this ResultSet twice, so I'm making a copy of it.
ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );
while ( results.hasNext() ) {
// As RobV pointed out, don't use the `?` in the variable
// name here. Use *just* the name of the variable.
// System.out.println( results.next().get( "resource" ));
QuerySolution resQs = results.next();
res = res + resQs.get( "resource" ) + "#";
res = res + resQs.get( "description" );
// System.out.println( resQs.get( "resource" ));
// System.out.println( resQs.get( "description" ));
}
// A simpler way of printing the results.
ResultSetFormatter.out( results );
// return results.toString();
if (res.equals(""))
res = "#";
return res;
}
示例13: queryDBPediaByLanguage
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
/**
* Sample query: "http://dbpedia.org/page/Chicago_blues"
* @param label
* @return DBPedia response
*/
public String queryDBPediaByLanguage(String label, String language) {
String res = "";
ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"\n" +
"select ?resource ?description where {\n" +
// " ?resource rdfs:label \"" + label + "\"@en .\n" +
" ?resource rdfs:label ?label .\n" +
" ?resource rdfs:comment ?description .\n" +
" FILTER (LANG(?description) = '" + language + "') .\n" +
// "select ?resource where {\n" +
// " ?resource rdfs:label ?label\n" +
"}" );
Literal labelLiteral = ResourceFactory.createLangLiteral( label, language );
qs.setParam("label", labelLiteral);
System.out.println( qs );
QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());
// Normally you'd just do results = exec.execSelect(), but I want to
// use this ResultSet twice, so I'm making a copy of it.
ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );
while ( results.hasNext() ) {
// As RobV pointed out, don't use the `?` in the variable
// name here. Use *just* the name of the variable.
// System.out.println( results.next().get( "resource" ));
QuerySolution resQs = results.next();
res = res + resQs.get( "resource" ) + "#";
res = res + resQs.get( "description" );
// System.out.println( resQs.get( "resource" ));
// System.out.println( resQs.get( "description" ));
}
// A simpler way of printing the results.
ResultSetFormatter.out( results );
// return results.toString();
if (res.equals(""))
res = "#";
return res;
}
示例14: tdbload
import com.hp.hpl.jena.query.ResultSetFormatter; //导入方法依赖的package包/类
public void tdbload() {
Dataset dataset = TDBFactory.createDataset("tdb");
Model model = dataset.getNamedModel("fdg");
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);
}