如何使用Java将所有nn标签组合成一个短语标签
nsubj(martyrdom-4, Today-1)
cop(martyrdom-4, is-2)
det(martyrdom-4, the-3)
root(ROOT-0, martyrdom-4)
nn(Mukherjee-7, Dr-6)
prep_of(martyrdom-4, Mukherjee-7)
det(founder-9, the-8)
dep(tribute-17, founder-9)
prep_of(founder-9, Jan-11)
nn(body-15, Sangh-12)
nn(body-15, BJP-13)
nn(body-15, parent-14)
dep(tribute-17, body-15)
poss(tribute-17, My-16)
dep(martyrdom-4, tribute-17)
prep_to(tribute-17, him-19)
我想得到一个名词短语:
prep_of(founder-9,Jan-11)
nn(body-15, Sangh-12)
nn(body-15, BJP-13)
nn(body-15, parent-14)
输出应该是---------> jan sangh BJP parent
最佳答案
我相信这是 Stanford Parser 的依赖链输出。如果是,那么你应该已经在句子的解析树中有了名词短语(NP 节点)。您可以从解析树中提取最低级别的 NP 节点以获得所需的名词短语。例如,对于句子“今天是 Jan Sangh BJP 的创始人 Mukherjee 博士的殉难。”,解析树将是:
(ROOT
(S
(NP (NNP Today))
(VP (VBZ is)
(NP
(NP (DT the) (NN martyrdom))
(PP (IN of)
(NP
(NP (NNP Dr.) (NNP Mukherjee))
(, ,)
(NP
(NP (NN founder))
(PP (IN of)
(NP (NNP Jan) (NNP Sangh) (NNP BJP))))))))
(. .)))
在这棵树中,包含专有名词 (NNP) 的最低级别 NP 将为您提供最多(所有这些都不是您需要的命名实体)您需要的名词短语。在这种情况下,输出将是:
(NP (NNP Today))
(NP (NNP Dr.) (NNP Mukherjee))
(NP (NNP Jan) (NNP Sangh) (NNP BJP))
关于java - 使用Java组合nn标签形成名词短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12107147/