# Path: tde/util/functions.py
# def iterator_length(iterable):
# def unique(iterable):
# def unique_by(iterable, key):
# def intersection(iterable1, iterable2):
# def intersection_by(iterable1, iterable2, key):
# def grouper(n, iterable, padvalue=None):
# def fname2speaker(corpus_type):
# def fscore(p, r):


from pprint import pformat
from itertools import izip, repeat, combinations, ifilterfalse
from tde.util.functions import unique, flatten
import collections
        within : bool
            Only select pairs from the same class.
        order : bool
            Also include reverse of a pair.

        Returns
        -------
        Iterator over (FragmentToken, FragmentToken) pairs.

        """
        vals = self.clsdict.itervalues()
        if within:
            if order:
                pairs = flatten(((f1, f2), (f2, f1))
                                for fragments in vals
                                for f1, f2 in combinations(fragments, 2))
            else:
                pairs = (tuple(sorted((f1, f2),
                                      key=lambda f: (f.name, f.interval.start)))
                         for fragments in vals
                         for f1, f2 in combinations(fragments, 2))
        else: # across classes
            if order:
                pairs = (((f1, f2), (f2, f1))
                         for f1, f2 in combinations(flatten(vals), 2))
                pairs = flatten(pairs)
            else:
                pairs = (tuple(sorted((f1, f2),
                                      key=lambda f: (f.name, f.interval.start)))
                         for f1, f2 in combinations(flatten(vals), 2))

# Path: tde/util/functions.py
# def iterator_length(iterable):
# def unique(iterable):
# def unique_by(iterable, key):
# def intersection(iterable1, iterable2):
# def intersection_by(iterable1, iterable2, key):
# def grouper(n, iterable, padvalue=None):
# def fname2speaker(corpus_type):
# def fscore(p, r):


# Path: tde/data/classes.py
from pprint import pformat
from itertools import izip, repeat, combinations, ifilterfalse
from tde.util.functions import unique, flatten
import collections

        within : bool
            Only select pairs from the same class.
        order : bool
            Also include reverse of a pair.

        Returns
        -------
        Iterator over (FragmentToken, FragmentToken) pairs.

        """
        vals = self.clsdict.itervalues()
        if within:
            if order:
                pairs = flatten(((f1, f2), (f2, f1))
                                for fragments in vals
                                for f1, f2 in combinations(fragments, 2))
            else:
                pairs = (tuple(sorted((f1, f2),
                                      key=lambda f: (f.name, f.interval.start)))
                         for fragments in vals
                         for f1, f2 in combinations(fragments, 2))
        else: # across classes
            if order:
                pairs = (((f1, f2), (f2, f1))
                         for f1, f2 in combinations(flatten(vals), 2))
                pairs = flatten(pairs)
            else:
                pairs = (tuple(sorted((f1, f2),
                                      key=lambda f: (f.name, f.interval.start)))
                         for f1, f2 in combinations(flatten(vals), 2))

        return unique(ifilterfalse(lambda f: f[0].interval.overlaps_with(f[1].interval),