From 30e0795d9417aed0156940dfbf6b9ad41a61940b Mon Sep 17 00:00:00 2001 From: timv Date: Sun, 16 Jun 2013 22:50:04 -0400 Subject: [PATCH] added repl data loading example. --- src/Dyna/Backend/Python/repl.py | 1 - test/repl/load.bash | 10 ++++++++++ test/repl/load.dyna | 21 +++++++++++++++++++++ test/repl/papa.gr | 14 ++++++++++++++ test/repl/sentences.txt | 3 +++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 test/repl/load.bash create mode 100644 test/repl/load.dyna create mode 100644 test/repl/papa.gr create mode 100644 test/repl/sentences.txt diff --git a/src/Dyna/Backend/Python/repl.py b/src/Dyna/Backend/Python/repl.py index ab59502..fa963f3 100644 --- a/src/Dyna/Backend/Python/repl.py +++ b/src/Dyna/Backend/Python/repl.py @@ -139,7 +139,6 @@ class REPL(cmd.Cmd, object): def _load(self, cmd): import re - print 'cmd:', repr(cmd) [(name, module, args)] = re.findall('^([a-z][a-zA-Z_0-9]*) = ([a-z][a-zA-Z_0-9]*)\((.*)\)', cmd) m = __import__(module) diff --git a/test/repl/load.bash b/test/repl/load.bash new file mode 100755 index 0000000..7cb0e8b --- /dev/null +++ b/test/repl/load.bash @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# The example shows off some of the REPL's data loading commands. + +echo ' +load rules_tsv = tsv("test/repl/papa.gr"). +load token = loadmat("test/repl/sentences.txt", astype=str). +' |./dyna test/repl/load.dyna -i + +#load tree_sexpr = sexpr("trees.txt", binarize=True) diff --git a/test/repl/load.dyna b/test/repl/load.dyna new file mode 100644 index 0000000..4bc7d70 --- /dev/null +++ b/test/repl/load.dyna @@ -0,0 +1,21 @@ +% accompanies load.bash + +% binary rules +rewrite(X, Y, Z) := + rules_tsv(Linenum, Cost, X, R), + List is pycall("split", R, "\\s+"), + cons(Y, &cons(Z, &nil)) is List, + pycall("float", Cost). + +% load unary rules +rewrite(X, Y) := + rules_tsv(Linenum, Cost, X, R), + cons(Y, &nil) is pycall("split", R, "\\s+"), + pycall("float", Cost). + +phrase(S,X,I,K) += phrase(S,Y,I,K) + rewrite(X,Y). +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)). diff --git a/test/repl/papa.gr b/test/repl/papa.gr new file mode 100644 index 0000000..1ab3e6b --- /dev/null +++ b/test/repl/papa.gr @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..197e3ce --- /dev/null +++ b/test/repl/sentences.txt @@ -0,0 +1,3 @@ +Papa ate the caviar . + +Papa ate the caviar with the spoon . -- 2.50.1