lac_demo.py 781 字节
Newer Older
S
Steffy-zxf 已提交
1 2 3 4
#coding:utf-8
from __future__ import print_function

import json
Z
Zeyu Chen 已提交
5
import os
S
Steffy-zxf 已提交
6 7
import six

Z
Zeyu Chen 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20
import paddlehub as hub

if __name__ == "__main__":
    # Load LAC Module
    lac = hub.Module(name="lac")
    test_text = ["今天是个好日子", "天气预报说今天要下雨", "下一班地铁马上就要到了"]

    # Set input dict
    inputs = {"text": test_text}

    # execute predict and print the result
    results = lac.lexical_analysis(data=inputs)
    for result in results:
S
Steffy-zxf 已提交
21 22 23 24 25 26 27 28
        if six.PY2:
            print(json.dumps(
                result['word'], encoding="utf8", ensure_ascii=False))
            print(json.dumps(
                result['tag'], encoding="utf8", ensure_ascii=False))
        else:
            print(result['word'])
            print(result['tag'])