Stanford Parser and NLTK

后端 未结 18 2371
既然无缘
既然无缘 2020-11-22 01:32

Is it possible to use Stanford Parser in NLTK? (I am not talking about Stanford POS.)

18条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 02:32

    I took many hours and finally found a simple solution for Windows users. Basically its summarized version of an existing answer by alvas, but made easy to follow(hopefully) for those who are new to stanford NLP and are Window users.

    1) Download the module you want to use, such as NER, POS etc. In my case i wanted to use NER, so i downloaded the module from http://nlp.stanford.edu/software/stanford-ner-2015-04-20.zip

    2) Unzip the file.

    3) Set the environment variables(classpath and stanford_modules) from the unzipped folder.

    import os
    os.environ['CLASSPATH'] = "C:/Users/Downloads/stanford-ner-2015-04-20/stanford-ner.jar"
    os.environ['STANFORD_MODELS'] = "C:/Users/Downloads/stanford-ner-2015-04-20/classifiers/"
    

    4) set the environment variables for JAVA, as in where you have JAVA installed. for me it was below

    os.environ['JAVAHOME'] = "C:/Program Files/Java/jdk1.8.0_102/bin/java.exe"
    

    5) import the module you want

    from nltk.tag import StanfordNERTagger
    

    6) call the pretrained model which is present in classifier folder in the unzipped folder. add ".gz" in the end for file extension. for me the model i wanted to use was english.all.3class.distsim.crf.ser

    st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
    

    7) Now execute the parser!! and we are done!!

    st.tag('Rami Eid is studying at Stony Brook University in NY'.split())
    

提交回复
热议问题