Commit fc12c44b authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat(entities): Export mappings between entity types and owl class and relations/properties

parent 7deb0470af2d
...@@ -5,5 +5,7 @@ ...@@ -5,5 +5,7 @@
entities_template = jinja2.Template( entities_template = jinja2.Template(
""" """
from cubicweb.entities.adapters import EntityRDFAdapter from cubicweb.entities.adapters import EntityRDFAdapter
from cubicweb.predicates import is_instance
from cubicweb.rdf import NAMESPACES
from rdflib import URIRef, OWL from rdflib import URIRef, OWL
...@@ -8,3 +10,14 @@ ...@@ -8,3 +10,14 @@
from rdflib import URIRef, OWL from rdflib import URIRef, OWL
class OWL2YamsGenericRDFAdapter(EntityRDFAdapter):
def triples(self):
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
yield(NAMESPACES['cubicweb']["{{fragment}}"], OWL.equivalentClass, URIRef("{{uri}}"))
{% endfor %}
{% for fragment, uri in relationtype_fragment_to_uri.items() %}
yield(NAMESPACES['cubicweb']["{{fragment}}"], OWL.equivalentProperty, URIRef("{{uri}}"))
{% endfor %}
yield from super().triples()
{% for fragment, uri in entitytype_fragment_to_uri.items() %} {% for fragment, uri in entitytype_fragment_to_uri.items() %}
...@@ -10,9 +23,8 @@ ...@@ -10,9 +23,8 @@
{% for fragment, uri in entitytype_fragment_to_uri.items() %} {% for fragment, uri in entitytype_fragment_to_uri.items() %}
class {{fragment}}RDFAdapter(EntityRDFAdapter): class {{fragment}}RDFAdapter(OWL2YamsGenericRDFAdapter):
def triples(self): __select__ = is_instance("{{fragment}}")
yield from super().triples() __regid__ = "rdf"
yield(URIRef("{{uri}}"), OWL.sameAs, URIRef(self.uri))
{% endfor %} {% endfor %}
def registration_callback(vreg): def registration_callback(vreg):
...@@ -15,12 +27,8 @@ ...@@ -15,12 +27,8 @@
{% endfor %} {% endfor %}
def registration_callback(vreg): def registration_callback(vreg):
vreg.register_all( vreg.register_all(globals().values(), __name__, ())
globals().values(),
__name__,
({% for fragment in entitytype_fragment_to_uri %} {{fragment}}RDFAdapter, {% endfor %})
)
""" """
) )
...@@ -32,5 +40,6 @@ ...@@ -32,5 +40,6 @@
relationtype_fragment_to_uri: Dict[str, str], relationtype_fragment_to_uri: Dict[str, str],
) -> str: ) -> str:
return entities_template.render( return entities_template.render(
entitytype_fragment_to_uri=entitytype_fragment_to_uri entitytype_fragment_to_uri=entitytype_fragment_to_uri,
relationtype_fragment_to_uri=relationtype_fragment_to_uri,
) )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment