我设法为给定的句子构建了解析树,这里的句子是:"那个人回家了."
T = s(np(det(the), n(man)), vp(v(went), np(n(home))))
Run Code Online (Sandbox Code Playgroud)
1)如何使用短语/ 2?
如何使用prolog翻译逻辑语言中的句子? - 类似于我的需要,但它的解决方案对我不起作用.
2)我想用语法模式映射它并得到单词标签.
Det=the,N(Subject)=man,V=went,N(Object)=home
有没有办法用给定的树集结构映射这个树并识别语法.如何使用解析树来识别主语,动词,宾语,语法模式以及生成目标语言句子.
稍后编辑..我试过这个代码,它给出了相当大的答案.对此代码的任何建议.
sent("(s(np(n(man))) (vp(v(went)) (np(n(home)))))").
whitespace --> [X], { char_type(X, white) ; char_type(X, space) }, whitespace.
whitespace --> [].
char(C) --> [C], { char_type(C, graph), \+ memberchk(C, "()") }.
chars([C|Rest]) --> char(C), chars(Rest).
chars([C]) --> char(C).
term(T) --> chars(C), { atom_chars(T, C) }.
term(L) --> list(L).
list(T) --> "(", terms(T), ")".
terms([]) --> [].
terms([T|Terms]) --> term(T), whitespace, !, terms(Terms). …Run Code Online (Sandbox Code Playgroud) 我需要找到一种方法将一个解析树转移到另一个不同顺序的树.它适用于具有SVO和SOV架构的两种语言的机器翻译项目.
t1 = s(np(n(he)), vp( v(went), np(n(home))))
Run Code Online (Sandbox Code Playgroud)
我想要它
t2 = s(np(n(he)), vp( np(n(home)), v(went)))
Run Code Online (Sandbox Code Playgroud)
根据表示t1的规则表示SVO语言,t2表示SOV语言体系结构.
规则集应适用于具有形容词和副词的复杂句子.
t1 = s(np(n(he)), vp( v(went), np(adj(his), n(home))))
t2 = s(np(n(he)), vp( np(adj(his), n(home)), v(went)))
Run Code Online (Sandbox Code Playgroud)
任何评论都会有用
谢谢Mathee