@classmethod
    def filter_by_entity_occurrence_kind_pair(cls, kind_a, kind_b):
        # This may be implemented as a Manager method, but for simplicity, will
        # be put in here as a classmethod.
        matching_segms = TextSegment.objects.filter(
            entity_occurrences__entity__kind=kind_a).distinct()
        if kind_a == kind_b:
            # BECAREFUL!!! There is a very subtle detail in here. The Django ORM,
            # after doing the first filter (before entering this if-branch) gave us
            # <TextSegments> whose "entity_occurrences" are not all of them, but only
            # those that match the criteria expressed above. Because of that, is that
            # when annotating Count of such thing, we trust is counting EOccurrences of
            # the kind we are interested in, and not the others.
            matching_segms = matching_segms.annotate(
                kind_count=models.Count('entity_occurrences__entity__kind')).filter(
                    kind_count__gte=2
                )
        else:
            matching_segms = matching_segms.filter(
                entity_occurrences__entity__kind=kind_b,
            ).distinct()
        return matching_segms
Raises a ProtocolError if the Connection header is present in a header
dataset/ETHPy150Open machinalis/iepy/iepy/data/models.py/TextSegment.filter_by_entity_occurrence_kind_pair--crossover with--dataset/ETHPy150Open python-hyper/hyper-h2/h2/utilities.py/_reject_connection_header