]> hydra-www.ietfng.org Git - dyna2/commitdiff
()
authorTim Vieira <tim.f.vieira@gmail.com>
Wed, 19 Jun 2013 00:29:36 +0000 (20:29 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Wed, 19 Jun 2013 00:29:36 +0000 (20:29 -0400)
examples/ptb.dyna
test/repl/load.bash

index b4877f575d1def475af574e12b785e9b5e52cd3d..918bd6dcbbca85988f5745c2f7813bd89eda18b6 100644 (file)
@@ -115,6 +115,17 @@ sym(&t(A,B,C)) := needs(&t(A,B,C)), A.
 rules(&t(X,Y)) := needs(&t(X,Y)), &r(X, sym(Y)).
 rules(&t(X,Y,Z)) := needs(&t(X,Y,Z)), needs(Z), &r(X, sym(Y), sym(Z)).
 
+% count the number of words in a subtree
+numwords(X) := 1.
+numwords(t(X,Y)) := numwords(Y).
+numwords(t(X,Y,Z)) := numwords(Y) + numwords(Z).
+
+% extract word and it's position in tree
+word(0, X) := X.
+word(I, t(X,Y)) := word(I, Y).
+word(I, t(X,Y,Z)) := I < numwords(Y), word(I, Y).
+word(I, t(X,Y,Z)) := I >= numwords(Y), word(I-numwords(Y), Z).
+
 % unnormalized
 c(X,Y) += r(X,Y) is rules(&t(X1,Y1)), 1.
 c(X,Y,Z) += r(X,Y,Z) is rules(&t(X1,Y1,Z1)), 1.
index 14f56fe0ec3745080179fb1a59ea6e75bac5e7e5..293fadea534968d4ce061ad6e050e09c4b7fd781 100755 (executable)
@@ -7,4 +7,4 @@
          'token = matrix("test/repl/english.sen", astype=str)' \
          'tree = sexpr("test/repl/english.par")' \
   --post 'dump_chart()' \
-  "$@"
\ No newline at end of file
+  "$@"