2017-05-31 97 views
0

我在這個網站上執行此代碼MESH Query它返回正確的結果 但是,當我使用耶拿執行它會返回null。 在耶拿問題執行MESH端點的SPARQL查詢

String s = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#> 
PREFIX mesh: <http://id.nlm.nih.gov/mesh/> 
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/> 
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/> 
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/> 
SELECT ?d ?dName ?c ?cName 
FROM <http://id.nlm.nih.gov/mesh> 
WHERE { 
    ?d a meshv:Descriptor . 
    ?d meshv:concept ?c . 
    ?d rdfs:label ?dName . 
    ?c rdfs:label ?cName 
    FILTER(REGEX(?dName,'infection','i') || REGEX(?cName,'infection','i')) 
} 
ORDER BY ?d "; 
Query query = QueryFactory.create(s); 
      QueryExecution qe = QueryExecutionFactory.sparqlService("http://id.nlm.nih.gov/mesh/sparql", query); 
      ResultSet results = qe.execSelect(); 
      ResultSetFormatter.out(System.out, results, query); 
+0

我想你必須啓用RDFS推理,很可能通過'qe.addParam(「推理」, 'true')' –

+0

這個函數不存在。 –

+1

最有可能。這個想法是你必須在URL中設置'&inference = true'。你有沒有看到「RDFS推理?」用戶界面中的複選框? –

回答

2

你必須使用QueryEngineHTTP這樣可以啓用通過HTTP PARAM inference=true推斷:

Query query = QueryFactory.create(s); 
QueryEngineHTTP qe = new QueryEngineHTTP("http://id.nlm.nih.gov/mesh/sparql", query); 
qe.addPAram("inference", "true") 
ResultSet results = qe.execSelect(); 
ResultSetFormatter.out(System.out, results, query); 
+0

謝謝你現在的作品,我明白了 –

0

我編輯查詢,我有一個resut它是不一樣的,因爲「http://id.nlm.nih.gov/mesh/sparql」不知道meshv:描述所以我刪除了它,現在我想重新制定查詢有同樣的結果

+0

爲什麼?理解您在UI中啓用了「RDFS推理」是非常重要的,默認情況下它未啓用。並且沒有與您的查詢匹配的類「meshv:Descriptor」的直接實例。解決方法是在Jena中通過添加一個URL參數'&inference = true'來啓用它,正如StanislavKralin在他的評論中已經提出的那樣。 – AKSW