我想从句子中提取名词并从 POS Tag 中取回原句
//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() );
}
}
输出:嗨,但我需要一个句子中所有名词的列表。