def difference()

in distill/segmentation/segment.py [0:0]


def difference(segment_name, segment1, segment2):
    """
    Creates a new segment based on the logical difference of segment2 from segment1.

    :param segment_name: Name associated with the new segment
    :param segment1: Segment from which to subtract segment2's matched UIDs.
    :param segment2: Segment whose matched UIDs are to be subtracted from segment1.

    :return: A new segment with the given segment_name, start and end values based on segment1, and a list of the
    difference of the uids of segment1 and segment2.
    """

    # Find matching UIDs
    matched_uids = []
    for uid in segment2.uids:
        if uid in segment1.uids:
            matched_uids.append(uid)

    # Subtract matched UIDs from segment1
    uids = copy.deepcopy(segment1.uids)
    for uid in matched_uids:
        uids.remove(uid)

    # Return new segment
    segment = Segment(segment_name, segment1.start_end_val, len(uids), uids)
    segment.segment_type = Segment_Type.DIFFERENCE
    segment.generate_field_name = None
    segment.generate_matched_values = None
    return segment