]> hydra-www.ietfng.org Git - dyna2/commitdiff
added a few examples.
authortimv <tim.f.vieira@gmail.com>
Wed, 5 Jun 2013 16:25:56 +0000 (12:25 -0400)
committertimv <tim.f.vieira@gmail.com>
Wed, 5 Jun 2013 16:25:56 +0000 (12:25 -0400)
examples/errors.dyna [new file with mode: 0644]
examples/geom.dyna [new file with mode: 0644]
examples/lang-model.dyna [new file with mode: 0644]
src/Dyna/Backend/Python/interpreter.py

diff --git a/examples/errors.dyna b/examples/errors.dyna
new file mode 100644 (file)
index 0000000..3d06b01
--- /dev/null
@@ -0,0 +1,10 @@
+
+b := 0.
+
+a += 1/b.
+
+c += "" + b.
+
+
+d += null.
+d += 1.
diff --git a/examples/geom.dyna b/examples/geom.dyna
new file mode 100644 (file)
index 0000000..4e7c057
--- /dev/null
@@ -0,0 +1,2 @@
+a += 1.
+a += a/2.
diff --git a/examples/lang-model.dyna b/examples/lang-model.dyna
new file mode 100644 (file)
index 0000000..0d7f091
--- /dev/null
@@ -0,0 +1,42 @@
+% Find the most frequent word type and it's frequency in a collection of tokens.
+
+tokens(W) += 1 for word(W,I).   % tokens of word W
+
+ntokens += tokens(W).           % total tokens.
+ntypes += 1 for tokens(W) > 0.  % number of word types
+
+maxtokens max= tokens(W).       % number of tokens for the most frequent type
+
+mostfreq max= &pair(tokens(W), W).
+
+mostfreq_type := pair(Cnt, W) is mostfreq, W.
+mostfreq_cnt := pair(Cnt, W) is mostfreq, Cnt.
+
+%%%
+% Just for fun, you can also aggregate types as a set (you can't use sets as a
+% value yet, however)
+types set= word(W,_), W.
+
+
+%%%%
+% Even more fun! bigram language model.
+
+% bigram counts
+bigram(U,V) += 1 for word(U,T), word(V,T+1).
+
+% conditional probably p(U|V)
+p_cond(U,V) := (bigram(U,V) + smoothing) / (tokens(V) + smoothing).
+smoothing := 0.0.
+
+% probability of enture word sequence
+prob_seq *= word(U, T), word(V,T+1), p_cond(U,V).
+
+
+% Data!
+word("a",0).
+word("a",1).
+word("b",2).
+word("c",3).
+word("c",4).
+word("c",5).
+word("d",6).
index 87ccf80e9f3144d7212085bdd2ab7127a1caaf0e..0694eae3e0775ecbd23064c571bd8bb4a9ebc8cc 100644 (file)
@@ -300,7 +300,7 @@ class Chart(object):
         else:
             for term in candidates:
                 if term.value == val:
-                    yield term, term.args + (term.value,)
+                    yield term, term.args + (term.value,)   # TODO: change codegen to avoid addition..
 
     def lookup(self, args):
         "find index for these args"