From f350006c6c097b381629ddc98b70c53fc06d9f98 Mon Sep 17 00:00:00 2001 From: Tim Vieira Date: Tue, 18 Jun 2013 10:38:56 -0400 Subject: [PATCH] test/repl/load uses data --- .gitignore | 2 + src/Dyna/Backend/Python/load/sexpr.py | 9 ++- test/repl/english.gr | 98 +++++++++++++++++++++++++++ test/repl/english.par | 22 ++++++ test/repl/english.sen | 22 ++++++ test/repl/load.bash | 9 +-- test/repl/load.dyna | 2 +- test/repl/papa.gr | 14 ---- test/repl/sentences.txt | 3 - 9 files changed, 156 insertions(+), 25 deletions(-) create mode 100644 test/repl/english.gr create mode 100644 test/repl/english.par create mode 100644 test/repl/english.sen delete mode 100644 test/repl/papa.gr delete mode 100644 test/repl/sentences.txt diff --git a/.gitignore b/.gitignore index 9e0a918..be7310c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,11 +2,13 @@ *.o *.pyc *.swp +*.pyc dist/ examples/*.d examples/*.hist examples/*.plan +examples/*.planc examples/*.plan.py examples/*.out diff --git a/src/Dyna/Backend/Python/load/sexpr.py b/src/Dyna/Backend/Python/load/sexpr.py index 453bf77..a4e0d66 100644 --- a/src/Dyna/Backend/Python/load/sexpr.py +++ b/src/Dyna/Backend/Python/load/sexpr.py @@ -33,8 +33,11 @@ class sexpr(object): if isinstance(xs, basestring): return xs else: - assert len(xs) > 1 - if len(xs) == 2: + if len(xs) == 1: +# [sym] = map(t, xs) +# return node(sym, ()) + return t(xs[0]) # doesn't have a label. + elif len(xs) == 2: [sym, a] = map(t, xs) return node(sym, a) elif len(xs) == 3: @@ -47,7 +50,7 @@ class sexpr(object): contents = file(filename).read() - for i, [x] in enumerate(parse_sexpr(contents)): + for i, x in enumerate(parse_sexpr(contents)): interp.emit(obj(i), t(x), ruleix=None, diff --git a/test/repl/english.gr b/test/repl/english.gr new file mode 100644 index 0000000..b2088e2 --- /dev/null +++ b/test/repl/english.gr @@ -0,0 +1,98 @@ +0 S NP VP +1.58 ROOT S . +1.58 ROOT S ! +1.58 ROOT VP ! +3.81 VP V +3.81 VP V NP +1.49 VP V VP +3.81 VP V NP VP +3.81 VP V SBAR +3.81 VP V N +3.81 VP V Adj +0 SBAR that S +3.7 NP Det N +3.7 N Adj N +0 PP P NP +3.81 VP VP PP +3.7 N N PP +3.81 VP Modal VP +3 Modal will +3 Modal would +3 Modal should +3 Modal could +3 Modal can +3 Modal might +3 Modal may +3 Modal must +4.09 V V -ed +5.09 V V -ing +5.09 V V -s +5.09 V V -0 +5.09 V to V +4.09 V have +4.09 V had +5.09 V having +5.09 V has +5.09 V be +5.09 V was +5.09 V were +5.09 V been +5.09 V being +5.09 V is +5.09 V are +5.09 V go +5.09 V sleep +5.09 V kiss +5.09 V love +5.09 V spoon +4.09 V eat +3.5 V want +5.09 V say +4.09 V understand +4.09 V entice +3.7 NP Papa +3.7 NP George +3.7 NP Laura +3.7 NP her +3.7 NP she +3.7 NP him +3.7 NP he +2.7 NP it +3.7 NP they +3.7 NP them +3.7 N N -s +3.7 N bonbon +3.7 N spoon +3.7 N president +3.7 N pickle +3.7 N sandwich +3.7 N floor +3.7 N chief of staff +3.7 N chiefs of staff +3.7 N man +3.7 N woman +4.09 Det a +4.09 Det all +4.09 Det every +4.09 Det each +4.09 Det two +3.09 Det some +3.09 Det the +3.09 Det his +3.09 Det her +3.09 Det its +3.09 Det their +2.81 Adj fine +2.81 Adj blue +2.81 Adj delicious +2.81 Adj perplexed +2.81 Adj pickled +2.81 Adj very Adj +2.32 P with +2.32 P on +2.32 P onto +2.32 P under +2.32 P in +2.81 Adj Adj and Adj +3.7 NP NP and NP +3.81 VP VP and VP diff --git a/test/repl/english.par b/test/repl/english.par new file mode 100644 index 0000000..6bdac28 --- /dev/null +++ b/test/repl/english.par @@ -0,0 +1,22 @@ +(ROOT (S (NP George) (VP (V (V love) -s) (NP Laura))) .) +(ROOT (S (NP he) (VP (V (V love) -s) (NP her))) .) +(ROOT (S (NP him) (VP (V (V love) -s) (NP she))) .) +(ROOT (S (NP Papa) (VP (VP (V (V sleep) -s)) (PP (P with) (NP (Det a) (N spoon))))) .) +(ROOT (S (NP Papa) (VP (VP (V (V eat) -ed)) (PP (P with) (NP (Det a) (N spoon))))) .) +(ROOT (S (NP Papa) (VP (V (V sleep) -s) (NP (Det every) (N (N bonbon) (PP (P with) (NP (Det a) (N spoon))))))) .) +(ROOT (S (NP Papa) (VP (V (V eat) -ed) (NP (Det every) (N (N bonbon) (PP (P with) (NP (Det a) (N spoon))))))) .) +(ROOT (VP (V have) (NP (Det a) (N bonbon))) !) +(ROOT (S (NP (Det a) (N (N bonbon) (PP (P on) (NP (Det the) (N spoon))))) (VP (V (V entice) -s))) .) +(ROOT (S (NP (Det a) (N (N bonbon) (PP (P on) (NP (Det the) (N spoon))))) (VP (V (V entice) -0))) .) +(ROOT (S (NP (Det the) (N (N (N bonbon) -s) (PP (P on) (NP (Det the) (N spoon))))) (VP (V (V entice) -0))) .) +(ROOT (S (NP George) (VP (V (V kiss) -ed) (NP (Det every) (N chief of staff)))) .) +(ROOT (S (NP Laura) (VP (V (V say) -s) (SBAR that (S (NP George) (VP (VP (Modal might) (VP (V sleep))) (PP (P on) (NP (Det the) (N floor)))))))) !) +(ROOT (S (NP (Det the) (N (Adj perplexed) (N president))) (VP (V (V eat) -ed) (NP (Det a) (N pickle)))) .) +(ROOT (S (NP Papa) (VP (V is) (Adj perplexed))) .) +(ROOT (S (NP Papa) (VP (V is) (N chief of staff))) .) +(ROOT (S (NP Papa) (VP (V (V want) -ed) (NP (Det a) (N sandwich)))) .) +(ROOT (S (NP Papa) (VP (V (V want) -ed) (VP (V to (V eat)) (NP (Det a) (N sandwich))))) .) +(ROOT (S (NP Papa) (VP (V (V want) -ed) (NP George) (VP (V to (V eat)) (NP (Det a) (N pickle))))) .) +(ROOT (S (NP Papa) (VP (Modal would) (VP (V have) (VP (V (V eat) -ed) (NP (Det his) (N (N sandwich) -s)))))) .) +(ROOT (S (NP (Det every) (N sandwich)) (VP (V was) (VP (V (V go) -ing) (VP (V to (V have)) (VP (V been) (Adj delicious)))))) .) +(ROOT (S (NP (NP (Det the) (N (Adj (Adj fine) and (Adj blue)) (N woman))) and (NP (Det every) (N man))) (VP (VP (Modal must) (VP (V have) (VP (VP (V (V eat) -ed) (NP (Det two) (N (N sandwich) -s))) and (VP (V (V sleep) -ed))))) (PP (P on) (NP (Det the) (N floor))))) .) diff --git a/test/repl/english.sen b/test/repl/english.sen new file mode 100644 index 0000000..edb7674 --- /dev/null +++ b/test/repl/english.sen @@ -0,0 +1,22 @@ +George love -s Laura . +he love -s her . +him love -s she . +Papa sleep -s with a spoon . +Papa eat -ed with a spoon . +Papa sleep -s every bonbon with a spoon . +Papa eat -ed every bonbon with a spoon . +have a bonbon ! +a bonbon on the spoon entice -s . +a bonbon on the spoon entice -0 . +the bonbon -s on the spoon entice -0 . +George kiss -ed every chief of staff . +Laura say -s that George might sleep on the floor ! +the perplexed president eat -ed a pickle . +Papa is perplexed . +Papa is chief of staff . +Papa want -ed a sandwich . +Papa want -ed to eat a sandwich . +Papa want -ed George to eat a pickle . +Papa would have eat -ed his sandwich -s . +every sandwich was go -ing to have been delicious . +the fine and blue woman and every man must have eat -ed two sandwich -s and sleep -ed on the floor . diff --git a/test/repl/load.bash b/test/repl/load.bash index 02d0cfb..14f56fe 100755 --- a/test/repl/load.bash +++ b/test/repl/load.bash @@ -3,7 +3,8 @@ # The example shows off some of the REPL's data loading commands. ./dyna test/repl/load.dyna \ - --load 'rules_tsv = tsv("test/repl/papa.gr")' \ - 'token = matrix("test/repl/sentences.txt", astype=str)' \ - 'tree = sexpr("test/repl/trees.txt")' \ - --post 'dump_chart()' + --load 'rules_tsv = tsv("test/repl/english.gr")' \ + 'token = matrix("test/repl/english.sen", astype=str)' \ + 'tree = sexpr("test/repl/english.par")' \ + --post 'dump_chart()' \ + "$@" \ No newline at end of file diff --git a/test/repl/load.dyna b/test/repl/load.dyna index 1e41078..240278a 100644 --- a/test/repl/load.dyna +++ b/test/repl/load.dyna @@ -17,4 +17,4 @@ phrase(S,X,I,K) += phrase(S,Y,I,J) + phrase(S,Z,J,K) + rewrite(X,Y,Z). phrase(S,W,I,I+1) += W is token(S,I), 0. sentence_length(S) max= token(S,I), I+1. -goal(S) += phrase(S, "S", 0, sentence_length(S)). +goal(S) += phrase(S, "ROOT", 0, sentence_length(S)). diff --git a/test/repl/papa.gr b/test/repl/papa.gr deleted file mode 100644 index 1ab3e6b..0000000 --- a/test/repl/papa.gr +++ /dev/null @@ -1,14 +0,0 @@ -1 S S . -1 S NP VP -1 NP Det N -1 NP NP PP -1 VP V NP -1 VP VP PP -1 PP P NP -1 NP Papa -1 N caviar -1 N spoon -1 V ate -1 P with -1 Det the -1 Det a diff --git a/test/repl/sentences.txt b/test/repl/sentences.txt deleted file mode 100644 index 197e3ce..0000000 --- a/test/repl/sentences.txt +++ /dev/null @@ -1,3 +0,0 @@ -Papa ate the caviar . - -Papa ate the caviar with the spoon . -- 2.50.1