<commit_before>from zohmg.config import Config

class Mapper(object):
    def __init__(self, usermapper):
        self.usermapper = usermapper
        self.projections = Config().projections()

    # wrapper around the user's mapper.
    def __call__(self, key, value):
        # from the usermapper: a timestamp, a point in n-space, units and their values.
        for (ts, point, units) in self.usermapper(key, value):
            for p in self.projections:
                # perform dimensionality reduction,
                reduced = {}
                for d in p:
                    reduced[d] = point[d]
                # yield for each requested projection.
                # include the projections list to get the order right.
                for u in units:
                    value = units[u]
                    yield (ts, p, reduced, u), value<commit_msg>mapper yields 'all' records.<commit_after>from zohmg.config import Config

# exploding mapper!
class Mapper(object):
    def __init__(self, usermapper):
        self.usermapper = usermapper
        self.projections = Config().projections()

    # helper for generating all permutations of a dictionary.
    def dict_permutations(self, dict_):
        dict = dict_.copy()
        # base case.
        if len(dict) == 1:
            # {'agent': 'firefox'} => [{'agent': 'firefox'}, {'agent': 'all'}]
            return [dict, {dict.keys()[0] : 'all'}]

        x  = dict.popitem()
        xs = self.dict_permutations(dict)

        permuts = []
        for a in [x, (x[0], 'all')]:
            for b in xs: # b => {'agent': "firefox", 'country': "US"}
                b[a[0]] = a[1] # add a to b.
                permuts.append(b.copy())
        return permuts

    # wrapper around the user's mapper.
    def __call__(self, key, value):
        # from the usermapper: a timestamp, a point in n-space, units and their values.
        for (ts, point, units) in self.usermapper(key, value):
            for p in self.projections:
                # dimensionality reduction,
                reduced = {}
                for d in p:
                    reduced[d] = point[d]
                # yield for each requested projection.
                # include the projections list to get the order right.
                for u in units:
                    value = units[u]
                    for permut in self.dict_permutations(reduced):
                        # we yield len(projections) * len(units) * 2^len(reduced) times.
                        yield (ts, p, permut, u), value
{'fraction_non_alphanumeric': 0.10648330058939097, 'fraction_numerical': 0.002357563850687623, 'mean_word_length': 1.7405812701829924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3898575', 'n_tokens_mistral': 735, 'n_tokens_neox': 690, 'n_words': 234}