From 86d77d779fdc21fd0af2f1482bdae57c5cc162c0 Mon Sep 17 00:00:00 2001 From: grammarware Date: Wed, 9 May 2012 08:50:31 +0000 Subject: [PATCH] added xbgf:split, a reverse of xbgf:unite git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1195 ab42f6e0-554d-0410-b580-99e487e6eeb2 --- shared/prolog/readXbgf.pro | 10 +++++ shared/prolog/xbgf1.pro | 45 +++++++++++++++++++ shared/xsd/xbgf.xsd | 16 +++++++ .../transformation/xbgf/tests/split1.baseline | 24 ++++++++++ topics/transformation/xbgf/tests/split1.bgf | 24 ++++++++++ topics/transformation/xbgf/tests/split1.xbgf | 13 ++++++ .../transformation/xbgf/tests/split2.baseline | 24 ++++++++++ topics/transformation/xbgf/tests/split2.bgf | 24 ++++++++++ topics/transformation/xbgf/tests/split2.xbgf | 13 ++++++ .../transformation/xbgf/tests/split3.baseline | 24 ++++++++++ topics/transformation/xbgf/tests/split3.bgf | 24 ++++++++++ topics/transformation/xbgf/tests/split3.xbgf | 14 ++++++ .../transformation/xbgf/tests/split4.baseline | 24 ++++++++++ topics/transformation/xbgf/tests/split4.bgf | 24 ++++++++++ topics/transformation/xbgf/tests/split4.xbgf | 14 ++++++ .../xbgf/tests/unite_eq.baseline | 17 ++++--- topics/transformation/xbgf/tests/unite_eq.bgf | 25 ++++++----- .../transformation/xbgf/tests/unite_eq.xbgf | 13 +++--- .../xbgf/tests/unite_normal.baseline | 38 ++++++++-------- .../xbgf/tests/unite_normal.bgf | 38 ++++++++-------- .../xbgf/tests/unite_normal.xbgf | 14 +++--- 21 files changed, 388 insertions(+), 74 deletions(-) create mode 100644 topics/transformation/xbgf/tests/split1.baseline create mode 100644 topics/transformation/xbgf/tests/split1.bgf create mode 100644 topics/transformation/xbgf/tests/split1.xbgf create mode 100644 topics/transformation/xbgf/tests/split2.baseline create mode 100644 topics/transformation/xbgf/tests/split2.bgf create mode 100644 topics/transformation/xbgf/tests/split2.xbgf create mode 100644 topics/transformation/xbgf/tests/split3.baseline create mode 100644 topics/transformation/xbgf/tests/split3.bgf create mode 100644 topics/transformation/xbgf/tests/split3.xbgf create mode 100644 topics/transformation/xbgf/tests/split4.baseline create mode 100644 topics/transformation/xbgf/tests/split4.bgf create mode 100644 topics/transformation/xbgf/tests/split4.xbgf diff --git a/shared/prolog/readXbgf.pro b/shared/prolog/readXbgf.pro index 0abfcea7..f2e0b83c 100644 --- a/shared/prolog/readXbgf.pro +++ b/shared/prolog/readXbgf.pro @@ -318,6 +318,16 @@ xml2xbgf(T,detour(P2)) child(name(bgf:production),T,P1), xmlToP(P1,P2). +xml2xbgf(T,split(N,Ps2,Ls2)) + :- + self(name(xbgf:split),T), + child(name(nonterminal),T,Nonterminal), + children(name(bgf:production),T,Ps1), + children(name(label),T,Ls1), + content(Nonterminal,N), + maplist(xmlToP,Ps1,Ps2), + maplist(content,Ls1,Ls2). + xml2xbgf(T,stripL(L)) :- self(name(xbgf:strip),T), diff --git a/shared/prolog/xbgf1.pro b/shared/prolog/xbgf1.pro index 71d2f066..b39914c3 100644 --- a/shared/prolog/xbgf1.pro +++ b/shared/prolog/xbgf1.pro @@ -1294,6 +1294,51 @@ detour(P1,g(Rs,Ps1),g(Rs,Ps2)) [N]), append(Ps1,[P1],Ps2). +% +% p([l(split)], f, ','([n(n), n(n)])) +% +% Nonterminal splitting, a form of "de-unification" +% +% TODO: works only on labels, should eventually be implemented for all kinds of scopes/contexts +% +split(N1,Ps0,Ls1,g(Rs,Ps1),g(Rs,Ps2)) + :- + allNs(g(Rs,Ps1),Ns1), + definedNs(g([],Ps0),[N0]), + require( + (member(N1,Ns1)), + 'Source name ~q for splitting must not be fresh.', + [N1]), + require( + (\+ member(N0,Ns1)), + 'Target name ~q for splitting must be fresh.', + [N0]), + changelhs(N0,N1,Ps0,Ps0p), + removeprods(Ps0p,g(Rs,Ps1),g(Rs,Ps3)), + import(Ps0,g(Rs,Ps3),g(Rs,Ps4)), + replaceLs(n(N1),n(N0),Ls1,g(Rs,Ps4),g(Rs,Ps2)). + +changelhs(_,_,[],[]). +changelhs(N1,N2,[P1|Ps1],[P2|Ps2]) + :- + P1 = p(L,N3,X), + ( + N1 == N3, + P2 = p(L,N2,X) + ; + P2 = p(L,N3,X) + ), + changelhs(N1,N2,Ps1,Ps2). + +removeprods([],G1,G1). +removeprods([P0|Ps0],g(Rs,Ps1),g(Rs,Ps3)) :- removeV(P0,g(Rs,Ps1),g(Rs,Ps2)), removeprods(Ps0,g(Rs,Ps2),g(Rs,Ps3)). + +replaceLs(_,_,[],G1,G1). +replaceLs(X1,X2,[L1|Ls],g(Rs,Ps1),g(Rs,Ps3)) + :- + replaceL(X1,X2,L1,g(Rs,Ps1),g(Rs,Ps2)), + replaceLs(X1,X2,Ls,g(Rs,Ps2),g(Rs,Ps3)). + % % p([l(stripL)], f, n(l)) % p([l(stripLs)], f, true) diff --git a/shared/xsd/xbgf.xsd b/shared/xsd/xbgf.xsd index ba2f17a8..c0f5aba1 100644 --- a/shared/xsd/xbgf.xsd +++ b/shared/xsd/xbgf.xsd @@ -167,6 +167,7 @@ + @@ -1162,6 +1163,21 @@ + + + + The reverse of unite. + + + + + + + + + + + diff --git a/topics/transformation/xbgf/tests/split1.baseline b/topics/transformation/xbgf/tests/split1.baseline new file mode 100644 index 00000000..c6d8692a --- /dev/null +++ b/topics/transformation/xbgf/tests/split1.baseline @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + foo + + b + + + + + bar + + d + + + diff --git a/topics/transformation/xbgf/tests/split1.bgf b/topics/transformation/xbgf/tests/split1.bgf new file mode 100644 index 00000000..1055d83c --- /dev/null +++ b/topics/transformation/xbgf/tests/split1.bgf @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + foo + + b + + + + + foo + + d + + + diff --git a/topics/transformation/xbgf/tests/split1.xbgf b/topics/transformation/xbgf/tests/split1.xbgf new file mode 100644 index 00000000..654fc87d --- /dev/null +++ b/topics/transformation/xbgf/tests/split1.xbgf @@ -0,0 +1,13 @@ + + + + foo + + + bar + + d + + + + diff --git a/topics/transformation/xbgf/tests/split2.baseline b/topics/transformation/xbgf/tests/split2.baseline new file mode 100644 index 00000000..4720b147 --- /dev/null +++ b/topics/transformation/xbgf/tests/split2.baseline @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + foo + + b + + + + + bar + + foo + + + diff --git a/topics/transformation/xbgf/tests/split2.bgf b/topics/transformation/xbgf/tests/split2.bgf new file mode 100644 index 00000000..74270c56 --- /dev/null +++ b/topics/transformation/xbgf/tests/split2.bgf @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + foo + + b + + + + + foo + + foo + + + diff --git a/topics/transformation/xbgf/tests/split2.xbgf b/topics/transformation/xbgf/tests/split2.xbgf new file mode 100644 index 00000000..7fb2c0c0 --- /dev/null +++ b/topics/transformation/xbgf/tests/split2.xbgf @@ -0,0 +1,13 @@ + + + + foo + + + bar + + foo + + + + diff --git a/topics/transformation/xbgf/tests/split3.baseline b/topics/transformation/xbgf/tests/split3.baseline new file mode 100644 index 00000000..c0c8d007 --- /dev/null +++ b/topics/transformation/xbgf/tests/split3.baseline @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + wez + + bar + + + + + bar + + foo + + + diff --git a/topics/transformation/xbgf/tests/split3.bgf b/topics/transformation/xbgf/tests/split3.bgf new file mode 100644 index 00000000..18ea3220 --- /dev/null +++ b/topics/transformation/xbgf/tests/split3.bgf @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + wez + + foo + + + + + foo + + foo + + + diff --git a/topics/transformation/xbgf/tests/split3.xbgf b/topics/transformation/xbgf/tests/split3.xbgf new file mode 100644 index 00000000..b44f23ae --- /dev/null +++ b/topics/transformation/xbgf/tests/split3.xbgf @@ -0,0 +1,14 @@ + + + + foo + + + bar + + foo + + + + + diff --git a/topics/transformation/xbgf/tests/split4.baseline b/topics/transformation/xbgf/tests/split4.baseline new file mode 100644 index 00000000..cec0952f --- /dev/null +++ b/topics/transformation/xbgf/tests/split4.baseline @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + foo + + bar + + + + + bar + + foo + + + diff --git a/topics/transformation/xbgf/tests/split4.bgf b/topics/transformation/xbgf/tests/split4.bgf new file mode 100644 index 00000000..e096fb87 --- /dev/null +++ b/topics/transformation/xbgf/tests/split4.bgf @@ -0,0 +1,24 @@ + + + + + foo + + a + + + + + foo + + foo + + + + + foo + + foo + + + diff --git a/topics/transformation/xbgf/tests/split4.xbgf b/topics/transformation/xbgf/tests/split4.xbgf new file mode 100644 index 00000000..b44f23ae --- /dev/null +++ b/topics/transformation/xbgf/tests/split4.xbgf @@ -0,0 +1,14 @@ + + + + foo + + + bar + + foo + + + + + diff --git a/topics/transformation/xbgf/tests/unite_eq.baseline b/topics/transformation/xbgf/tests/unite_eq.baseline index 90169a4d..928f0927 100644 --- a/topics/transformation/xbgf/tests/unite_eq.baseline +++ b/topics/transformation/xbgf/tests/unite_eq.baseline @@ -1,10 +1,9 @@ - - - - a - - - - - \ No newline at end of file + + + a + + + + + diff --git a/topics/transformation/xbgf/tests/unite_eq.bgf b/topics/transformation/xbgf/tests/unite_eq.bgf index 7d8750c0..bb7365c5 100644 --- a/topics/transformation/xbgf/tests/unite_eq.bgf +++ b/topics/transformation/xbgf/tests/unite_eq.bgf @@ -1,14 +1,15 @@ + - - a - - - - - - b - - - - + + a + + + + + + b + + + + diff --git a/topics/transformation/xbgf/tests/unite_eq.xbgf b/topics/transformation/xbgf/tests/unite_eq.xbgf index 29062fdd..0cca42d1 100644 --- a/topics/transformation/xbgf/tests/unite_eq.xbgf +++ b/topics/transformation/xbgf/tests/unite_eq.xbgf @@ -1,8 +1,7 @@ - - - b - a - + + + + b + a + diff --git a/topics/transformation/xbgf/tests/unite_normal.baseline b/topics/transformation/xbgf/tests/unite_normal.baseline index c7470897..9c22b8b0 100644 --- a/topics/transformation/xbgf/tests/unite_normal.baseline +++ b/topics/transformation/xbgf/tests/unite_normal.baseline @@ -1,21 +1,21 @@ - - foo - - a - - - - foo - - b - - - - foo - - d - - - \ No newline at end of file + + foo + + a + + + + foo + + b + + + + foo + + d + + + diff --git a/topics/transformation/xbgf/tests/unite_normal.bgf b/topics/transformation/xbgf/tests/unite_normal.bgf index d81ee594..8bfe0335 100644 --- a/topics/transformation/xbgf/tests/unite_normal.bgf +++ b/topics/transformation/xbgf/tests/unite_normal.bgf @@ -1,21 +1,21 @@ - - foo - - a - - - - foo - - b - - - - bar - - d - - - + + foo + + a + + + + foo + + b + + + + bar + + d + + + diff --git a/topics/transformation/xbgf/tests/unite_normal.xbgf b/topics/transformation/xbgf/tests/unite_normal.xbgf index 192779ef..6d9961d8 100644 --- a/topics/transformation/xbgf/tests/unite_normal.xbgf +++ b/topics/transformation/xbgf/tests/unite_normal.xbgf @@ -1,9 +1,7 @@ - - - - bar - foo - + + + + bar + foo +