from opyenxes.extension.XExtension import XExtension
from urllib.parse import urlparse
from opyenxes.info.XGlobalAttributeNameMap import XGlobalAttributeNameMap
from opyenxes.factory.XFactoryRegistry import XFactoryRegistry
from opyenxes.utils.SingletonClassGenerator import XSemanticExtensionMetaclass
[docs]class XSemanticExtension(XExtension, metaclass=XSemanticExtensionMetaclass):
"""This extension adds semantic attributes to event log objects.
These semantic attributes reference concepts, which are represented by event
log objects, as unique URIs.
Uses the singleton metaclass
"""
def __init__(self):
super().__init__("Semantic", "semantic", urlparse("http://www.xes-standard.org/semantic.xesext"))
factory = XFactoryRegistry().current_default()
self.ATTR_MODELREFERENCE = factory.create_attribute_literal("semantic:modelReference", "UNKNOWN", self)
self.get_event_attributes().add(self.ATTR_MODELREFERENCE.clone())
self.get_trace_attributes().add(self.ATTR_MODELREFERENCE.clone())
self.get_log_attributes().add(self.ATTR_MODELREFERENCE.clone())
self.get_meta_attributes().add(self.ATTR_MODELREFERENCE.clone())
XGlobalAttributeNameMap().register_mapping("EN", "semantic:modelReference", "Ontology Model Reference")
XGlobalAttributeNameMap().register_mapping("DE", "semantic:modelReference", "Ontologie-Modellreferenz")
XGlobalAttributeNameMap().register_mapping("FR", "semantic:modelReference", "Référence au Modèle Ontologique")
XGlobalAttributeNameMap().register_mapping("ES", "semantic:modelReference", "Referencia de Modelo Ontológico")
XGlobalAttributeNameMap().register_mapping("PT", "semantic:modelReference", "Referência de Modelo Ontológico")
[docs] def assign_model_references(self, target, model_reference):
"""Assigns to a log element (i.e., archive, log, trace, event, or
attribute) a list of model references.
:param target: Any log element (i.e., archive, log, trace, event, or
attribute) to be assigned references to.
:type target: `XAttributable`
:param model_reference: The list of model references, as a list of
strings, referred to by this element.
:type model_reference: list[str]
"""
sb = []
for ref in model_reference:
sb.append(ref)
sb.append(" ")
aux = "".join(sb)
if len(aux.lower()) > 0:
attr = self.ATTR_MODELREFERENCE.clone()
attr.set_value(aux)
target.get_attributes()["semantic:modelReference"] = attr
[docs] def assign_model_reference_uris(self, target, model_reference):
"""Assigns to a log element (i.e., archive, log, trace, event, or
attribute) a list of model references.
:param target: Any log element (i.e., archive, log, trace, event,
or attribute) to be assigned references to.
:type target: `XAttributable`
:param model_reference: The list of model references, as a list of URIs,
referred to by this element.
:type model_reference: list[ParseResult or SplitResult]
"""
sb = []
for ref in model_reference:
sb.append(ref.geturl())
sb.append(" ")
aux = "".join(sb)
if len(aux.lower()) > 0:
attr = self.ATTR_MODELREFERENCE.clone()
attr.set_value(aux)
target.get_attributes()["semantic:modelReference"] = attr