RDFLib似乎可以support解析RDFa数据。在实现一个代码片段来解析带RDFa注释的HTML页面时,我遇到了这个问题:
Traceback (most recent call last):
File "/home/zonk/.local/lib/python3.8/site-packages/rdflib/plugin.py", line 107, in get
p = _plugins[(name, kind)]
KeyError: ('html', <class 'rdflib.parser.Parser'>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "basic-rdfa.py", line 7, in <module>
g.parse("beatles.rdfa.html", format='html')
File "/home/zonk/.local/lib/python3.8/site-packages/rdflib/graph.py", line 1209, in parse
parser = plugin.get(format, Parser)()
File "/home/zonk/.local/lib/python3.8/site-packages/rdflib/plugin.py", line 109, in get
raise PluginException("No plugin registered for (%s, %s)" % (name, kind))
rdflib.plugin.PluginException: No plugin registered for (html, <class 'rdflib.parser.Parser'>)
使用以下代码片段:
from rdflib import Graph, plugin
g = Graph()
g.parse("beatles.rdfa.html", format='html')
for subj, pred, obj in g:
if(subj, pred, obj) not in g:
raise Exception("Zonk!")
print(f"Graph g has {len(g)} statements.")
print(g.serialize(format="turtle"))
使用以下虚拟数据:
<!DOCTYPE html>
<html lang="en">
<head>
<title>John Lennon</title>
</head>
<div vocab="http://schema.org/">
<div typeof="Person">
<link property="rdfa:copy" href="#lennon"/>
<link property="rdfa:copy" href="#band"/>
</div>
<p resource="#lennon" typeof="rdfa:Pattern">
Name: <span property="name">John Lennon</span>
<p>
<div resource="#band" typeof="rdfa:Pattern">
<div property="band" typeof="MusicGroup">
<link property="rdfa:copy" href="#beatles"/>
</div>
</div>
<div resource="#beatles" typeof="rdfa:Pattern">
<p>Band: <span property="name">The Beatles</span></p>
<p>Size: <span property="size">4</span> players</p>
</div>
</div>
</html>
实际上,plugin.py
中没有注册任何超文本标记语言数据的行。在这种情况下,我如何解析带rdfa注释的数据?
提前谢谢你。
发布于 2021-08-09 06:37:55
抱歉,文档已过期,当前RDFlib版本(6.0.0)或之前的版本(5.0.0)不再支持RDFa解析
要获得RDFa支持,您必须使用RDFlib 4.2.2 (https://github.com/RDFLib/rdflib/tree/4.2.2)。
https://stackoverflow.com/questions/68500028
复制相似问题