From e928c660ea6c1b492e6715459a45ffe01ee37736 Mon Sep 17 00:00:00 2001 From: Tim Vieira Date: Tue, 18 Jun 2013 20:29:36 -0400 Subject: [PATCH] () --- examples/ptb.dyna | 11 +++++++++++ test/repl/load.bash | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/ptb.dyna b/examples/ptb.dyna index b4877f5..918bd6d 100644 --- a/examples/ptb.dyna +++ b/examples/ptb.dyna @@ -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. diff --git a/test/repl/load.bash b/test/repl/load.bash index 14f56fe..293fade 100755 --- a/test/repl/load.bash +++ b/test/repl/load.bash @@ -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 + "$@" -- 2.50.1