Как мне установить rdfs: isDefinedBy для всех ресурсов в моем графе RDFLib? - PullRequest
1 голос
/ 17 апреля 2020

Я хотел бы изменить свойство для всех ресурсов в моем графе RDFLib, сгенерированном мной при разборе файла. Затем я хочу сохранить измененный график в новый файл.

Есть ли простой способ сделать это?

Я использую RDFLib в Python

Спасибо!

Даниил

1 Ответ

1 голос
/ 18 апреля 2020
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")
...