コード例 #1
0
    def _is_match_with_relationships(*, db_entity, ingested_entity):
        ing_entity_id = generate_id_from_obj(ingested_entity)
        db_entity_id = db_entity.get_id()
        matcher = getattr(county_matching_utils, "is_{}_match".format(name))
        obj_match = matcher(db_entity=db_entity,
                            ingested_entity=ingested_entity)
        # The relationships "match" if new relationships have been added
        # since the last scrape, but not if relationships have been removed.
        parents_of_db_entity = db_relationship_map[db_entity_id]
        parents_of_ing_entity = ing_relationship_map[ing_entity_id]
        relationship_match = parents_of_db_entity.issubset(
            parents_of_ing_entity)

        return obj_match and relationship_match
コード例 #2
0
def _build_maps_from_charges(
        charges: List[entities.Charge], child_obj_name: str
) -> Tuple[Dict[str, Entity], Dict[str, Set[Entity]]]:
    """Helper function that returns a pair of maps describing the relationships
    between charges and their children. The |object_map| maps ids, which may be
    temporary generated ids, to the objects they refer to. The
    |object_relationships| map maps those ids to the set of charges that the
    object is a child of. This is part of determining entity equality,
    e.g. two bonds are equal only if the same set of charges has the bond as its
    child."""
    object_map = {}
    object_relationships: Dict[str, set] = defaultdict(set)

    for charge in charges:
        child_obj = getattr(charge, child_obj_name)
        if child_obj:
            child_obj_id = child_obj.get_id()
            if not child_obj_id:
                child_obj_id = generate_id_from_obj(child_obj)
            object_map[child_obj_id] = child_obj
            object_relationships[child_obj_id].add(charge.charge_id)
    return object_map, object_relationships