Exemplo n.º 1
0
def main(args, _in, _out):
    parts = args.matcher_fn.split(".")
    module = __import__(".".join(parts[:-1]), fromlist=[""])
    matcher = getattr(module, parts[-1])
    with open(args.f, "r") as f:
        _dict = list(load_dict(f))

    raw = list(load_raw(_in))
    from rank.util.feature import vw_model

    bow = list(compute_bow(raw, _dict, matcher, args.max_dist, args.multi))
    _out.write("{0}".format(vw_model(bow_string(bow), args.label)))
Exemplo n.º 2
0
def main(args, _in, _out):
    parts = args.matcher_fn.split(".")
    module = __import__(".".join(parts[:-1]), fromlist=[""])
    matcher = getattr(module, parts[-1])
    with open(args.f, "r") as f:
        _dict = list(load_dict(f))

    raw = list(load_raw(_in))
    from rank.util.feature import vw_model

    bow = list(compute_bow(raw, _dict, matcher, args.max_dist, args.multi))
    _out.write("{0}".format(vw_model(bow_string(bow), args.label)))
Exemplo n.º 3
0
def main(args, _in, _out):
    import pandas as pd
    from rank.util.feature import parse_bow, vw_model
    with open(args.m, "r") as f:
        mask = list(map(lambda x: x.strip(), f.read().split("\n")))

    data = [parse_bow(line)
            for line in map(lambda x: x.strip(), _in.read().split("\n"))
            if len(line) > 0
            ]

    df = pd.DataFrame(data)
    filtered = df[mask]
    for label, line in zip(df["label"], filtered.values):
        _out.write("{0}\n".format(vw_model(" ".join(
            map(lambda x: "{0}:{1}".format(*x), zip(filtered.columns, line))), label)
        ))
Exemplo n.º 4
0
def main(args, _in, _out):
    import pandas as pd
    from rank.util.feature import parse_bow, vw_model
    with open(args.m, "r") as f:
        mask = list(map(lambda x: x.strip(), f.read().split("\n")))

    data = [
        parse_bow(line) for line in map(lambda x: x.strip(),
                                        _in.read().split("\n"))
        if len(line) > 0
    ]

    df = pd.DataFrame(data)
    filtered = df[mask]
    for label, line in zip(df["label"], filtered.values):
        _out.write("{0}\n".format(
            vw_model(
                " ".join(
                    map(lambda x: "{0}:{1}".format(*x),
                        zip(filtered.columns, line))), label)))