【发布时间】:2019-04-24 16:59:58
【问题描述】:
如果我使用 Jena 与 http://dbpedia.org/sparql 的查询表单,结果会不一样
我在 Jena 中的代码(我尝试返回两个列表,其中包含搜索到的文本名称的类型):
s1 = "Ketolide";
s2 = "Aminocoumarin";
String sparqlQueryString1 = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"SELECT distinct ?type1 " +
"WHERE { ?data rdfs:label ?label1. ?data rdf:type ?type1. FILTER contains(lcase(str(?label1)),'" + s1.toLowerCase() + "'). }";
Query query = QueryFactory.create(sparqlQueryString1);
QueryEngineHTTP objectToExec = QueryExecutionFactory.createServiceRequest("http://dbpedia.org/sparql", query);
objectToExec.addParam("timeout","3000");
ResultSet results = objectToExec.execSelect();
List<QuerySolution> s = ResultSetFormatter.toList(results);
ResultSetFormatter.out(System.out, results, query);
sparqlQueryString1 = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"SELECT distinct ?type1 " +
"WHERE {?data rdfs:label ?label1. ?data rdf:type ?type1. FILTER contains(lcase(str(?label1)),'" + s2.toLowerCase() + "'). }";
query = QueryFactory.create(sparqlQueryString1);
objectToExec = QueryExecutionFactory.createServiceRequest("http://dbpedia.org/sparql", query);
objectToExec.addParam("timeout","3000");
results = objectToExec.execSelect();
List<QuerySolution> s22 = ResultSetFormatter.toList(results);
ResultSetFormatter.out(System.out, results, query);
当我在http://dbpedia.org/sparql 的查询表单中使用相同的查询时,它会得到结果:
SELECT distinct ?type1 WHERE{ ?data rdf:type ?type1. ?data rdfs:label ?label1 . FILTER contains(lcase(str(?label1)), 'ketolide') .}
这会返回:
type1
http://dbpedia.org/ontology/ChemicalCompound
http://dbpedia.org/class/yago/WikicatKetolideAntibiotics
http://dbpedia.org/class/yago/Agent114778436
http://dbpedia.org/class/yago/Antibacterial102716205
http://dbpedia.org/class/yago/Antibiotic102716866
http://dbpedia.org/class/yago/CausalAgent100007347
http://dbpedia.org/class/yago/Drug103247620
http://dbpedia.org/class/yago/Matter100020827
http://dbpedia.org/class/yago/Medicine103740161
http://dbpedia.org/class/yago/PhysicalEntity100001930
http://dbpedia.org/class/yago/Substance100020090
http://dbpedia.org/class/yago/WikicatAntibiotics
造成这种差异的原因和原因是什么?
【问题讨论】:
-
您的查询很糟糕,因为它必须对基本上所有具有标签的资源进行全面扫描,然后应用字符串函数。您在表单中得到一个结果是因为它偶然在默认的 30 秒时间内找到了一些匹配的资源。 3000 以毫秒为单位,因此为 3 秒。三合店不太可能在这段时间内找到任何东西