我正在研究一个涉及通过Hobbs算法进行回指解析的项目.我使用Stanford解析器解析了我的文本,现在我想操纵节点以实现我的算法.
目前,我不明白如何:
基于其POS标签访问节点(例如,我需要以代词开头 - 我如何得到所有代词?).
使用访客.我有点像Java的菜鸟,但是在C++中我需要实现一个Visitor仿函数然后处理它的钩子.我找不到Stanford Parser的Tree结构.那是jgrapht吗?如果是的话,你可以在代码片段中提供一些指示吗?
有没有办法从Stanford CoreNLP中提取段落信息?我目前正在使用它从文档中提取句子,但我也有兴趣确定文档的段落结构,我理想情况下CoreNLP会为我做.我在源文档中将段落作为双换行符.我查看了CoreNLP的javadoc,似乎有一个ParagraphAnnotation类,但文档似乎没有指定它包含的内容,我看不到任何地方如何使用它的例子.谁能指出我正确的方向?
作为参考,我当前的代码是这样的:
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
List<Sentence> convertedSentences = new ArrayList<> ();
for (CoreMap sentence : sentences)
{
convertedSentences.add (new Sentence (sentence));
}
Run Code Online (Sandbox Code Playgroud)
句子的构造函数从句子中提取单词.我如何扩展这一点以便获得额外的数据级别,即我当前的文档范围内的"convertedSentences"列表由"convertedParagraphs"列表补充,其中每个条目包含一个"convertedSentences"列表?
我尝试了对我来说最明显的方法:
List<CoreMap> paragraphs = document.get(ParagraphsAnnotation.class);
for (CoreMap paragraph : paragraphs)
{
List<CoreMap> sentences = paragraph.get(SentencesAnnotation.class);
List<Sentence> convertedSentences = new ArrayList<> ();
for (CoreMap sentence : sentences)
{
convertedSentences.add (new Sentence (sentence));
}
convertedParagraphs.add (new Paragraph (convertedSentences));
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,所以我想我误解了一下这应该是怎么回事.
我喜欢Stanford CoreNLP,现在它对我的NLP需求非常准确.问题在于分析大量文本(假设数百万句话)需要数天时间.
是否存在牺牲一些准确性以提高效率的替代Java实现(理想情况下)提供相同的API?
我正在尝试使用StanfordCoreNLP来区分单个和复数名词.首先,我正在使用http://nlp.stanford.edu/software/corenlp.shtml中的代码.在netbeans 8.0中,我打开了一个新的java项目.我已经下载stanford-corenlp-full-2014-06-16并将jar文件(包括模型jar)添加到我的项目中:

代码类SingularORPlural:
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import edu.stanford.nlp.ling.CoreAnnotations.LemmaAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;
/**
*
* @author ha
*/
public class SingularORPlural {
protected StanfordCoreNLP pipeline;
public SingularORPlural() {
// Create StanfordCoreNLP object properties, with POS tagging
// (required for lemmatization), and lemmatization
Properties props;
props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma");
/*
* This is a pipeline that takes in a string and …Run Code Online (Sandbox Code Playgroud) 我正在使用stanford CoreNLP来尝试找到名词短语的语法关系.
这是一个例子:
鉴于句子"健身房很脏".
我设法将"健身房"识别为我的目标名词短语.我现在正在寻找一种方法来发现"脏"的形容词与"健身室"有关系,而不仅仅是 "房间".
示例代码:
private static void doSentenceTest(){
Properties props = new Properties();
props.put("annotators","tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP stanford = new StanfordCoreNLP(props);
TregexPattern npPattern = TregexPattern.compile("@NP");
String text = "The fitness room was dirty.";
// create an empty Annotation just with the given text
Annotation document = new Annotation(text);
// run all Annotators on this text
stanford.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
Tree sentenceTree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
TregexMatcher matcher …Run Code Online (Sandbox Code Playgroud) 我正在寻找优化斯坦福CoreNLP情绪管道性能的方法.结果,想要得到句子的情感,但只有那些包含作为输入的特定关键词的句子.
我尝试了两种方法:
方法1:StanfordCoreNLP管道用情绪注释整个文本
我已经定义了一个注释器管道:tokenize,ssplit,parse,sentiment.我在整篇文章中运行它,然后在每个句子中查找关键字,如果它们存在,则运行返回关键字值的方法.虽然处理需要几秒钟,但我并不满意.
这是代码:
List<String> keywords = ...;
String text = ...;
Map<Integer,Integer> sentenceSentiment = new HashMap<>();
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
props.setProperty("parse.maxlen", "20");
props.setProperty("tokenize.options", "untokenizable=noneDelete");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation annotation = pipeline.process(text); // takes 2 seconds!!!!
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (int i=0; i<sentences.size(); i++) {
CoreMap sentence = sentences.get(i);
if(sentenceContainsKeywords(sentence,keywords) {
int sentiment = RNNCoreAnnotations.getPredictedClass(sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class));
sentenceSentiment.put(sentence,sentiment);
}
}
Run Code Online (Sandbox Code Playgroud)
方法2:StanfordCoreNLP管道用句子注释整个文本,分离在感兴趣的句子上运行的注释器
由于第一个解决方案的性能较弱,我已经定义了第二个解决方案.我已经使用注释器定义了一个管道:tokenize,ssplit.我在每个句子中查找了关键字,如果它们存在,我只为这个句子创建了一个注释并在其上运行下一个注释器:ParserAnnotator,BinarizerAnnotator和SentimentAnnotator.
由于ParserAnnotator,结果真的不令人满意.即使我用相同的属性初始化它.在方法1中,有时花费的时间比整个管道在文档上运行的时间更长.
List<String> keywords = ...;
String text = ...;
Map<Integer,Integer> …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习斯坦福NLP分类器,并希望解决文档分类问题.任何人都可以建议我找到一个有效的例子吗?我也在查看Open NLP库,并且能够找到许多工作示例,例如
http://tharindu-rusira.blogspot.com/2013/12/opennlp-text-classifier.html
因此,正如我们在这里看到的,很容易弄清楚发生了什么并创建了一个小型工作原型.但是,我找不到斯坦福NLP的简单示例,它将向我展示
有什么建议?
我的数据集中有两个句子:
w1 =我是Pusheen的猫.我太可爱了.#句号后没有空格
w2 =我是Pusheen的猫.我很可爱.#期后的空间
当我使用NKTL tokenizer(word和sent)时,nltk无法区分cat.I.
这是单词标记化
>>> nltk.word_tokenize(w1, 'english')
['I', 'am', 'Pusheen', 'the', 'cat.I', 'am', 'so', 'cute']
>>> nltk.word_tokenize(w2, 'english')
['I', 'am', 'Pusheen', 'the', 'cat', '.', 'I', 'am', 'so', 'cute']
Run Code Online (Sandbox Code Playgroud)
并发送了tokenize
>>> nltk.sent_tokenize(w1, 'english')
['I am Pusheen the cat.I am so cute']
>>> nltk.sent_tokenize(w2, 'english')
['I am Pusheen the cat.', 'I am so cute']
Run Code Online (Sandbox Code Playgroud)
我想问一下如何解决这个问题?即:在我的数据集中将nlkt检测为w2,有时单词和标点符号会粘在一起.
更新:尝试过Stanford CoreNLP 3.7.0,他们也无法区分'cat.I'为'cat','.','I'
meow@meow-server:~/projects/stanfordcorenlp$ java edu.stanford.nlp.process.PTBTokenizer sample.txt
I
am
Pusheen
the
cat.I
am
so
cute
.
PTBTokenizer tokenized 9 tokens at 111.21 tokens …Run Code Online (Sandbox Code Playgroud) 在StanfordCore NLP网站上有以下演示:http : //nlp.stanford.edu : 8080/sentiment/rntnDemo.html
该演示为句子提供了详细的情感评分,范围从0到4。
我了解如何使用命令行获得“积极”或“消极”评估,类似于以下内容: corenlp.run的屏幕截图显示了积极的情绪分析
我已经看到了这个问题,但是我对如何创建所附屏幕快照中显示的分析感兴趣。使用Stanford Core NLP Java代码获取情感分析结果
在Stanford CoreNLP中,有没有一种方法可以返回给定句子的分数(即0-4),从而显示其阳性或阴性程度?
谢谢!
我有一句话,我需要单独识别人名:
例如:
sentence = "Larry Page is an American business magnate and computer scientist who is the co-founder of Google, alongside Sergey Brin"
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码来识别NER.
from nltk import word_tokenize, pos_tag, ne_chunk
print(ne_chunk(pos_tag(word_tokenize(sentence))))
Run Code Online (Sandbox Code Playgroud)
我收到的输出是:
(S
(PERSON Larry/NNP)
(ORGANIZATION Page/NNP)
is/VBZ
an/DT
(GPE American/JJ)
business/NN
magnate/NN
and/CC
computer/NN
scientist/NN
who/WP
is/VBZ
the/DT
co-founder/NN
of/IN
(GPE Google/NNP)
,/,
alongside/RB
(PERSON Sergey/NNP Brin/NNP))
Run Code Online (Sandbox Code Playgroud)
我想提取所有人名,例如
Larry Page
Sergey Brin
Run Code Online (Sandbox Code Playgroud)
为了达到这个目的,我对此链接进行了审核并尝试了这一点.
from nltk.tag.stanford import StanfordNERTagger
st = StanfordNERTagger('/usr/share/stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz','/usr/share/stanford-ner/stanford-ner.jar')
Run Code Online (Sandbox Code Playgroud)
但是我继续得到这个错误:
LookupError: Could not find stanford-ner.jar jar …Run Code Online (Sandbox Code Playgroud) stanford-nlp ×10
java ×7
nlp ×6
nltk ×2
python ×2
jgrapht ×1
netbeans ×1
parsing ×1
performance ×1
tokenize ×1