- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我的情况。
我有一个处理文本的 TextProcessor 类。我需要在这样的文本中找到引用,然后使用斯坦福的工具 OpenIE 提取信息。我使用这两条管道:
"tokenize,ssplit,pos,lemma,ner,parse,mention,coref" for coreferences.
和
"tokenize,ssplit,pos,lemma,depparse,natlog,openie" for Information Extraction.
单独使用它们来分析单个文本需要很多时间,但目前我必须这样做,因为将它们一起使用需要大量内存,而且管道会超出我的内存范围。
public class TextProcessor(){
Properties props;
StanfordCoreNLP pipeline;
public TextProcessor() {
props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,mention,coref");
pipeline = new StanfordCoreNLP(props);
}
// Performs NER and COREF
public void process(String text) {
Annotation document = new Annotation(malware.getDescription());
pipeline.annotate(document);
// Process text (tokenization, pos, lemma, ner, coref)....
}
public void extractInformation(String document) {
props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
pipeline = new StanfordCoreNLP(props);
Annotation doc = new Annotation(document);
pipeline.annotate(doc);
// Extract informations from doc ...
}
有没有办法动态地将两个管道放在一起?我的意思是,像这样:
1) "tokenize,ssplit,pos,lemma,ner,depparse,mention,coref"
2) "tokenize,ssplit,pos,lemma,ner,depparse,mention,coref,natlog,openie".
我尝试从第一个方法 process(String text)
返回一个 Annotation 对象,然后在 extractInformation(String text)
方法中将其他三个属性添加到它,像这样:
public Annotation process(String text) {
Annotation document = new Annotation(malware.getDescription());
pipeline.annotate(document);
// Process text (tokenization, pos, lemma, ner, coref)....
return document;
}
public void extractInformation(Annotation document) {
props.setProperty("annotators","depparse,natlog,openie");
pipeline = new StanfordCoreNLP(props);
pipeline.annotate(document);
// Extract informations from doc ...
}
但是我得到这个错误:
注释器“depparse”需要注释“TextAnnotation”。此注释器的通常要求是:tokenize、ssplit、pos
。
我认为将新的三个属性(depparse、natlog、openie)添加到一个已经注释的文档(使用 tokenize、ssplit、pos)会起作用,但它没有。
那么,有没有办法将这些属性添加到最旧的管道,避免再次执行所有管道(加上新属性)并避免内存超出其界限?
更新
我需要做的就是
public Annotation process(String text) {
Annotation document = new Annotation(malware.getDescription());
pipeline.annotate(document);
// Process text (tokenization, pos, lemma, ner, coref)....
StanfordCoreNLP.clearAnnotatorPool(); // <-- Added: to get rid of the models and solve the memory issue
return document;
}
public void extractInformation(Annotation document) {
props.setProperty("annotators","natlog,openie");
props.setProperty("enforceRequirements", "false") //<-- Added
pipeline = new StanfordCoreNLP(props);
pipeline.annotate(document);
// Extract informations from doc ...
}
或者,您可以使用:
pipeline = new StanfordCoreNLP(props, false);
在extractInformation(注释文档)中。
最佳答案
听起来您想构建第一个管道,在一组文档上运行它,清除内存,然后构建第二个管道并在一组文档上运行它。
如果您在同一组注释上运行第二个管道,它只会从第一个管道完成的地方开始。但是您需要将 enforceRequirements
设置为 false
,这样第二个管道就不会崩溃。此外,在您使用完第一个管道后,您应该运行 StanfordCoreNLP.clearAnnotatorPool();
以摆脱模型,否则您将无法解决内存问题。
关于java - 动态添加属性到 StanfordCoreNLP Annotator 或 Pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46194378/
在 documentation ,有一个使用类的示例:StanfordCoreNLP .但是当您下载最新版本时,该类无处可寻。在早期版本中很容易找到它,并且该示例效果很好。我一直在寻找,但似乎无法弄清
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOExce
问题:是否可以选择使用 stanford-core-nlp 来词干? ? 我找不到一个!我正在使用 stanford-corenlp-3.5.2.jar。 代码: public class Stanf
假设我定义了以下 StanfordCoreNLP 管道: Properties props = new Properties(); props.put("language", "english");
我一直在网站上手动尝试 StanfordCoreNLP NER 和所有内容,例如,它们似乎依赖于非常具体/正确的英语提示来检测实体。但是,在处理网络文本时,您可以在其中放置一些文本,如 李四 计算机科
我找到了这段对文本进行词形还原的代码。 此文本被拆分成句子,然后进行标记化。 最后对标记进行词形还原。 我的问题是我不需要执行 splitting 和 tokenize 的步骤,因为我已经在我的程序中
我正在尝试将 Stanford CoreNLP 用作我的 Java 程序中的库。我使用 IntelliJ 作为 IDE。我试图测试这个库,所以我写了这段代码: import edu.stanford.
我已经从 http://nlp.stanford.edu/software/corenlp.shtml#Download 下载并安装了所需的 jar 文件. 我已经包含了五个 jar 文件 Satnf
我刚刚开始研究斯坦福 NLP 库。我下载并解压缩了包含所有内容的核心文件,然后尝试运行演示文件 (StanfordCoreNlpDemo.java)。 import edu.stanford.nlp.
下面是我的情况。 我有一个处理文本的 TextProcessor 类。我需要在这样的文本中找到引用,然后使用斯坦福的工具 OpenIE 提取信息。我使用这两条管道: "tokenize,ssplit,
我正在使用StanfordCoreNLP作为依存解析器句子。我按照本教程设置并使用StanfordCoreNLP:https://www.khalidalnajjar.com/setup-use-st
我对StanfordNlpTagger很天真。我已经下载了 JAR 文件形式 http://nlp.stanford.edu/software/corenlp.shtml#Download . 我已经
所以我正在使用 stanford core nlp 库做一个关于 TokenRegex 模式匹配的示例。需要帮助将规则文件放置在适当的位置。尝试将其放在 src 文件夹中,但没有成功 代码:- pub
我正在使用 StanfordCoreNLP API 接口(interface)以编程方式执行一些基本的 NLP。我需要在自己的语料库上训练模型,但我想使用 StanfordCoreNLP 界面来完成它
我正在尝试加载包 StanfordCoreNLP 以正确解析其页面 (https://nlp.stanford.edu/sentiment/treebank.html) 中显示的电影评论:(我使用的是
我正在尝试使用 StanfordCoreNLP 来区分句子中的单数名词和复数名词。作为开始,我正在使用 http://nlp.stanford.edu/software/corenlp.shtml 中
我想在 R 软件中使用“coreNLP”库。我使用的是ubuntu,java版本是11.0.4。 我在使用initCoreNLP()期间遇到错误 Error in rJava::.jnew("edu.
我从 https://stanfordnlp.github.io/CoreNLP/ 下载了 stanford corenlp zip 文件然后将其解压缩并插入其中。现在我尝试运行以下 java 文件。
我是一名优秀的程序员,十分优秀!