在 rdflib.store.IOMemory 中添加三元组时出现问题

发布于 2024-12-04 18:29:52 字数 358 浏览 0 评论 0原文

每当我尝试使用以下代码将三元组添加到商店中时,都会出现以下错误。您能在这方面帮助我吗?提前致谢。

store = plugin.get('IOMemory',Store)()
store.add((abc, FOAF['knows'],def))

Error:

Traceback (most recent call last):
  File "C:\Python27\internetcode.py", line 114, in <module>
  store.add((abc, FOAF['knows'],def))
TypeError: add() takes at least 3 arguments (2 given)

Whenever I try to add triple into the store using following code it gives me following error. Could you please help me in this regard. Thanks in advance.

store = plugin.get('IOMemory',Store)()
store.add((abc, FOAF['knows'],def))

Error:

Traceback (most recent call last):
  File "C:\Python27\internetcode.py", line 114, in <module>
  store.add((abc, FOAF['knows'],def))
TypeError: add() takes at least 3 arguments (2 given)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-12-11 18:29:52

看来你必须传递至少 3 个参数。在 文档在该模块中,您可以看到哪些参数需要 add 方法:

(abc, FOAF['knows'],def) 是您的三元组吗?在这种情况下,您还需要两个: contextquoted

add(self, triple, context, quoted) 

我找到了更多信息 此处

添加(自我,(主语,谓语,宾语),上下文,引用=False)

将给定语句添加到特定上下文或模型中。这
引用的参数由公式感知存储解释以指示
该声明被引用/假设,不这样做应该是一个错误
指定上下文并使引用的参数为 True。也应该
当存储不是时,引用的参数为 True 时会出现错误
公式感知。

It seems you have to pass at least 3 arguments. In the documentation of that module you can see what arguments needs add method:

(abc, FOAF['knows'],def) is your triple? in that case you need two more: context and quoted

add(self, triple, context, quoted) 

I've found some more information here

add(self, (subject, predicate, object), context, quoted=False)

Adds the given statement to a specific context or to the model. The
quoted argument is interpreted by formula-aware stores to indicate
this statement is quoted/hypothetical It should be an error to not
specify a context and have the quoted argument be True. It should also
be an error for the quoted argument to be True when the store is not
formula-aware.

一江春梦 2024-12-11 18:29:52

首先,你需要知道,当 python 说一个方法需要 3 个参数时,它实际上意味着两个参数加上实例参数(通常是 self)。您当前正在传递实例 (store) 以及一个三元素元组:(abc, FOAF['knows'], def),它算作一个参数。 store.add() 需要第三个参数。这就是错误消息试图告诉您的内容。我不知道它需要什么,但文档应该能够进一步解释。

如果没有别的事,您可以尝试 store.add((abc, FOAF['knows'], def), None),看看是否会导致新的错误。

So first, you need to know that when python says that a method takes 3 arguments, it really means two argument plus the instance argument (usually self). You are currently passing the instance (store) plus a three element tuple: (abc, FOAF['knows'], def), which counts as one argument. store.add() needs a third argument. That's what the error message is trying to tell you. I don't know what it needs, but the documentation should be able to explain further.

If nothing else, you can try store.add((abc, FOAF['knows'], def), None), and see if that causes a new error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文