how to use spacy lemmatizer to get a word into basic form

后端 未结 5 1313
青春惊慌失措
青春惊慌失措 2021-02-02 08:25

I am new to spacy and I want to use its lemmatizer function, but I don\'t know how to use it, like I into strings of word, which will return the string with the basic form the w

5条回答
  •  清歌不尽
    2021-02-02 08:44

    Code :

    import os
    from spacy.en import English, LOCAL_DATA_DIR
    
    data_dir = os.environ.get('SPACY_DATA', LOCAL_DATA_DIR)
    
    nlp = English(data_dir=data_dir)
    
    doc3 = nlp(u"this is spacy lemmatize testing. programming books are more better than others")
    
    for token in doc3:
        print token, token.lemma, token.lemma_
    

    Output :

    this 496 this
    is 488 be
    spacy 173779 spacy
    lemmatize 1510965 lemmatize
    testing 2900 testing
    . 419 .
    programming 3408 programming
    books 1011 book
    are 488 be
    more 529 more
    better 615 better
    than 555 than
    others 871 others
    

    Example Ref: here

提交回复
热议问题