java - 使用StanfordCoreNLPServer将props(属性)从Java转换为Python3

标签 java python-3.x stanford-nlp

我正在将使用 StanfordCoreNLPJava 代码转换为访问 StanfordCoreNLPServerPython 代码。我根本不是 Java 开发人员。

java代码使用以下属性实例化StanfordCoreNLPpipeline

    Properties props = new Properties();
    props.put("annotators", "tokenize, ssplit, pos, lemma, ner, regexner");
    props.put("ner.model", serializedClassifier);
    props.put("pos.model", posModel);
    props.put("tokenize.language", "de");
    props.put("ssplit.isOneSentence", "true");
    props.put("ssplit.language", "de");
    props.put("lemma.language", "de");
    props.put("regexner.mapping", Init.REGEXNER);
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

我正在实例化 Python 管道,如下所示:

    self.nlp = StanfordCoreNLP(host, port=port, timeout=30000)
    self.props = {
        'annotators': 'tokenize, ssplit, pos, lemma, ner, regexner',
        'pipelineLanguage': 'de',
        'tokenizeLanguage': 'de',
        'outputFormat': 'json', 
    }

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

问题是,我不确定如何将java属性(例如ner.model)转换为Python dict键。我认为它会类似于 nerModel ...但是,当传递 self.props 对象时 - 无意义的键不会出错。所以,我不知道 key 是否有效。

我在斯坦福大学页面上的任何地方都没有看到有关 Python 属性的文档。

最佳答案

启动服务器时,您可以使用-serverProperties选项并提交一个属性文件,该文件将自定义服务器使用的管道。

完整详细信息请参见此处:

https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

关于java - 使用StanfordCoreNLPServer将props(属性)从Java转换为Python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51133613/

相关文章:

java - 使用 Java 模拟杂货店排队队列

python - 将图像复制到剪贴板?

java - GUI 上的按钮有什么问题

python - 解析俄语站点编码错误

python - 在 excel 文件中写入字典值

java - 从 stanford core nlp 依赖表示中提取主要语义元素

java - 如何从 Stanford Core NLP 包中获取短语级情绪

regex - 如何对 NLP 解析树进行逆向工程以得到原始句子?

java读写构造

java - findbugs 显示 sessionFactory 为 null 保证被取消引用