# Path: broca/common/util.py
# def parallel(func, inputs, n_jobs, expand_args=False):
#     """
#     Convenience wrapper around joblib's parallelization.
#     """
#     if expand_args:
#         return Parallel(n_jobs=n_jobs)(delayed(func)(*args) for args in inputs)
#     else:
#         return Parallel(n_jobs=n_jobs)(delayed(func)(arg) for arg in inputs)


import json
from collections import defaultdict
from broca.common.util import parallel
from broca.knowledge.util import merge


def train_tf(tokens_stream, out=None, **kwargs):
    """
    Train a map of term frequencies on a list of files (parallelized).
    """
    print('Counting terms...')

# Path: broca/common/util.py
# def parallel(func, inputs, n_jobs, expand_args=False):
#     """
#     Convenience wrapper around joblib's parallelization.
#     """
#     if expand_args:
#         return Parallel(n_jobs=n_jobs)(delayed(func)(*args) for args in inputs)
#     else:
#         return Parallel(n_jobs=n_jobs)(delayed(func)(arg) for arg in inputs)


# Path: broca/knowledge/tf.py
import json
from collections import defaultdict
from broca.common.util import parallel
from broca.knowledge.util import merge



def train_tf(tokens_stream, out=None, **kwargs):
    """
    Train a map of term frequencies on a list of files (parallelized).
    """
    print('Counting terms...')

    results = parallel(count_tf, tokens_stream, n_jobs=-1)