Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_hanlp_result(sentences):
"""
Ref to: https://github.com/hankcs/pyhanlp
Install by: pip install pyhanlp
(Before using pyhanlp, you need to download the model manully.)
"""
from pyhanlp import HanLP
preds = []
for sentence in sentences:
arraylist = HanLP.segment(sentence)
sent_seg = " ".join(
[term.toString().split("/")[0] for term in arraylist])
sent_seg = to_unicode(sent_seg)
preds.append(sent_seg)
return preds
def HanLP_seg(content):
segments = HanLP.segment(content)
for term in segments:
if str(term.nature) != 'w':
print('{}/{}'.format(term.word, term.nature), end=' ')