I am trying to add triples to a Graph using python's rdflib package. The relations are provided as a list (a particular column in a dataframe)
sampleRelations = ['similarTo', 'brotherOf', 'capitalOf']
g = Graph()
# general relations
gen = Namespace('http://abcd.com/general#')
g.bind('gen',gen)
# Adding predefined relationships
g.add( (gen.relatedTo, RDFS.subClassOf, OWL.ObjectProperty) )
This works as usual. But, when iterating through a list:
for rel in sampleRelations:
g.add( ('gen.'+rel, RDFS.subClassOf, OWL.ObjectProperty) )
It throws an error : "Subject %s must be an rdflib term" % (s,).
relWithNamespace = gen+rel
print(relWithNamespace)
g.add( (relWithNamespace, RDFS.subClassOf, OWL.ObjectProperty) )
Error
AssertionError: Subject http://abcd.com/general#similarTo must be an rdflib term
I understand the problem. I'm looking for pointers which can circumvent this.