如何为我的 RDFLib 图中的所有资源设置 rdfs:isDefinedBy?

How do I set the rdfs:isDefinedBy for all resources in my RDFLib graph?

我想为我通过解析文件生成的 RDFLib 图中的所有资源修改 属性。然后我想将修改后的图形保存到一个新文件中。

有没有简单的方法来做到这一点?

我在 Python

中使用 RDFLib

谢谢!

丹尼尔

from rdflib import Graph

# create an rdflib graph
g = Graph()

# fill the graph from your file
g.parse('your_rdf_file.ttl', format="turtle")

# you can then modify the contents of the graph either by accessing the graph 
# object directly (see https://rdflib.readthedocs.io/en/latest/intro_to_graphs.html) 
# or by using SPARQL `UPDATE` queries (see
# https://rdflib.readthedocs.io/en/latest/intro_to_sparql.html 
# but there's not really enough documentation on `UPDATE`!)

# e.g 
g.update("SOME SPARQL UPDATE QUERY")

# serialize the graph to a new file
g.serialize(destination="new_file.ttl", format="turtle")