在PYTHON中设置Stanford corenlp面临困难

在PYTHON中设置Stanford corenlp面临困难,nlp,stanford-nlp,Nlp,Stanford Nlp,我没有找到一个完整的教程在我的系统(windows)上使用python来使用StanfordCorenlp。在搜索了很多之后,我正在使用StanfordCoreNLP包并在我的系统上使用。我找不到任何文档可以更有效地使用它我想提取关系和OPENIE,因为没有任何文档,我只是尝试将OPENIE放在属性中 self.props = { 'annotators': 'tokenize,ssplit,pos,lemma,ner,parse,depparse,dcoref,rela

我没有找到一个完整的教程在我的系统(windows)上使用python来使用StanfordCorenlp。在搜索了很多之后,我正在使用StanfordCoreNLP包并在我的系统上使用。我找不到任何文档可以更有效地使用它我想提取关系和OPENIE,因为没有任何文档,我只是尝试将OPENIE放在属性中

self.props = {
            'annotators': 'tokenize,ssplit,pos,lemma,ner,parse,depparse,dcoref,relation,OpenIE',
            'pipelineLanguage': 'en',
            'outputFormat': 'json'
        }

但是它不起作用!(显然)。我得到这个错误

AttributeError:'StanfordCoreNLP'对象没有属性“关系” AttributeError:'StanfordCoreNLP'对象没有属性'openie'

你能给我介绍一下PYTHON的详细教程吗? 我听说StanfordCoreNLP软件包不具备StanfordCoreNLP的所有功能?太令人困惑了!有这么多的软件包,很难决定使用哪一个,哪一个是正确的! 请帮忙

from stanfordcorenlp import StanfordCoreNLP
import logging
import json

class StanfordNLP:
    def __init__(self, host='http://localhost', port=9000):
        self.nlp = StanfordCoreNLP(host, port=port,
                                   timeout=30000)  # , quiet=False, logging_level=logging.DEBUG)
        self.props = {
            'annotators': 'tokenize,ssplit,pos,lemma,ner,parse,depparse,dcoref,relation,OpenIE',
            'pipelineLanguage': 'en',
            'outputFormat': 'json'
        }

    def word_tokenize(self, sentence):
        return self.nlp.word_tokenize(sentence)

    def pos(self, sentence):
        return self.nlp.pos_tag(sentence)

    def ner(self, sentence):
        return self.nlp.ner(sentence)

    def parse(self, sentence):
        return self.nlp.parse(sentence)

    def dependency_parse(self, sentence):
        return self.nlp.dependency_parse(sentence)

    def annotate(self, sentence):
        return json.loads(self.nlp.annotate(sentence, properties=self.props))

    def cor(self, sentence):
        return (self.nlp.coref(sentence))

    # **I tried to get relations and OpenIE**
    def relations(self, sentence):
        return (self.nlp.relations(sentence))

     def openie(self, sentence):
        return (self.nlp.openie(sentence))




    @staticmethod
    def tokens_to_dict(_tokens):
        tokens = defaultdict(dict)
        for token in _tokens:
            tokens[int(token['index'])] = {
                'word': token['word'],
                'lemma': token['lemma'],
                'pos': token['pos'],
                'ner': token['ner']
            }
        return tokens

if __name__ == '__main__':
    sNLP = StanfordNLP()
    text = 'John likes apple. Mary Likes Him'


    s=sNLP.relations(text)
    print(s)
    print("OpenIE:", sNLP.openie(text))
    ```
StanfordCorenlp(Java代码库)提供了对OpenIE和关系提取的访问

您可以启动服务器(Java)并用Python访问它。您可以用JSON返回结果

这里有关于使用服务器的详细说明:

from stanfordcorenlp import StanfordCoreNLP
import logging
import json

class StanfordNLP:
    def __init__(self, host='http://localhost', port=9000):
        self.nlp = StanfordCoreNLP(host, port=port,
                                   timeout=30000)  # , quiet=False, logging_level=logging.DEBUG)
        self.props = {
            'annotators': 'tokenize,ssplit,pos,lemma,ner,parse,depparse,dcoref,relation,OpenIE',
            'pipelineLanguage': 'en',
            'outputFormat': 'json'
        }

    def word_tokenize(self, sentence):
        return self.nlp.word_tokenize(sentence)

    def pos(self, sentence):
        return self.nlp.pos_tag(sentence)

    def ner(self, sentence):
        return self.nlp.ner(sentence)

    def parse(self, sentence):
        return self.nlp.parse(sentence)

    def dependency_parse(self, sentence):
        return self.nlp.dependency_parse(sentence)

    def annotate(self, sentence):
        return json.loads(self.nlp.annotate(sentence, properties=self.props))

    def cor(self, sentence):
        return (self.nlp.coref(sentence))

    # **I tried to get relations and OpenIE**
    def relations(self, sentence):
        return (self.nlp.relations(sentence))

     def openie(self, sentence):
        return (self.nlp.openie(sentence))




    @staticmethod
    def tokens_to_dict(_tokens):
        tokens = defaultdict(dict)
        for token in _tokens:
            tokens[int(token['index'])] = {
                'word': token['word'],
                'lemma': token['lemma'],
                'pos': token['pos'],
                'ner': token['ner']
            }
        return tokens

if __name__ == '__main__':
    sNLP = StanfordNLP()
    text = 'John likes apple. Mary Likes Him'


    s=sNLP.relations(text)
    print(s)
    print("OpenIE:", sNLP.openie(text))
    ```