使用 txt 文件作为输入创建 RDF 文件
如何使用 python 模块 RDFlib 将简单的制表符分隔 txt 文件(包含标头主语、谓语、宾语)转换为 RDF N-三重格式?
How can I convert a simple tab-delimited txt file (containing the headers subject, predicate, object) into a RDF N-triple format using the python module RDFlib?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是很复杂。首先,一些必要的导入:
我在这里使用
StringIO
以避免创建文件。相反,我将只列出一些内容和一个包含这些内容的类似文件的对象:然后创建一个图表并将所有三元组加载到其中:
现在您在内存中拥有整个图表(当然假设您有足够的内存)。您现在可以打印它:
It's not very complicated. First, some necessary imports:
I'm using
StringIO
here to avoid creating a file. Instead, I'll just list some contents and a file-like object with these contents:Then create a graph and load all triples to it:
Now you have the whole graph in memory (assuming you have enough memory, of course). You can now print it: