鉴于其wikiPageID查询Dbpedia资源并不适用于某些ID

时间:2017-06-18 10:37:40

标签: sparql dbpedia

我尝试在给定wikiPageID的情况下从dbpedia查询有关特定人员的数据。我已经尝试过这个SPARQL查询来查询Michael Jackson:

Exception in thread "main" java.lang.NumberFormatException: For input string: "11111111111111111111111111010001"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:583)
    at com.company.Main.reverseIntBitwise(Main.java:169)
    at com.company.Main.main(Main.java:150)

查询返回空结果。但是,当我换到别人的PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbp: <http://dbpedia.org/property/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?name (SAMPLE (?photoLink) as ?photo) (SAMPLE (?occupation) as occup) (SAMPLE (?spouse) as ?spouses) (SAMPLE (?spName) as ?sname) (SAMPLE (?spOccupation) as ?spOccu) (SAMPLE (?deathPlace) as ?death) (SAMPLE(?birthPlace) as ?birth) (SAMPLE(?deathDate) as ?dDate) (SAMPLE( ?birthDate) as ?bDate) { VALUES ?wikiPageID { 14995351 } ?res a dbo:Person. ?res dbp:name ?name. ?res dbo:wikiPageID ?wikiPageID. ?res dbp:birthPlace ?birthPlace. ?res dbp:birthDate ?birthDate. OPTIONAL{?res dbo:occupation ?occupation}. OPTIONAL{?res dbo:thumbnail ?photoLink}. OPTIONAL{?res dbo:spouse ?spouse. ?spouse dbp:name ?spName. ?spouse dbo:occupation ?spOccupation}. OPTIONAL{?res dbp:deathDate ?deathDate. ?res dbp:deathPlace ?deathPlace}. } GROUP BY (?name) (例如Toby Maguire - 163228)时,它可以工作。可能是造成差异的原因是什么?

1 个答案:

答案 0 :(得分:2)

如果您在DBpedia http://dbpedia.org/page/Michael_Jackson上查看Michael Jackson页面,您可以很容易地发现它没有dbp:name属性或dbp:birthPlace,甚至没有dbp:birthDate }。要解决此问题,请将OPTIONAL添加到这些属性中:

OPTIONAL{?res dbp:name ?name}.
OPTIONAL{?res dbp:birthPlace ?birthPlace}.
OPTIONAL{dbp:birthDate ?birthDate}.