def query_line(line, models, use_duration, window):
    ret = addict.Dict()
    ret.term, paths = history.build(line)

    if ret.term and paths:
        assert len(paths) == 1

        ret.path = paths[0]
        ret.result = query(ret.term, ret.path, models,
                           decision=False,
                           use_duration=use_duration,
                           window=window)
        return ret

    return {}
Beispiel #2
0
def main():
    args = docopt(__doc__)

    for line in sys.stdin:
        term, histories = history.build(line)

        if term and histories:
            assert len(histories) == 1

            if args['train']:
                mergers = int(args['-m'])
                reducers = int(args['-r'])

                key = term
                n = int(ceil(pow(reducers, 1.0 / mergers)))
                for i in xrange(mergers):
                    key += '-%d' % randint(0, n)

                forward(key, stream.encode(histories))
            elif args['classify']:
                fields = history.extract_fields(line)

                forward(fields.mid_terminal, fields.uid, fields.bid, fields.aid,
                        stream.encode(histories))