我想知道如何从 Jena SPARQL 查询的结果中创建 .txt 或 .xls 文件输出。任何人都可以帮忙吗?
这里是代码的一部分
InputStream in = new FileInputStream(new File("./src/myfile.owl"));
Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
model.read(in, null);
in.close();
String queryString =
"prefix : <http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#> " +
"prefix rdfs: <" + RDFS.getURI() + "> " +
"prefix owl: <" + OWL.getURI() + "> " +
"prefix rdf: <" + RDF.getURI() + "> " +
"select ?Model " +
"where {" +
"{?Model rdf:type :ApplicationModel. " +
"?Model :hasDomain ?domain. " +
"?domain :domainCode ?domaincode. " +
"FILTER (?domaincode =" + "'"+ domainElement.getAttribute(attrDomain) + "'"+ ")" +
"?Model :hasPhase ?phase." +
"?phase :name ?phasecode. " +
"FILTER (?phasecode = "+ "'"+ phaseElement.getAttribute(attrPhase)+"'"+")" +
"?Model :hasLevelOfDetail ?lod." +
"?lod :name ?lodcode." +
"FILTER (?lodcode = "+ lodElement.getAttribute(attrLOD) +")" +
"}"
;
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
qe.close();
}
}