【发布时间】:2013-09-30 13:57:15
【问题描述】:
我想从句子中提取名词,从词性标签中取回原句
//Extract the words before _NNP & _NN from below and also how to get back the original sentence from the Pos TAG.
Original Sentence:Hi. How are you? This is Mike·
POSTag: Hi._NNP How_WRB are_VBP you?_JJ This_DT is_VBZ Mike._NN
我试过这样的
String txt = "Hi._NNP How_WRB are_VBP you?_JJ This_DT is_VBZ Mike._NN";
String re1 = "((?:[a-z][a-z0-9_]*))"; // Variable Name 1
String re2 = ".*?"; // Non-greedy match on filler
String re3 = "(_)"; // Any Single Character 1
String re4 = "(NNP)"; // Word 1
Pattern p = Pattern.compile(re1 + re2 + re3 + re4, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(txt);
if (m.find()) {
String var1 = m.group(1);
System.out.print( var1.toString() );
}
}
输出:嗨 但我需要一个句子中所有名词的列表。
【问题讨论】:
-
你有没有尝试过?
[a-zA-Z](?=[.]_NN)将捕获任何 alphachar 字符串,然后是._NN,也许你可以从它开始。 -
您的示例中有错字。在第一个街区,“迈克”。后面是“_NN”,但在第二个块中,后面是“_NNP”。
-
这是一种名词,它是专有名词我得到了 pos 标签,它给了我不同类型的名词