]> hydra-www.ietfng.org Git - dyna2/commitdiff
added repl data loading example.
authortimv <tim.f.vieira@gmail.com>
Mon, 17 Jun 2013 02:50:04 +0000 (22:50 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Tue, 18 Jun 2013 01:24:27 +0000 (21:24 -0400)
src/Dyna/Backend/Python/repl.py
test/repl/load.bash [new file with mode: 0755]
test/repl/load.dyna [new file with mode: 0644]
test/repl/papa.gr [new file with mode: 0644]
test/repl/sentences.txt [new file with mode: 0644]

index ab595025e2a56e6bfdd7767105e863ff49a0024b..fa963f369d4f89aabd4aae6bab1684b7c582be08 100644 (file)
@@ -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 (executable)
index 0000000..7cb0e8b
--- /dev/null
@@ -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 (file)
index 0000000..4bc7d70
--- /dev/null
@@ -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 (file)
index 0000000..1ab3e6b
--- /dev/null
@@ -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 (file)
index 0000000..197e3ce
--- /dev/null
@@ -0,0 +1,3 @@
+Papa ate the caviar .
+
+Papa ate the caviar with the spoon .