我正在尝试使用 rdflib 以 xml 格式加载和解析一个非常简单的 rdf 文件。我不认为,它解析正确。这是我的 rdf/xml 文件,
<rdf:RDF xmlns:rdf="http://w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
>
<foaf:Person>
<foaf:name>Peter Parker</foaf:name>
</foaf:Person>
</rdf:RDF>
我的python脚本在这里,
from rdflib import Graph
g = Graph()
g.parse("person_1.rdf", format="xml")
print(len(g))
print(g.serialize(format="xml").decode("u8"))
print("Test - 2")
而且,这是程序输出,
3
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<rdf:Description rdf:nodeID="Nababb97ad88341329a7cf22cec65c00c">
<rdf:type rdf:resource="http://w3.org/1999/02/22-rdf-syntax-ns#RDF"/>
<foaf:Person rdf:nodeID="Nfa7b9ab24fae4bcd9ffbaa13aeb733db"/>
</rdf:Description>
<rdf:Description rdf:nodeID="Nfa7b9ab24fae4bcd9ffbaa13aeb733db">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/name"/>
</rdf:Description>
</rdf:RDF>
Test - 2
我在输出中没有看到“Peter Parker”这个名字。难道我做错了什么。提前致谢。