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 @@
entities_template = jinja2.Template(
"""
from cubicweb.entities.adapters import EntityRDFAdapter
from cubicweb.predicates import is_instance
from cubicweb.rdf import NAMESPACES
from rdflib import URIRef, OWL
......@@ -8,3 +10,14 @@
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() %}
......@@ -10,9 +23,8 @@
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
class {{fragment}}RDFAdapter(EntityRDFAdapter):
def triples(self):
yield from super().triples()
yield(URIRef("{{uri}}"), OWL.sameAs, URIRef(self.uri))
class {{fragment}}RDFAdapter(OWL2YamsGenericRDFAdapter):
__select__ = is_instance("{{fragment}}")
__regid__ = "rdf"
{% endfor %}
def registration_callback(vreg):
......@@ -15,12 +27,8 @@
{% endfor %}
def registration_callback(vreg):
vreg.register_all(
globals().values(),
__name__,
({% for fragment in entitytype_fragment_to_uri %} {{fragment}}RDFAdapter, {% endfor %})
)
vreg.register_all(globals().values(), __name__, ())
"""
)
......@@ -32,5 +40,6 @@
relationtype_fragment_to_uri: Dict[str, str],
) -> str:
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,
)
Supports Markdown
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