morph-kgc / morph-kgc

Powerful RDF Knowledge Graph Generation with RML Mappings
https://morph-kgc.readthedocs.io
Apache License 2.0
191 stars 35 forks source link

Use of global variables in user defined functions (udf) #271

Closed fanavarro closed 4 months ago

fanavarro commented 4 months ago

I have a user defined function that extract information from ontologies. The input parameter is the ontology path, so the function needs to load it as a graph by using rdflib. As the ontology parsing could be a heavy operation, I would like to keep a dictionary acting as a cache, where the key is the ontology path and the value is the rdflib graph, so that each ontology I use is read only once. I have defined the dictionary as a global variable outside the function, and I check and update it inside the function. However, I see the logs while the mapping process is being performed, and it seems that my dictionary is always empty, and every time the function is called, the ontology is loaded. I suspect this is related with how the udf function is being executed inside the yarrrml engine.

Could you provide some hints to achieve this? Basically, the problem is to use a global variable from a udf function.

Thanks beforehand, and kind regards.

arenas-guerrero-julian commented 4 months ago

Hi @fanavarro ,

It is not possible to achieve this in the current version. A possible alternative (maybe not suitable for your use case) could be to load the ontologies to an SPARQL endpoint once and then accessing the endpoint with Morph-KGC. To do this an SPARQL connector must be implemnted, but this is simple.

fanavarro commented 4 months ago

Hi @arenas-guerrero-julian, thanks for your quick answer!

Ok, I will give a try by using an sparql endpoint. I am closing the issue, thanks so much!