From 5a8b62e383afc479c5ecf7294f29b1872dbc1e89 Mon Sep 17 00:00:00 2001
From: Bugra Altug <baltug@genetec.com>
Date: Sat, 27 Jul 2024 18:09:59 +0200
Subject: [PATCH] extract equivalence correction

---
 dbrepo-somapper/matching/read_inputs.py | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/dbrepo-somapper/matching/read_inputs.py b/dbrepo-somapper/matching/read_inputs.py
index b63640c67a..8a132ae3ee 100644
--- a/dbrepo-somapper/matching/read_inputs.py
+++ b/dbrepo-somapper/matching/read_inputs.py
@@ -283,7 +283,7 @@ class OntologyParser:
     # Direct/Indirect imports need to be deleted from ontologies (or imported as seperate. see Owlready2 documentation). Protege can be used for this.
     # OWL 2.0 ontologies in NTriples, RDF/XML or OWL/XML format are supported. (OWL/XML is recommended.)
     # Relation (A is a B, B is a C, C is a A) is not supported: http://owlready.306.s1.nabble.com/TypeError-metaclass-conflict-td2889.html
-    def parse(self, _loc:str, _include_only:OntologyClassTypes=None, _use_reasoner=True, _only_local:bool=True) -> OntologyData:
+    def parse(self, _loc:str, _include_only:[OntologyClassTypes]=None, _use_reasoner=True, _only_local:bool=True) -> OntologyData:
         self._data = OntologyData()
         try:
             Loggers.info(LoggerTypes.LOAD_SERVICE, "Parsing ontology "+str(_loc))
@@ -400,13 +400,9 @@ class OntologyParser:
 
     def _fill_indirect_class_datatype(self, subject, property, value):
         if isinstance(property, or2.DataPropertyClass): # Datatype
-            if isinstance(value, or2.LogicalClassConstruct):
-                logical_values = self._extract_class_construct_information(value)
-                logical_values = [self._get_iri(v) for _, v in logical_values]
-                self._data.safe_append_class_indirectdatatypes(self._get_iri(subject), logical_values)
-            elif isinstance(value, type):
-                self._data.safe_append_class_indirectdatatypes(self._get_iri(subject), [self._get_iri(value)])
-        elif type(value)==subject: # Individuals will use their parent data types.
+            values = self._extract_range_construct_information(value)
+            self._data.safe_append_class_indirectdatatypes(self._get_iri(subject), values)
+        elif type(value)==subject: # Individuals will use their parent data types. This is done in the "get_individual_datatypes"
             self._data.safe_append_class_indirectdatatypes(self._get_iri(subject), [])
             
     def _fill_indirectly_defined_object_property_class(self, property, value):
@@ -424,11 +420,9 @@ class OntologyParser:
         Loggers.info(LoggerTypes.LOAD_SERVICE, "Extracting class construct information.")
         if isinstance(class_construct, or2.Restriction):
             Loggers.info(LoggerTypes.LOAD_SERVICE, "("+str(class_construct.value)+") Extracting restriction.")
-            if isinstance(class_construct.value, or2.Restriction):
+            if isinstance(class_construct.value, or2.Restriction): # property chain (op some (dp exactly 1 int))
                 #return [(class_construct.property, class_construct.value.property)] + self._extract_class_construct_information(class_construct.value) # Gets all chained relations
                 return self._extract_class_construct_information(class_construct.value) # Gets only chain end.
-            elif isinstance(class_construct.value, or2.ConstrainedDatatype):
-                return [(class_construct.property, class_construct.value.base_datatype)]
             else:
                 return [(class_construct.property, class_construct.value)]
         elif isinstance(class_construct, or2.LogicalClassConstruct): # Complex construction with logical operators
@@ -455,11 +449,6 @@ class OntologyParser:
             Loggers.info(LoggerTypes.LOAD_SERVICE, "("+str(class_construct.property)+") Extracting inverse.")
             # [(type(class_construct) , class_construct.property)]
             return []
-        elif isinstance(class_construct, type):
-            Loggers.info(LoggerTypes.LOAD_SERVICE, "("+str(class_construct)+") Extracting python type.")
-            return [(str(type(class_construct)), class_construct)]
-        elif hasattr(class_construct, 'value') and isinstance(class_construct.value, or2.ConstrainedDatatype):
-            return [(class_construct.property, class_construct.value.base_datatype)]
         else:
             Loggers.error(LoggerTypes.LOAD_SERVICE, "In class_construct_information unknown type:"+str(type(class_construct)))
             return []
@@ -505,7 +494,7 @@ class OntologyParser:
                 tmp += self._extract_range_construct_information(cls)
             return tmp
         else:
-            Loggers.error(LoggerTypes.LOAD_SERVICE, "In range_construct_information unknown type:"+str(type(_construct)))
+            Loggers.error(LoggerTypes.LOAD_SERVICE, "In range_construct_information unknown: \"" + str(_construct) + "\" type: \""+str(type(_construct)) + "\".")
             return []
         
     def _get_name(self, _entity:or2) -> str:
-- 
GitLab