diff --git a/src/caoscrawler/semantic_target.py b/src/caoscrawler/semantic_target.py index 3c8112e0afe14cabc30c2f5f31bbf55015e7dd98..2396446f1f46f7b73bea71c44185d1fa5b695b1b 100644 --- a/src/caoscrawler/semantic_target.py +++ b/src/caoscrawler/semantic_target.py @@ -97,8 +97,7 @@ class SemanticTarget(): are updated according to the reference map. This model should only be manipulated via three functions: - - make_identifiable: adds an identifiable to a SemanticEntity what possibly allows to merge it - with another SemanticEntity + - make_identifiable: adds an identifiable to a SemanticEntity - merge_with_equivalent: check whether there is an equivalent SemanticEntity and merge into that if one is found - check_remote_server: uses the identifiable to check the remote server and add ID and path if @@ -143,15 +142,14 @@ class SemanticTarget(): self._mark_entities_with_path_or_id() def make_identifiable(self, se: SemanticEntity): - """ creates an identifiable for the given SemanticEntity and possibly merges it into an - equivalent SemanticEntity + """Create an identifiable for the given SemanticEntity and store it there. """ if se.identifiable is not None: raise RuntimeError("Already has identifiable") se.identifiable = self.identifiableAdapter.get_identifiable( se, self.backward_id_referenced_by[se.uuid]) - def merge_with_equivalent(self, se: SemanticEntity): + def merge_with_equivalent(self, se: SemanticEntity) -> bool: equivalent_se = self.get_checked_equivalent(se) if equivalent_se is None: return False @@ -159,14 +157,14 @@ class SemanticTarget(): self._merge_into(se, equivalent_se) return True - def check_remote_server(self, se: SemanticEntity): + def check_remote_server(self, se: SemanticEntity) -> None: identified_record = ( self.identifiableAdapter.retrieve_identified_record_for_identifiable( se.identifiable)) if identified_record is not None: se.identify_with(identified_record) - def set_missing(self, se: SemanticEntity): + def set_missing(self, se: SemanticEntity) -> None: """ add the given SemanticEntity to the list of missing entities This removes the SemanticEntity from the unchecked list and implies that the entity does @@ -208,27 +206,27 @@ class SemanticTarget(): self._identifiable_look_up): return self._identifiable_look_up[entity.identifiable.get_representation()] - def get_equivalent_existing(self, se): - """ Check whether this Record exists on the remote server + # def get_equivalent_existing(self, se): + # """ Check whether this Record exists on the remote server - Returns: The stored Record - """ - treated = self.get_any(se) - if id(treated) in self._existing: - return rec - else: - return None + # Returns: The stored Record + # """ + # treated = self.get_any(se) + # if id(treated) in self._existing: + # return rec + # else: + # return None - def get_equivalent_missing(self, se): - """ Check whether this Record is missing on the remote server + # def get_equivalent_missing(self, se): + # """ Check whether this Record is missing on the remote server - Returns: The stored Record - """ - treated = self.get_any(record, identifiable) - if id(treated) in self._missing: - return rec - else: - return None + # Returns: The stored Record + # """ + # treated = self.get_any(record, identifiable) + # if id(treated) in self._missing: + # return rec + # else: + # return None def combine_fragments(self): for se in self.se: @@ -473,13 +471,19 @@ class SemanticTarget(): if referenced in self.unchecked: if referenced in circle: closed = True - circle.append(pval) + circle.append(pval) # FIXME added_to_circle = True if not added_to_circle: return None return circle def _add_any(self, entity: SemanticEntity, lookup): + """Add ``entity`` to this SemanticTarget and store in ``lookup`` cache. + +The entity is stored in the SemanticEntity's ``id``, ``path`` and ``identifiable`` lookup tables, if +the respective attributes exist. + +""" if entity.id is not None: self._id_look_up[entity.id] = entity if entity.path is not None: @@ -489,7 +493,7 @@ class SemanticTarget(): lookup[id(entity)] = entity def _merge_into(self, source: SemanticEntity, target: SemanticEntity): - """ tries to merge record into newrecord + """ FIXME tries to merge record into newrecord If it fails, record is added to the try_to_merge_later list. In any case, references are bent to the newrecord object.