From: timv Date: Wed, 5 Jun 2013 16:25:56 +0000 (-0400) Subject: added a few examples. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=fa2d1f0c386a7c5ad10f528ff14e570eaf447110;p=dyna2 added a few examples. --- diff --git a/examples/errors.dyna b/examples/errors.dyna new file mode 100644 index 0000000..3d06b01 --- /dev/null +++ b/examples/errors.dyna @@ -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 index 0000000..4e7c057 --- /dev/null +++ b/examples/geom.dyna @@ -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 index 0000000..0d7f091 --- /dev/null +++ b/examples/lang-model.dyna @@ -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). diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index 87ccf80..0694eae 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -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"