我有这种格式的Collins解析器的输出:
(TOP~goes~1~1 (S~goes~2~2 (NP~story~2~1 (NPB~story~2~2 The/DT story/NN ) (PP~of~2~1 of/IN (NPB~genes~2~2 tumor-suppressor/JJ genes/NNS ) ) ) (VP~goes~2~1 goes/VBZ (ADVP~back~2~1 back/RB (PP~to~2~1 to/TO (NP~1970s~2~1 (NPB~1970s~2~2 the/DT 1970s/NNS ,/PUNC, ) (SBAR~when~2~1 (WHADVP~when~1~1 when/WRB ) (S~proposed~2~2 (NP~pediatrician~2~1 (NPB~pediatrician~2~2 a/DT pediatrician/NN ) (VP~named~2~1 named/VBN (S~Jr.~1~1 (NPB~Jr.~4~4 Alfred/NNP G./NNP Knudson/NNP Jr./NNP ) ) ) ) (VP~proposed~2~1 proposed/VBD (SBAR~that~2~1 that/DT (S~stemmed~2~2 (NPB~retinoblastoma~1~1 retinoblastoma/NN ) (VP~stemmed~2~1 stemmed/VBD (PP~from~2~1 from/IN (NPB~defects~4~4 two/CD separate/JJ genetic/JJ defects/NNS ./PUNC. ) ) ) ) ) ) ) ) ) ) ) ) ) )
我需要的是这个文本文件的树结构。我实际上需要非终端节点的头字。例如,story
是整个句子的第二个单词。所以,我希望有一棵树,其中(NPB~story~2~2
的首字被确定为(NPB:2
。
有没有什么方法可以解析这个解析树并提取每个节点的子节点?
如果您需要更多信息,在(NP~story~2~1
中,story
是首字母,2
是给定短语的子项数,1
是其中的子项你可以找到这个短语的首字。
谢谢,