For some reason, I cannot insert triples into a named graph that are formatted as Python strings... if the named graph contains more than 1 triple. I can insert triples into a named graph via Python strings, however, if the named graph is empty to begin with.
Not sure if I'm doing some sort of Python related thing wrong or if it's a Pystardog thing.
I can insert triples using this method if I'm creating a new named graph... if the named graph already exists, though, it will not insert any additional triples. At the moment, I can insert triples into a named graph only if I create insert a TTL file directly.
After trying to debug this more... I have some corrections.
(1) For some reason now, inserting a single triple as a Python string works through Pystardog.
(2) Furthermore, inserting a single triple a raw file now does not work (the code above) through Pystardog.
This is how our code works currently:
def insert_stardog(triple: str, graph_iri: str):
with stardog.Connection(DB_NAME, **SD_CONN_DETAILS) as conn:
conn.begin()
if file_raw == 'file':
conn.add(stardog.content.File(triple), graph_uri=graph_iri)
else:
conn.add(stardog.content.Raw(triple, "text/turtle"), graph_uri=graph_iri)
conn.commit()
I've tried creating the sample triple ('<{iri}> <urn:ontology:lastUpdated> "{last_updated}"^^xsd:dateTime') and inserting it into Stardog via Pystardog. The conn.add with the Python string now works fine... but the file will not add to the named graph no matter what I do. If I try to add it through Studio to the named graph, it works.
I'm really not sure if this a Pystardog thing or if I need to blow away my Stardog DB and build it again from scratch.
content.File is for inserting a file using the file name. If you try to load a file it should look something like this: conn.add(stardog.content.File('filename.ttl', 'text/turtle'). The content-type is optional. It will use 'text/turtle' if the file extension is ttl. Is it possible that you have passed a string with the file contents instead? If you do that, content.Raw should be used instead of content.File. Link to documentation for File and Raw
That's the thing... I don't get any error message back nor cause a StardogException.
I am surprised that the triple will insert without a period at the end.
Sorry, that's a copy/paste error on my part -- I did try to insert this with a period at the end.
content.File is for inserting a file using the file name. If you try to load a file it should look something like this: conn.add(stardog.content.File('filename.ttl', 'text/turtle') . The content-type is optional. It will use 'text/turtle' if the file extension is ttl . Is it possible that you have passed a string with the file contents instead? If you do that, content.Raw should be used instead of content.File .
Right, that's exactly I tried -- in the case that I was trying to add a Turtle file, my "triple" parameter would be a filename.