无法获得CONSTRUCT查询的结果

时间:2019-03-28 14:21:15

标签: java rdf jena

我正在浏览不同的.ttl文件,并执行查询以提取所需的信息。我需要.rdf格式的结果。该查询与显示所有结果的SELECT语句完美配合,但是当我更改为CONSTRUCT时,它不显示结果。

我也看到在queryExecute中没有hasNext()函数。如何使用queryExecute构造while / hasNext部分?

while (resultat.hasNext()) {
QuerySolution sol=resultat.nextSolution();
System.out.println(sol); 

代码如下:

Model m2 = FileManager.get().loadModel(files[i].getAbsolutePath());
String queryString = "PREFIX mus: <http://data.doremus.org/ontology#>"
+ "PREFIX ecrm: <http://erlangen-crm.org/current/>"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
+ "PREFIX efrbroo: <http://erlangen-crm.org/efrbroo/>"
+ "CONSTRUCT {?F22_Self_Contained_Expression ?composerName       ?catalogueNumber}"
+ "WHERE {"
+ "?F22_Self_Contained_Expression mus:U16_has_catalogue_statement/mus:U41_has_catalogue_number ?catalogueNumber."
+ "?F28_Expression_Creation efrbroo:R17_created ?F22_Self_Contained_Expression;"
+ "ecrm:P9_consists_of/ecrm:P14_carried_out_by/ecrm:P131_is_identified_by ?composerName."
+ " }";


Query query = QueryFactory.create(queryString);
QueryExecution qexec= QueryExecutionFactory.create(query, m2);
Model resultModel = qexec.execConstruct();
qexec.close();

String outfile = "/outfile.rdf";
OutputStream out = new FileOutputStream(outfile);
RDFDataMgr.write(System.out, resultModel, Lang.RDFXML);

此查询的结果是:

</rdf:RDF>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:efrbroo="http://erlangen-crm.org/efrbroo/"
xmlns:cro="http://rhizomik.net/ontologies/copyrightonto#"
xmlns:schema="http://schema.org/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:mus="http://data.doremus.org/ontology#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:time="http://www.w3.org/2006/time#"
xmlns:ecrm="http://erlangen-crm.org/current/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:prov="http://www.w3.org/ns/prov#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
</rdf:RDF>

0 个答案:

没有答案