为 MESH 端点执行 SPARQL 查询时出现问题
Probleme executing SPARQL query for MESH Endpoint
我在这个网站上执行这段代码MESH Query它returns正确的结果
但是当我使用 Jena 执行时,它 returns null。
在耶拿
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);
我编辑了查询,结果不一样,因为“http://id.nlm.nih.gov/mesh/sparql”不知道 meshv:Descriptor,所以我删除了它,现在我正在尝试将查询重新表述为结果相同
您必须使用 QueryEngineHTTP
这样您就可以通过 HTTP 参数启用推理 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);
我在这个网站上执行这段代码MESH Query它returns正确的结果 但是当我使用 Jena 执行时,它 returns null。 在耶拿
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);
我编辑了查询,结果不一样,因为“http://id.nlm.nih.gov/mesh/sparql”不知道 meshv:Descriptor,所以我删除了它,现在我正在尝试将查询重新表述为结果相同
您必须使用 QueryEngineHTTP
这样您就可以通过 HTTP 参数启用推理 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);