如何从一个包含多个动词和介词的复杂句子中获取主语,动词和宾语?

时间:2018-11-12 09:51:17

标签: java data-structures nlp predicate subject

以前,我是使用(名词)(动词)(名词)关系进行区分的,

例如,它可以很好地配合:

(John) (went) (to the market)

我的源代码:

str = John went to the market
splited_str = str.split(" ")
String subject, verb, object;
Boolean flag = true;
for i=0 to i<splited_str.length
  if (!isVerb(splited_str[i]) && flag)
     subject += splited_str[i] + " "
  if (isVerb)
     flag = false
     verb = splited_str[i]
  else
     object += splited_str[i] + " "

但是对于像这样的复杂句子,我的代码失败了:

It is up to us to find the answer.

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以使用Stanford CoreNLP OpenIE提取这种类型的三元组。

在Java中使用OpenIE时,只需将注释器openie添加到属性中即可。

有关使用三胞胎的示例,请参见this example from Stanfordthis answer which uses a command line

弄清楚三元组之后,可以删除作为其他子集的三元组,以仅获取更具体的三元组。

相关问题