Stanford nlp for python

前端 未结 9 1247
野的像风
野的像风 2020-11-29 17:41

All I want to do is find the sentiment (positive/negative/neutral) of any given string. On researching I came across Stanford NLP. But sadly its in Java. Any ideas on how ca

9条回答
  •  囚心锁ツ
    2020-11-29 18:10

    Use stanfordcore-nlp python library

    stanford-corenlp is a really good wrapper on top of the stanfordcore-nlp to use it in python.

    wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip

    Usage

    # Simple usage
    from stanfordcorenlp import StanfordCoreNLP
    
    nlp = StanfordCoreNLP('/Users/name/stanford-corenlp-full-2018-10-05')
    
    sentence = 'Guangdong University of Foreign Studies is located in Guangzhou.'
    print('Tokenize:', nlp.word_tokenize(sentence))
    print('Part of Speech:', nlp.pos_tag(sentence))
    print('Named Entities:', nlp.ner(sentence))
    print('Constituency Parsing:', nlp.parse(sentence))
    print('Dependency Parsing:', nlp.dependency_parse(sentence))
    
    nlp.close() # Do not forget to close! The backend server will consume a lot memory.
    

    More info

提交回复
热议问题