我试图用Turtle格式编码一些植物数据,并使用RDFLib从Python读取这些数据。但是,我有麻烦了,我不确定是因为我的乌龟畸形还是我是misusingRDFLib。
我的测试数据是:@PREFIX rdf: .
@PREFIX rdfs: .
@PREFIX p: .
p:description a rdfs:Property .
p:name a rdfs:Property .
p:language a rdfs:Property .
p:value a rdfs:Property .
p:gender a rdfs:Property .
p:inforescence a rdfs:Property .
p:color a rdfs:Property .
p:sense a rdfs:Property .
p:type a rdfs:Property .
p:fruit a rdfs:Property .
p:flower a rdfs:Property .
p:dataSource a rdfs:Property .
p:degree a rdfs:Property .
p:date a rdfs:Property .
p:person a rdfs:Property .
p:c2a7b9a3-c54a-41f5-a3b2-155351b3590f
p:description [
p:name [
p:kingdom "Plantae" ;
p:division "Pinophyta" ;
p:class "Pinopsida" ;
p:order "Pinales" ;
p:family "Pinaceae" ;
p:genus "Abies" ;
p:species "A. alba" ;
p:language "latin" ;
p:given_by [
p:person p:source/Philip_Miller ;
p:start_date "1923-1-2"^^
]
] ;
p:name [
p:language "english" ;
p:value "silver fir"
] ;
p:flower [
p:gender "male"@en ;
p:inflorescence "catkin"@en ;
p:color "brown"@en ;
p:color "yellow"@en ;
p:sense "straight"@en
] ;
p:flower [
p:gender "female"@en ;
p:inflorescence "catkin"@en ;
p:color "pink"@en ;
p:color "yellow"@en ;
p:sense "straight"@en
] ;
p:fruit [
p:type "cone"@en ;
p:color "brown"@en
]
] .
我的Python是:import rdflib
g = rdflib.Graph()
#result = g.parse('trees.ttl')
#result = g.parse('trees.ttl', format='ttl')
result = g.parse('trees.ttl', format='n3')
print len(g)
for stmt in g:
print stmt
这给了我错误:ValueError: Found @PREFIX when expecting a http://www.w3.org/2000/10/swap/grammar/n3#document . todoStack=[['http://www.w3.org/2000/10/swap/grammar/n3#document', []]]
我已经尝试过改变parse()参数,但所有这些都会给我一个错误。我几乎找不到任何解析海龟的例子。我做错什么了?