2010-06-04 46 views
4

CONSTRUCT是替代SPARQL結果子句SELECTCONSTRUCT不是返回一個結果值表,而是返回一個RDF圖。例如,在以下Java代碼中運行此查詢會生成HttpException: 406 Unacceptable。但如果不是CONSTRUCT區塊,我選擇SELECT ?x,這很好。 Jena是否支持CONSTRUCT,如果有,如何?這兩個查詢都可以被DBpedia endpoint接受。Jena Sparql和構造

PREFIX : <http://dbpedia.org/resource/> 
PREFIX onto: <http://dbpedia.org/ontology/> 

CONSTRUCT { 
    :France onto:anthem ?x 
} 

WHERE 
{ 
    :France onto:anthem ?x . 
} 
Query query = QueryFactory.create("the query goes here"); 
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql",  query); 
ResultSet results = qexec.execSelect(); 
ResultSetFormatter.out(System.out, results, query); 

回答

11

耶拿支持CONSTRUCT,但要獲得你需要調用不同的方法,因爲execSelectResultSet僅供SELECT查詢結果。使用這個來代替:

Model results = qexec.execConstruct(); 
results.write(System.out, "TURTLE"); 

Model是耶拿的接口,用於訪問RDF圖,看到javadocs瞭解詳情。

+0

完美工作,write方法做所有的工作對我來說,THX – blueomega 2010-06-05 09:32:15

2

ResultSetFormatter.out(System.out的,結果,查詢)無法找到符號和標識預期的錯誤發生在這一點上