找出使用斯坦福NLP描述名词的形容词

ven*_*tKA 3 java nlp pos-tagger stanford-nlp

我需要编写一个代码,该代码对产品的几行评论作为输入,并根据描述评论中产品的形容词对产品进行评级.我刚刚使用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();
}
}
Run Code Online (Sandbox Code Playgroud)

我需要一种方法来继续..

mba*_*rov 5

一个简单的解决方案将使用Stanford CoreNLP中包含的依赖解析器.算法如下:

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

使用在线斯坦福演示的示例:

输入:

I own a tall glass and just bought a big red car.
Run Code Online (Sandbox Code Playgroud)

amod 依赖关系:

amod(glass-5, tall-4)
amod(car-12, big-10)
amod(car-12, red-11)
Run Code Online (Sandbox Code Playgroud)

假设评论是关于汽车的.最后两个依赖项包含目标名词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)
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,这里没有amod关系,只有一个copula和一个连词.你可以尝试与工艺更复杂的规则试图提取的事实car is redcar is black.你是否愿意这样做是最重要的.在当前形式中,当该算法返回形容词时,您可以合理地确信它确实描述了名词.在我看来,这是一个很好的特性,但这一切都取决于你的用例.


OP评论后编辑:

是的,I bought a new car.并且It is awesome.是两个单独的句子,将分开解析.这个问题被称为共指(anaphora)解决方案.原来斯坦福也支持这一点 - 看他们的网页.CMU还有一个系统,也是Java.我没有使用过这些系统,但后者有一个非常有用的在线演示.把上面两句话放进来,我明白了

[I] bought [a new car]2 .
[It]2 is awesome .
Run Code Online (Sandbox Code Playgroud)