Ejemplo n.º 1
0
async def load_score(title):
    import asyncio
    from rank.util import purge
    from rank.collect.movie import get_comments
    loop = asyncio.get_event_loop()
    data = get_comments(title.strip())
    lines = ["| {0}".format(purge(comment)) for comment in data]

    logger.debug("Got comments")
    create = asyncio.create_subprocess_exec("vw", "-c", "-k", "-t", "-i", "data/raw.vw", "-p", "/dev/stdout", "--quiet",
                                            stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)

    logger.debug("Creating classifier")
    proc = await create
    proc.stdin.write("\n".join(lines).encode("UTF-8"))
    await proc.stdin.drain()
    proc.stdin.close()
    result = await proc.stdout.read()
    await proc.wait()

    from score import score, parse_num

    logger.debug("Calculating score")
    ratings = [parse_num(line) for line in result.decode("UTF-8").split("\n")]
    for r, c in zip(ratings, data):
        logger.debug("Rating: {0}, Comment: {1}".format(r, c))
    mean = score(ratings[:-1], base=10)
    return True, str(mean)
Ejemplo n.º 2
0
def main(_in, _out):
    title = _in.read()
    from rank.collect.movie import get_comments
    for comment in get_comments(title.strip()):
        _out.write("| {0}\n".format(purge(comment)))
Ejemplo n.º 3
0
def main(_in, _out):
    title = _in.read()
    from rank.collect.movie import get_comments
    for comment in get_comments(title.strip()):
        _out.write("| {0}\n".format(purge(comment)))