How to fetch ontologies of a given DB using pystardog

Hi community, I need to fetch all the content of the ontologies (models) that are under use in a given DB, and if possible in a given virtual graph using pystardog. It can be by calling a SPARQL query as well.
I would appreciate any hints or links or some excerpt of code for that tasks.

Thanks in advance.

The best way to organize your database is to place ontologies in their own named graphs. By using named graphs, you can have multiple versions of ontologies, or different combinations that you may want to use in different use cases.

For use with the reasoner, you would use the reasoning.schema feature, and then pass in the name of the schema when you create the connection.

If you want to query the ontology as data, then using named graph aliases allows you to group different graphs together for query.

I like to think about this as two lens over the database, one controlling what we see for reasoning, and one for what we see with data. Correspondingly, different datasets should also find their way to their own named graphs.

Finally, to simplify using the named graph alias in pystardog, we recently added this feature, see this PR:

1 Like