def decide_xref(xref, judgement, authz): """Store user feedback from an Xref result as an profile-type EntitySet The problem here is that we're trying to translate a single pair-wise user judgement into a merge or split judgement regarding a cluster of entities. This works for most cases, with the exception that a profile, once established, cannot be split in a way that preserves what entities were linked to what other entities originally.""" if not isinstance(judgement, Judgement): judgement = Judgement(judgement) entity_id = xref.get("entity_id") collection = Collection.by_id(xref.get("collection_id")) entity_profile = EntitySet.by_entity_id( entity_id, judgements=[Judgement.POSITIVE], collection_ids=[collection.id], types=[EntitySet.PROFILE], ).first() match_id = xref.get("match_id") match_collection_id = xref.get("match_collection_id") match_profile = EntitySet.by_entity_id( match_id, judgements=[Judgement.POSITIVE], collection_ids=[collection.id], types=[EntitySet.PROFILE], ).first() # If we are undecided, and we stay undecided, not much to change. if entity_profile is None or match_profile is None: if judgement == Judgement.NO_JUDGEMENT: return if entity_profile is None: entity_profile = create_profile(collection, authz) profile_add_entities(entity_profile, entity_id, collection.id, None, Judgement.POSITIVE, authz) if judgement is Judgement.POSITIVE and match_profile is not None: # Case 1: both entities have profiles and the match is positive entity_profile = entity_profile.merge(match_profile, authz.id) else: # Case 2: any other judgement # NOTE: Another case of NEGATIVE judgements triggering a # `split_profile` could be useful, however it isn't implemented # here so that we don't lose judgements. This however should be # strongly considered in order to reverse profile mergers. The question # is: what to do with old judgements on a pair when we do this? profile_add_entities(entity_profile, match_id, match_collection_id, entity_id, judgement, authz) db.session.commit() return entity_profile
def get_entitysets_by_entity(entity_id, collection_ids=None, judgements=None, types=None, labels=None): if judgements is not None: judgements = list(map(Judgement, judgements)) entitysets = EntitySet.by_entity_id( entity_id, collection_ids=collection_ids, judgements=judgements, types=types, labels=labels, ) return entitysets
def decide_pairwise(collection, entity, match_collection, match, judgement, authz): """Store user feedback from an pairwise judgement as an profile-type EntitySet The problem here is that we're trying to translate a single pair-wise user judgement into a merge or split judgement regarding a cluster of entities. This works for most cases, with the exception that a profile, once established, cannot be split in a way that preserves what entities were linked to what other entities originally.""" if not isinstance(judgement, Judgement): judgement = Judgement(judgement) # This will raise a InvalidData error if the two types are not compatible model.common_schema(entity.get("schema"), match.get("schema")) profile = EntitySet.by_entity_id( entity.get("id"), collection_ids=[collection.id], types=[EntitySet.PROFILE], judgements=[Judgement.POSITIVE], ).first() if profile is None: data = {"type": EntitySet.PROFILE, "label": "profile"} profile = EntitySet.create(data, collection, authz) item = save_entityset_item( profile, collection, entity.get("id"), judgement=Judgement.POSITIVE, added_by_id=authz.id, ) item = save_entityset_item( profile, match_collection, match.get("id"), judgement=judgement, compared_to_entity_id=entity.get("id"), added_by_id=authz.id, ) db.session.commit() if item is not None: return item.entityset