How to use the pyhanlp.HanLP.segment function in pyhanlp

To help you get started, we’ve selected a few pyhanlp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaddlePaddle / models / PaddleNLP / lexical_analysis / compare.py View on Github external
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
github daviddwlee84 / MachineLearningPractice / Algorithm / HMM / HMM_Text_Segmentation / CompareJiebaHanLP.py View on Github external
def HanLP_seg(content):
    segments = HanLP.segment(content)
    for term in segments:
        if str(term.nature) != 'w':
            print('{}/{}'.format(term.word, term.nature), end=' ')