I need to find a way to Transfer a parse tree in to another with different order. It is for machine translation project with two languages with SVO and SOV architecture.
t1 = s(np(n(he)), vp( v(went), np(n(home))))
and I want it to be
t2 = s(np(n(he)), vp( np(n(home)), v(went)))
according to a rule that represent t1 represent the SVO language and t2 represent the SOV language architecture.
And the rule set should be applicable for complex sentences with adjectives and adverbs.
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)))
Any comment would be useful
thanks Mathee
the easier way it's the declaration of any transformation to be done, via pattern matching, and a generic rule working recursively on any pattern:
% specialize for VP
transfer(vp(X,Y), vp(V,U)) :- !,
transfer(X,U), transfer(Y,V).
% generic rule, work out arguments
transfer(X, Y) :-
X =.. [F|Xs],
maplist(transfer, Xs, Ys),
Y =.. [F|Ys].
If you need your program to be able to work bidirectionally, check the variables instantiation in generic rule
transfer(X, Y) :-
nonvar(X), !, X =.. [F|Xs],
maplist(transfer, Xs, Ys),
Y =.. [F|Ys].
transfer(X, Y) :-
Y =.. [F|Ys],
maplist(transfer, Xs, Ys),
X =.. [F|Xs].
yields (for instance)
?- transfer(s(np(n(he)), vp( v(went), np(adj(his), n(home)))),T2).
T2 = s(np(n(he)), vp(np(adj(his), n(home)), v(went))).
?- transfer(T1,$T2).
T1 = s(np(n(he)), vp(v(went), np(adj(his), n(home)))).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With