0

I am working by using rdflib python library for .ttl file processing. I have some triples in the .ttl file but I want to append (update) the file by adding new triples to the existing .ttl file using python rdflib library. For example: file1.ttl has 10 triples (subject->predicate->object) and I want to add 5 new triples to the same file by appending the .ttl file in python rdflib.

Thanks!

Shahi Dost
  • 21
  • 4

1 Answers1

2

you just need to "add" the graph as per documentation: https://rdflib.readthedocs.io/en/4.2.2/merging.html

from rdflib import Graph

g1 = Graph()
g1.parse("file1.ttl", format="turtle")

g2 = Graph()
g2.parse("file2.ttl", format="turtle")

graph = g1 + g2

graph.serialize("file1.ttl", format="turtle")
Peb
  • 151
  • 3