【问题标题】:Finding out adjectives describing a noun using Stanford NLP使用斯坦福 NLP 找出描述名词的形容词
【发布时间】:2013-06-22 13:14:04
【问题描述】:

我需要编写一个代码,将有关产品的几行 cmets 作为输入,并根据评论中描述产品的形容词对产品进行评分。我刚刚使用 POS 标记器来标记每条评论的词性。现在,我必须挑选出描述名词的形容词,如果一个名词似乎与产品有关,我需要考虑相应的形容词。这是我用于 POS 标记的代码。它工作得很好。

import java.io.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class Tagg {
public static void main(String[] args) throws IOException,
ClassNotFoundException {

String tagged;

// Initialize the tagger
MaxentTagger tagger = new MaxentTagger("edu/stanford/nlp/models/pos-tagger/wsj-        left3words/wsj-0-18-left3words-distsim.tagger");
FileInputStream fstream = new FileInputStream("src/input.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
FileWriter q = new FileWriter("src/output.txt",true);
BufferedWriter out =new BufferedWriter(q);
String sample;
//we will now pick up sentences line by line from the file input.txt and store it in the string sample
while((sample = br.readLine())!=null)
{
//tag the string
tagged = tagger.tagString(sample);
System.out.print(tagged+"\n");
//write it to the file output.txt
out.write(tagged);
out.newLine();
}
out.close();
}
}

我需要一个方法来继续。 .

【问题讨论】:

标签: java nlp stanford-nlp pos-tagger


【解决方案1】:

一个简单的解决方案是使用依赖解析器,它包含在斯坦福 CoreNLP 中。算法是这样的:

  1. PoS 标签和依赖解析你的句子
  2. 确定您感兴趣的名词。如果您正在处理产品评论,一个简单的方法是将文本中的所有名词与已知产品名称列表进行匹配。
  3. 在依赖解析器的输出中查找包含您感兴趣的名词的 amod 关系。

使用online Stanford demo 的示例:

输入:

I own a tall glass and just bought a big red car.

amod 依赖:

amod(glass-5, tall-4)
amod(car-12, big-10)
amod(car-12, red-11)

假设评论是关于汽车的。最后两个依赖项包含目标名词car,因此您要查找的形容词是bigred

警告:这是一种高精度搜索算法,而不是高召回率。您的关键字列表永远不会详尽,因此您可能会错过一些形容词。此外,解析器并不完美,有时会出错。此外,amod 关系是形容词描述名词的多种方式之一。例如,"The car is red" 解析为

det(car-2, The-1)
nsubj(red-4, car-2)
nsubj(black-6, car-2)
cop(red-4, is-3)
root(ROOT-0, red-4)
conj_and(red-4, black-6)

如您所见,这里没有amod 关系,只有一个系词和一个连词。您可以尝试制定更复杂的规则,以提取car is redcar is black 的事实。是否要这样做取决于您。在目前的形式中,当这个算法返回一个形容词时,你可以有理由相信它确实在描述这个名词。在我看来,这是一个很好的特性,但这完全取决于您的用例。


OP 评论后编辑:

是的,I bought a new car.It is awesome. 是两个独立的句子,将分别进行解析。这个问题被称为coreference (anaphora) resolution。事实证明,斯坦福也支持这一点——见their webpage。还有a system by CMU,也是Java。我没有使用过这些系统中的任何一个,但后者有一个非常有用的在线演示。把上面两句话放进去,我得到了

[I] bought [a new car]2 .
[It]2 is awesome .

【讨论】:

  • 太棒了!所以,你是说从I bought a new car. It is awesome 中挑选出awesome 有点困难,我应该继续努力吗?
猜你喜欢
  • 2015-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-26
相关资源
最近更新 更多