Exemple #1
0
def combine_entries(aaa, cor2res_gno):
    """
    list of (Correlative, is pro, is plur, out of) -> (Selectors, Selectors)
    """
    # They are all the same Correlative except for "some" (INDEF + EXIST).
    cor_pro2ns_ofs = defaultdict(list)
    for correlative, is_pro, is_plur, of in aaa:
        if is_plur:
            nn = [N5.ZERO, N5.DUAL, N5.FEW, N5.MANY]
        else:
            nn = [N5.SING]
        nn = filter(lambda n: n <= of, nn)
        for n in nn:
            cor_pro2ns_ofs[(correlative, is_pro)].append((n, of))

    # For each grouping,
    dets = []
    pros = []
    for correlative, is_pro in sorted(cor_pro2ns_ofs):
        ns_ofs = cor_pro2ns_ofs[(correlative, is_pro)]

        # Collect the variety of how many/out of there are for this word.
        ns, ofs = map(set, zip(*ns_ofs))

        # Require that each out-of range is contiguous.  This is also because it
        # happens to be true and it allows Selectors to contain ranges instead
        # of the insanity of individual N5s.
        ofs = sorted(ofs)
        assert ofs == range(ofs[0], ofs[-1] + 1)

        for n_min, n_max in split_into_ranges(sorted(ns)):
            # Get the possible range of how many they were selected from.
            of_n_min = min(ofs)
            of_n_max = max(ofs)

            # Create a Selector that covers all of those tuples.
            r = Selector(correlative, n_min, n_max, of_n_min, of_n_max)
            count_restriction, _ = cor2res_gno[correlative]
            r = r.fitted_to_count_restriction(count_restriction)
            if not r:
                continue

            if is_pro:
                pros.append(r)
            else:
                dets.append(r)

    return dets, pros