Closed fils closed 2 years ago
We should note that our load_jsonld()
and save_jsonld()
methods will probably be deprecated, since this has been pulled directly into RDFlib
v6+ and JSON-LD support no longer requires a special plugin.
That said, our load_rdf()
and load_rdf_text()
methods can parse from either a PATH
-like object or a string, respectively.
Since the StringIO
class in Python makes text look like it's being read from a file, it may work better to drill-down to RDFlib
methods themselves.
In other words, if you had a kg
object and s
as a StringIO
object then:
g = kg.rdf_graph()
g.parse(file=s, format="json-ld")
where you're calling RDFlib.Graph.parse()
directly.
Will that work well?
@ceteri
with that info I was able to simply try
for r in results:
rkg.load_rdf_text(data=json.dumps(r), format="json-ld")
like to do with turtle and that works fine now..
So my use case is solved.
So glad to hear! Happy Holidays -
I'm submitting a
Current Behaviour:
ref: https://github.com/gleanerio/notebooks/blob/master/notebooks/validation/frame_assay.ipynb
I have several JSON-LD framing events with the results in a list. I want to iterate through the list and load this into kglab KnowledgeGraph object.
This works:
However, writing, closing, reading and overwriting is not elegant. I thought I could pass a "file like object" to the load_json function so I tried
but this errors out with
I'm rather new to python at this level, so perhaps I am doing this wrong or not following correctly. Can a StringIO or ByteIO object be used here as a "file like object" for the load_jsonld() function?
Expected Behaviour:
Would like to have it work with a python "file like" object.
Steps to reproduce:
My steps are at: https://github.com/gleanerio/notebooks/blob/master/notebooks/validation/frame_assay.ipynb
No line numbers but in In cell 41 (near bottom)
Environment: