我正在尝试学习使用RDF,并试图从dbpedia中提取一组事实作为我的学习练习。下面的代码示例在某种程度上是可行的,但是对于像配偶这样的主题,它总是会把他们自己拉出来。在
这是代码块的输出,显示了我得到的一些奇怪的结果(参见属性中的混合输出,他与自己结婚的事实,以及约瑟芬的错误名字?在
Accessing facts for Napoleon held at http://dbpedia.org/resource/Napoleon
There are 800 facts about Napoleon stored at the URI
http://dbpedia.org/resource/Napoleon
Here are a few:-
Ontology:deathdate
Napoleon died on 1821-05-05
Ontology:birthdate
Napoleon was born on 1769-08-15
Property:spouse retruns the person themslves twice !
Napoleon was married to Marie Louise, Duchess of Parma
Napoleon was married to Napoleon
Napoleon was married to Jos%C3%A9phine de Beauharnais
Napoleon was married to Napoleon
Property:title retruns text and uri's
Napoleon Held the title: "The Death of Napoleon"
Napoleon Held the title: http://dbpedia.org/resource/Emperor_of_the_French
Napoleon Held the title: http://dbpedia.org/resource/King_of_Italy
Napoleon Held the title: First Consul of France
Napoleon Held the title: Provisional Consul of France
Napoleon Held the title: http://dbpedia.org/resource/Napoleon
Napoleon Held the title: Emperor of the French
Napoleon Held the title: http://dbpedia.org/resource/Co-Princes_of_Andorra
Napoleon Held the title: from the Memoirs of Bourrienne, 1831
Napoleon Held the title: Protector of the Confederation of the Rhine
Ontology birth place returns three records
Napoleon was born in Ajaccio
Napoleon was born in Corsica
Napoleon was born in Early modern France
这就是产生上述输出的python,它需要rdflib,而且还需要大量的工作。在
^{pr2}$
获取姓名
*get_name_from_uri*正在对该uri执行某些操作。由于DBpedia数据几乎所有的内容都有
^{pr2}$rdfs:labels
,所以最好请求rdfs:label
并将其用作值。E、 g.,看看这个SPARQL查询运行的结果the DBpedia SPARQL endpoint:意料之外的配偶
subject_objects的文档说明
您看到了,正确的,DBpedia中有四个三元组具有谓词
dbpprop:spouse
(顺便问一下,您没有使用dbpedia-owl:spouse
有什么原因吗?)并将Napoleon
作为主语或宾语:每一个你都要打印出来
其中X是三元组的对象。也许您应该改为使用^{} :
URI与文本(文本)结果
DBpedia本体属性(其uri以
http://dbpedia.org/ontology/
开头,通常缩写为dbpedia-owl:
)描述的数据比DBpedia原始数据属性(uri以http://dbpedia.org/property/
开头,通常缩写为dbpprop:
)描述的数据要“干净”得多。E、 g.当您查看标题时,您使用的是属性dbpprop:title
,并且uri和文本都作为值。不过,看起来并没有dbpedia-owl:title
,所以在这种情况下,您只需要处理它。但很容易过滤出其中一种:相关问题 更多 >
编程相关推荐