Search code examples
rdfowltriplestore

Create OWL-File based on data from triple store


I have basically a triple store in a mongoDB: It is a huge collection of data where every row contains an entry for "subject", "property" and "object". The collection was created by parsing an OWL-file.

After users have modified this database, I want to write a modified OWL-file based on this triple store.

Any suggestions?

Edit:

To get an Idea of the data I am talking about, here is an entry:

"_id" : ObjectId("60f54396c15008676831ad9c"),
"s" : "http://knowrob.org/kb/knowrob.owl#actor",
"p" : "http://www.w3.org/2000/01/rdf-schema#subPropertyOf",
"o" : "http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#hasParticipant"

I want to create an OWL-file out of this in order to feed it to an OWL-reasoner like HermiT.


Solution

  • One way to do this is with Python's RDFLib. The idea is to pull each record out of the relational database, insert it into rdflib's in memory graph store, and then export the rdflib store to disk which you can then use with HermiT.

    import rdflib
    
    graph = rdflib.Graph()
    
    For each database entry:
       graph.add((s, p, o))
    
    g.serialize(destination='graph.ttl', format='turtle')