hanlp2.0代碼塊


import hanlp

tokenizer = hanlp.load('PKU_NAME_MERGED_SIX_MONTHS_CONVSEG')
tagger = hanlp.load(hanlp.pretrained.pos.CTB5_POS_RNN_FASTTEXT_ZH)
syntactic_parser = hanlp.load(hanlp.pretrained.dep.CTB7_BIAFFINE_DEP_ZH)
semantic_parser = hanlp.load(hanlp.pretrained.sdp.SEMEVAL16_NEWS_BIAFFINE_ZH)
print(semantic_parser([('蠟燭', 'NN'), ('兩', 'CD'), ('頭', 'NN'), ('燒', 'VV')]))

pipeline = hanlp.pipeline() \
    .append(hanlp.utils.rules.split_sentence, output_key='sentences') \
    .append(tokenizer, output_key='tokens') \
    .append(tagger, output_key='part_of_speech_tags') \
    .append(syntactic_parser, input_key=('tokens', 'part_of_speech_tags'), output_key='syntactic_dependencies') \
    .append(semantic_parser, input_key=('tokens', 'part_of_speech_tags'), output_key='semantic_dependencies')


text='''
HanLP是一系列模型與算法組成的自然語言處理工具包,目標是普及自然語言處理在生產環境中的應用。
HanLP具備功能完善、性能高效、架構清晰、語料時新、可自定義的特點。
內部算法經過工業界和學術界考驗,配套書籍《自然語言處理入門》已經出版。
'''
p1=pipeline(text)
type(p1)  # hanlp.common.document.Document


import pickle

pickle.dump( p1, open( "save.p1", "wb" ) )

p2 = pickle.load( open( "save.p1", "rb" ) )


with open('/home/chencheng/data/sogou_phone0/sogou_q_phone','r')as ifile:
    corpus = ifile.read()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM