Commit 7faa4fab authored by Fabien Amarger's avatar Fabien Amarger
Browse files

fix(entities): Use a OWL2YAMSRDFAdapter class and fix CW namespace to use base_url

parent 5986c56080b2
Pipeline #95846 passed with stages
in 2 minutes and 4 seconds
......@@ -8,5 +8,7 @@
from cubicweb.entities.adapters import EntityRDFAdapter
from cubicweb.predicates import is_instance
from cubicweb.rdf import NAMESPACES
from rdflib import URIRef
from rdflib import URIRef, namespace
from rdflib.namespace import Namespace
......@@ -12,15 +14,3 @@
def owl2yams_triples(self):
OWL = self._use_namespace("owl")
CW = self._use_namespace("cubicweb")
RDFS = self._use_namespace("rdfs")
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
yield(CW["{{fragment}}"], RDFS.subClassOf, URIRef("{{uri}}"))
{% endfor %}
{% for fragment, uri in relationtype_fragment_to_uri.items() %}
yield(CW["{{fragment}}"], RDFS.subPropertyOf, URIRef("{{uri}}"))
{% endfor %}
yield(CW["label"], RDFS.subPropertyOf, RDFS.label)
if self.entity.equivalent_uri:
yield (self.uri, OWL.sameAs, URIRef(self.entity.equivalent_uri[0].uri))
......@@ -26,6 +16,4 @@
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
class {{fragment}}RDFAdapter(EntityRDFAdapter):
__select__ = is_instance("{{fragment}}")
class OWL2YAMSRDFAdapter(EntityRDFAdapter):
__regid__ = "rdf"
......@@ -30,4 +18,6 @@
__regid__ = "rdf"
class {{fragment}}(AnyEntity):
def __init__(self, _cw, **kwargs):
super().__init__(_cw, **kwargs)
NAMESPACES["cubicweb"] = Namespace(self._cw.cnx.base_url())
......@@ -33,8 +23,17 @@
def dc_title(self):
if self.label:
return self.label
return super().dc_title()
def owl2yams_triples(self):
OWL = self._use_namespace("owl")
CW = self._use_namespace("cubicweb")
RDFS = self._use_namespace("rdfs")
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
yield(CW["{{fragment}}"], RDFS.subClassOf, URIRef("{{uri}}"))
{% endfor %}
{% for fragment, uri in relationtype_fragment_to_uri.items() %}
yield(CW["{{fragment}}"], RDFS.subPropertyOf, URIRef("{{uri}}"))
{% endfor %}
yield(CW["label"], RDFS.subPropertyOf, RDFS.label)
if self.entity.equivalent_uri:
yield (self.uri, OWL.sameAs, URIRef(self.entity.equivalent_uri[0].uri))
def filter_rdf_type(self, triples):
RDF = self._use_namespace("rdf")
......@@ -45,4 +44,9 @@
else:
yield triple
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
class {{fragment}}RDFAdapter(OWL2YAMSRDFAdapter):
__select__ = is_instance("{{fragment}}")
def triples(self):
......@@ -48,3 +52,3 @@
def triples(self):
yield from owl2yams_triples(self)
yield from self.owl2yams_triples()
yield from self.filter_rdf_type(super().triples())
......@@ -50,4 +54,12 @@
yield from self.filter_rdf_type(super().triples())
class {{fragment}}(AnyEntity):
def dc_title(self):
if self.label:
return self.label
return super().dc_title()
{% endfor %}
......@@ -51,8 +63,8 @@
{% endfor %}
class CWETypeOWL2YAMSRDFAdapter(EntityRDFAdapter):
class CWETypeOWL2YAMSRDFAdapter(OWL2YAMSRDFAdapter):
__select__ = is_instance("CWEType")
__regid__ = "rdf"
def triples(self):
......@@ -55,8 +67,8 @@
__select__ = is_instance("CWEType")
__regid__ = "rdf"
def triples(self):
yield from owl2yams_triples(self)
yield from self.owl2yams_triples()
yield from super().triples()
......@@ -60,8 +72,8 @@
yield from super().triples()
class CWRTypeOWL2YAMSRDFAdapter(EntityRDFAdapter):
class CWRTypeOWL2YAMSRDFAdapter(OWL2YAMSRDFAdapter):
__select__ = is_instance("CWRType")
__regid__ = "rdf"
def triples(self):
......@@ -64,8 +76,8 @@
__select__ = is_instance("CWRType")
__regid__ = "rdf"
def triples(self):
yield from owl2yams_triples(self)
yield from self.owl2yams_triples()
yield from super().triples()
......
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