2017-05-31 31 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