Problem adding triples in rdflib.store.IOMemory
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开发者_如何学Python):
File "C:\Python27\internetcode.py", line 114, in <module>
store.add((abc, FOAF['knows'],def))
TypeError: add() takes at least 3 arguments (2 given)
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.
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.
精彩评论