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

feat(labels): Add the possibility to define several labels

parent 62ed723bcbd6
Pipeline #96235 passed with stages
in 1 minute and 28 seconds
......@@ -64,6 +64,7 @@
temp_relations = {}
for instance_uri, _, class_uri in g.triples((None, RDF.type, None)):
temp_labels = []
# Get entity type from equivalent_uri
try:
......@@ -87,6 +88,7 @@
external_uri = cnx.create_entity("ExternalUri", uri=instance_uri)
temp_attributes = {"equivalent_uri": external_uri}
for predicate_uri, object_value in g.predicate_objects(instance_uri):
relation_type = None
try:
relation_type = self.get_entity_from_uri(
cnx, predicate_uri, "CWRType"
......@@ -96,8 +98,11 @@
predicate_uri.toPython()
== "http://www.w3.org/2000/01/rdf-schema#label"
):
relation_type = cnx.find("CWRType", name="label").one()
label_entity = cnx.create_entity(
"Label", value=object_value.toPython()
)
temp_labels.append(label_entity)
else:
continue
except MultipleResultsError:
continue
......@@ -100,7 +105,9 @@
else:
continue
except MultipleResultsError:
continue
if relation_type is None:
continue
if relation_type.final:
temp_attributes[relation_type.name] = object_value.toPython()
else:
......@@ -109,7 +116,8 @@
temp_relations[instance_uri].append(
(relation_type, object_value)
)
cnx.create_entity(entity_type.name, **temp_attributes)
entity = cnx.create_entity(entity_type.name, **temp_attributes)
entity.cw_set(label=tuple(temp_labels))
for (instance_uri, relations) in temp_relations.items():
try:
......
......@@ -8,7 +8,7 @@
from cubicweb.entities.adapters import EntityRDFAdapter
from cubicweb.predicates import is_instance
from cubicweb.rdf import NAMESPACES
from rdflib import URIRef, namespace
from rdflib import URIRef, namespace, Literal
from rdflib.namespace import Namespace
......@@ -31,7 +31,9 @@
{% 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.label:
for label in self.entity.label:
yield(self.uri, RDFS.label, Literal(label.value))
yield(CW["equivalent_uri"], RDFS.subPropertyOf, OWL.sameAs)
if self.entity.equivalent_uri:
yield (self.uri, OWL.sameAs, URIRef(self.entity.equivalent_uri[0].uri))
......@@ -42,7 +44,7 @@
for triple in triples:
if triple == (self.uri, RDF.type, CW[self.entity.e_schema.type]):
yield (self.uri, RDF.type, URIRef(self.entity.is_instance_of[0].cwuri))
elif triple[1] != CW["cw_source"]:
elif triple[1] not in [CW["cw_source"], CW["label"], CW["equivalent_uri"]]:
yield triple
......@@ -58,7 +60,7 @@
def dc_title(self):
if self.label:
return self.label
return self.label[0].value
return super().dc_title()
{% endfor %}
......
......@@ -10,6 +10,9 @@
class label(RelationDefinition): # type: ignore
subject = "*"
object = "String"
cardinality = "?1"
final = True
object = "Label"
cardinality = "*?"
class Label(EntityType): # type: ignore
value = String(required=True) # type: ignore
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