diff --git a/examples/lassie/Holmakefile b/examples/lassie/Holmakefile
deleted file mode 100644
index d3c73bab5e..0000000000
--- a/examples/lassie/Holmakefile
+++ /dev/null
@@ -1,7 +0,0 @@
-ANT_INSTALLED = $(which ant)
-
-ifneq "$(ANT_INSTALLED)" ""
-CLINE_OPTIONS = -j1 -r
-INCLUDES = src examples
-
-endif
diff --git a/examples/lassie/examples/Holmakefile b/examples/lassie/examples/Holmakefile
deleted file mode 100644
index 28764c0e3e..0000000000
--- a/examples/lassie/examples/Holmakefile
+++ /dev/null
@@ -1,12 +0,0 @@
-INCLUDES = ../src/
-CLINE_OPTIONS=-j1
-TACTIC_WORLD = ../sempre/classes/interactive/edu/stanford/nlp/sempre/interactive/lassie/TacticWorld.class
-
-all: $(DEFAULT_TARGETS)
-.PHONY: all
-
-caseStudy1EuclidTheory.sml: $(TACTIC_WORLD)
-caseStudy2RealNumsTheory.sml: $(TACTIC_WORLD)
-caseStudy3IntervalLibTheory.sml: $(TACTIC_WORLD)
-caseStudy4NaprochePowersetTheory.sml: $(TACTIC_WORLD)
-gaussTheory.sml: $(TACTIC_WORLD)
diff --git a/examples/lassie/examples/arithTacticsLib.sml b/examples/lassie/examples/arithTacticsLib.sml
deleted file mode 100644
index a558493bbc..0000000000
--- a/examples/lassie/examples/arithTacticsLib.sml
+++ /dev/null
@@ -1,44 +0,0 @@
-structure arithTacticsLib =
-struct
- open LassieLib;
-
- local open arithmeticTheory in end;
- fun fs_all g = let val thms = map (fn (a,th) => th) (DB.theorems "-") in fs thms g end;
- val _ =
- let
- fun jargon () =
- let
- val _ = LassieLib.addCustomTactic fs_all "fs_all";
- val _ =
- map (uncurry def) [
- (`simplify`, `fs [ ]`),
- (`simplify with [ADD_ASSOC]`, `fs [ ADD_ASSOC ]`),
- (`use [ADD_ASSOC] to simplify`, `fs [ ADD_ASSOC ]`),
- (`follows from [ADD_ASSOC]`, `metis_tac [ ADD_ASSOC ]`),
- (`rewrite [ADD_ASSOC]` ,`rw [ADD_ASSOC]`),
- (`[ADD_ASSOC] solves the goal`,
- `all_tac THEN ( fs [ ADD_ASSOC ] THEN NO_TAC) ORELSE (rw [ ADD_ASSOC ] THEN NO_TAC) ORELSE metis_tac [ ADD_ASSOC ]`),
- (‘trivial’, ‘[] solves the goal’),
- (`perform an induction on 't'`, `Induct_on ' t '`),
- (`Induction on 't'`, `Induct_on ' t '`),
- (`perform a case split`, `Cases`),
- (`perform a case split for 't'`, `Cases_on ' t '`),
- (`Complete Induction on 't'`, `completeInduct_on ' t '`),
- (`suppose not`, `spose_not_then assume_tac`),
- (`show 'T' using (gen_tac)` ,`' T ' by gen_tac`),
- (‘show 'T' using [ CONJ_COMM ]’, ‘ ' T ' by ([ CONJ_COMM ] solves the goal)’),
- (‘'T' follows trivially’, ‘show 'T' using (trivial)’),
- (`we further know 'T'`, `' T ' by rw [ ]`),
- (`we can derive 'T' from [ADD_ASSOC]`, `' T ' by rw [ ADD_ASSOC ]`),
- (`thus ADD_ASSOC for 'n'`, `qspec_then ' n ' assume_tac ADD_ASSOC`),
- (‘'T' suffices to show the goal’, ‘'T' suffices_by (fs[])’),
- (`it suffices to show that the arguments are equal`, `AP_TERM_TAC`),
- (`it suffices to show that the functions are equal`, `AP_THM_TAC`),
- (‘cheat and cheat’, ‘cheat THEN cheat’)
- ]
- in () end;
- in
- LassieLib.registerJargon "Arithmetic" (jargon)
- end
-
-end;
diff --git a/examples/lassie/examples/caseStudy1EuclidScript.sml b/examples/lassie/examples/caseStudy1EuclidScript.sml
deleted file mode 100644
index 82ef9cab4e..0000000000
--- a/examples/lassie/examples/caseStudy1EuclidScript.sml
+++ /dev/null
@@ -1,280 +0,0 @@
-(** Taken from the HOL4 distribution (original file: HOL4/examples/euclid.sml **)
-
-(*===========================================================================*)
-(* Euclid's theorem: for every prime, there is another one that is larger. *)
-(* This proof has been excerpted and adapted from John Harrison's proof of *)
-(* a special case (n=4) of Fermat's Last Theorem. *)
-(* *)
-(*===========================================================================*)
-
-(*---------------------------------------------------------------------------*)
-(* First, open required context: the theory of arithmetic. This theory is *)
-(* automatically loaded when HOL starts, but the ML module arithmeticTheory *)
-(* needs to be opened before the definitions and theorems of the theory are *)
-(* available without supplying the "arithmeticTheory." prefix. *)
-(*---------------------------------------------------------------------------*)
-
-open BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic monadsyntax
- boolTheory bossLib arithmeticTheory;
-
-open LassieLib arithTacticsLib;
-
-val _ = new_theory "caseStudy1Euclid";
-
-val _ = LassieLib.loadJargon "Arithmetic";
-(*---------------------------------------------------------------------------*)
-(* Divisibility. *)
-(*---------------------------------------------------------------------------*)
-
-set_fixity "divides" (Infix(NONASSOC, 450));
-
-Definition divides_def:
-(a divides b) = (? x. b = a * x)
-End
-
-
-(*---------------------------------------------------------------------------*)
-(* Primality. *)
-(*---------------------------------------------------------------------------*)
-
-Definition prime_def:
- prime p = (p<>1 /\ !x . x divides p ==> (x=1) \/ (x=p))
-End
-
-(*---------------------------------------------------------------------------*)
-(* A sequence of basic theorems about the "divides" relation. *)
-(*---------------------------------------------------------------------------*)
-
-Theorem DIVIDES_0:
- ! x . x divides 0
-Proof
- LassieLib.nltac `
- [divides_def, MULT_CLAUSES] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES] *)
-QED
-
-Theorem DIVIDES_ZERO:
- ! x . (0 divides x) = (x = 0)
-Proof
- LassieLib.nltac `
- [divides_def, MULT_CLAUSES] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES] *)
-QED
-
-Theorem DIVIDES_ONE:
- ! x . (x divides 1) = (x = 1)
-Proof
- LassieLib.nltac
- `[divides_def, MULT_CLAUSES, MULT_EQ_1] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES,MULT_EQ_1] *)
-QED
-
-Theorem DIVIDES_REFL:
- ! x . x divides x
-Proof
- LassieLib.nltac `
- [divides_def, MULT_CLAUSES] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES] *)
-QED
-
-Theorem DIVIDES_TRANS:
- ! a b c . a divides b /\ b divides c ==> a divides c
-Proof
- LassieLib.nltac `
- [divides_def, MULT_ASSOC] solves the goal.`
- (* metis_tac [divides_def,MULT_ASSOC] *)
-QED
-
-Theorem DIVIDES_ADD:
- ! d a b . d divides a /\ d divides b ==> d divides (a + b)
-Proof
- LassieLib.nltac `
- [divides_def, LEFT_ADD_DISTRIB] solves the goal.`
- (* metis_tac [divides_def, LEFT_ADD_DISTRIB] *)
-QED
-
-Theorem DIVIDES_SUB:
- !d a b . d divides a /\ d divides b ==> d divides (a - b)
-Proof
- LassieLib.nltac `
- [divides_def, LEFT_SUB_DISTRIB] solves the goal.`
- (* metis_tac [divides_def,LEFT_SUB_DISTRIB] *)
-QED
-
-Theorem DIVIDES_ADDL:
- !d a b . d divides a /\ d divides (a + b) ==> d divides b
-Proof
- LassieLib.nltac `
- [ADD_SUB, ADD_SYM, DIVIDES_SUB] solves the goal.`
- (* metis_tac [ADD_SUB,ADD_SYM,DIVIDES_SUB] *)
-QED
-
-Theorem DIVIDES_LMUL:
- !d a x . d divides a ==> d divides (x * a)
-Proof
- LassieLib.nltac `
- [divides_def, MULT_ASSOC, MULT_SYM] solves the goal.`
- (* metis_tac [divides_def,MULT_ASSOC,MULT_SYM] *)
-QED
-
-Theorem DIVIDES_RMUL:
- !d a x . d divides a ==> d divides (a * x)
-Proof
- LassieLib.nltac `
- [MULT_SYM,DIVIDES_LMUL] solves the goal.`
- (* metis_tac [MULT_SYM,DIVIDES_LMUL] *)
-QED
-
-Theorem DIVIDES_LE:
- !m n . m divides n ==> m <= n \/ (n = 0)
-Proof
- LassieLib.nltac ‘
- rewrite [divides_def].
- [] solves the goal.’
- (* rw [divides_def] >> rw[] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Various proofs of the same formula *)
-(*---------------------------------------------------------------------------*)
-val NOT_X_LE = save_thm ("NOT_X_LE", DECIDE ``! x. ~(x < x)``);
-
-Theorem DIVIDES_FACT:
- !m n . 0 < m /\ m <= n ==> m divides (FACT n)
-Proof
- LassieLib.nltac ‘
- rewrite [LESS_EQ_EXISTS].
- perform an induction on 'p'.
- [FACT, NOT_X_LE, num_CASES, DIVIDES_RMUL, DIVIDES_LMUL, DIVIDES_REFL, ADD_CLAUSES]
- solves the goal.’
- (*
- rw [LESS_EQ_EXISTS]
- >> Induct_on `p`
- >> metis_tac [FACT, DECIDE ``!x. ~(x < x)``, num_CASES,
- DIVIDES_RMUL,DIVIDES_LMUL,DIVIDES_REFL,ADD_CLAUSES] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Zero and one are not prime, but two is. All primes are positive. *)
-(*---------------------------------------------------------------------------*)
-
-Theorem NOT_PRIME_0:
- ~prime 0
-Proof
- LassieLib.nltac `rewrite [prime_def, DIVIDES_0].`
- (* rw [prime_def,DIVIDES_0] *)
-QED
-
-Theorem NOT_PRIME_1:
- ~prime 1
-Proof
- LassieLib.nltac `rewrite [prime_def].`
- (* rw [prime_def] *)
-QED
-
-val two_prime_eqs = curry save_thm "two_prime_eqs" (DECIDE ``~(2=1) /\ ~(2=0) /\ ((x <=2) = (x = 0) \/ (x = 1) \/ (x = 2))``);
-
-Theorem PRIME_2:
- prime 2
-Proof
- LassieLib.nltac `
- rewrite [prime_def].
- [DIVIDES_LE, DIVIDES_ZERO, two_prime_eqs] solves the goal.`
- (* rw [prime_def] >>
- metis_tac [DIVIDES_LE, DIVIDES_ZERO,
- DECIDE``~(2=1) /\ ~(2=0) /\ (x<=2 = (x=0) \/ (x=1) \/ (x=2))``] *)
-QED
-
-Theorem PRIME_POS:
- !p . prime p ==> 0
> rw [NOT_PRIME_0] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Every number has a prime factor, except for 1. The proof proceeds by a *)
-(* "complete" induction on n, and then considers cases on whether n is *)
-(* prime or not. The first case (n is prime) is trivial. In the second case, *)
-(* there must be an "x" that divides n, and x is not 1 or n. By DIVIDES_LE, *)
-(* n=0 or x <= n. If n=0, then 2 is a prime that divides 0. On the other *)
-(* hand, if x <= n, there are two cases: if x ?p . prime p /\ p divides n
-Proof
- LassieLib.nltac ‘
- Complete Induction on 'n'.
- rewrite [].
- perform a case split for 'prime n'.
- Goal 1. [DIVIDES_REFL] solves the goal. End.
- Goal 1.
- show '? x. x divides n and x <> 1 and x <> n' using (follows from [prime_def]).
- [LESS_OR_EQ, PRIME_2, DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0] solves the goal.
- End.’
- (*
- completeInduct_on `n`
- >> rw []
- >> Cases_on `prime n` >|
- [metis_tac [DIVIDES_REFL],
- `?x. x divides n /\ x<>1 /\ x<>n` by metis_tac[prime_def] >>
- metis_tac [LESS_OR_EQ, PRIME_2,
- DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0]] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* In the following proof, metis_tac automatically considers cases on *)
-(* whether n is prime or not. *)
-(*---------------------------------------------------------------------------*)
-
-Theorem PRIME_FACTOR:
- !n . n<>1 ==> ?p . prime p /\ p divides n
-Proof
- LassieLib.nltac ‘
- Complete Induction on 'n'.
- [DIVIDES_REFL,prime_def,LESS_OR_EQ, PRIME_2,
- DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0] solves the goal.’
- (*
- completeInduct_on `n` >>
- metis_tac [DIVIDES_REFL,prime_def,LESS_OR_EQ, PRIME_2,
- DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Every number has a prime greater than it. *)
-(* Proof. *)
-(* Suppose not; then there's an n such that all p greater than n are not *)
-(* prime. Consider FACT(n) + 1: it's not equal to 1, so there's a prime q *)
-(* that divides it. q also divides FACT n because q is less-than-or-equal *)
-(* to n. By DIVIDES_ADDL, this means that q=1. But then q is not prime, *)
-(* which is a contradiction. *)
-(*---------------------------------------------------------------------------*)
-
-val neq_zero = curry save_thm "neq_zero" (DECIDE ``~(x=0) = (0 < x)``);
-
-Theorem EUCLID:
- !n . ?p . n < p /\ prime p
-Proof
- LassieLib.nltac‘
- suppose not. simplify.
- we can derive 'FACT n + 1 <> 1' from [FACT_LESS, neq_zero].
- thus PRIME_FACTOR for 'FACT n + 1'.
- we further know '?q. prime q and q divides (FACT n + 1)'.
- show 'q <= n' using [NOT_LESS_EQUAL].
- show '0 < q' using [PRIME_POS] .
- show 'q divides FACT n' using [DIVIDES_FACT].
- show 'q=1' using [DIVIDES_ADDL, DIVIDES_ONE].
- show 'prime 1' using (simplify).
- [NOT_PRIME_1] solves the goal.’
- (*
- spose_not_then strip_assume_tac
- >> mp_tac (SPEC ``FACT n + 1`` PRIME_FACTOR)
- >> rw [FACT_LESS, DECIDE ``~(x=0) = (0> metis_tac [DIVIDES_FACT, DIVIDES_ADDL, DIVIDES_ONE,
- NOT_PRIME_1, NOT_LESS, PRIME_POS] *)
-QED
-
-val _ = export_theory();
diff --git a/examples/lassie/examples/caseStudy2RealNumsScript.sml b/examples/lassie/examples/caseStudy2RealNumsScript.sml
deleted file mode 100644
index 7cb303b8cc..0000000000
--- a/examples/lassie/examples/caseStudy2RealNumsScript.sml
+++ /dev/null
@@ -1,189 +0,0 @@
-open BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic monadsyntax
- boolTheory bossLib;
-
-open realTheory arithmeticTheory realLib RealArith;
-
-open LassieLib realTacticsLib logicTacticsLib;
-
-val _ = new_theory "caseStudy2RealNums";
-
-val _ = (LassieLib.loadJargon "Reals"; LassieLib.loadJargon "Logic");
-
-Theorem binom1:
- ! (a b:real). (a + b) pow 2 = a pow 2 + 2 * a * b + b pow 2
-Proof
- LassieLib.nltac `
- introduce assumptions.
- rewrite with [POW_2, REAL_LDISTRIB, REAL_RDISTRIB].
- rewrite with [<- REAL_ADD_ASSOC].
- simplify with [REAL_EQ_RADD].
- rewrite with [REAL_ADD_ASSOC].
- simplify with [REAL_EQ_LADD]. trivial.`
- (*
- rpt strip_tac
- \\ once_rewrite_tac [POW_2]
- \\ once_rewrite_tac [REAL_LDISTRIB]
- \\ once_rewrite_tac [REAL_RDISTRIB]
- \\ rewrite_tac [REAL_ADD_ASSOC]
- \\ simp[REAL_EQ_RADD]
- \\ rewrite_tac [GSYM REAL_ADD_ASSOC]
- \\ simp[REAL_EQ_LADD]
- \\ `b * a = a * b` by (fs[REAL_MUL_COMM])
- \\ simp[REAL_DOUBLE, REAL_MUL_ASSOC] *)
-QED
-
-Theorem binom2:
- ! (a b:real). (a - b) pow 2 = a pow 2 - 2 * a * b + b pow 2
-Proof
- LassieLib.nltac `
- introduce assumptions.
- rewrite with [POW_2, real_sub, REAL_LDISTRIB, REAL_RDISTRIB].
- rewrite with [<- REAL_ADD_ASSOC].
- simplify with [REAL_EQ_RADD].
- rewrite once [REAL_NEG_MUL2].
- rewrite with [REAL_ADD_ASSOC].
- simplify with [REAL_EQ_LADD]. trivial.`
- (*
- rpt strip_tac
- \\ once_rewrite_tac [POW_2]
- \\ once_rewrite_tac [real_sub]
- \\ once_rewrite_tac [REAL_LDISTRIB]
- \\ once_rewrite_tac [REAL_RDISTRIB]
- \\ rewrite_tac [REAL_ADD_ASSOC]
- \\ once_rewrite_tac [REAL_NEG_MUL2]
- \\ simp[REAL_EQ_RADD]
- \\ rewrite_tac [GSYM REAL_ADD_ASSOC]
- \\ simp[REAL_EQ_LADD]
- \\ `-b * a = a * -b` by (fs[REAL_MUL_COMM])
- \\ simp[REAL_DOUBLE, GSYM REAL_NEG_LMUL, GSYM REAL_NEG_RMUL, REAL_MUL_ASSOC] *)
-QED
-
-Definition sum_of_cubes_def:
- (sum_of_cubes 0 = 0:real) /\
- (sum_of_cubes (SUC n) = (&(SUC n)) pow 3 + sum_of_cubes n)
-End
-
-Definition sum_def:
- (sum 0 = 0:real) /\
- (sum (SUC n) = (&(SUC n) + sum n))
-End
-
-Theorem closed_form_sum:
- ! n. (sum n = (((&n):real) * (1 + &n)) / 2)
-Proof
- LassieLib.nltac ‘
- induction on 'n'. simplify with [sum_def, REAL_DIV_LZERO, MULT].
- rewrite MULT_SYM for 'n'.
- we show 'SUC n + 1 = SUC (SUC n)' using (simplify).
- rewrite last assumption.
- we show 'SUC (SUC n) * n = n + n + n * n' using (simplify with [MULT]).
- rewrite last assumption.
- we show 'n + n + n * n + 1 = SUC n + n * (n + 1)' using
- (simplify with [ADD1, LEFT_ADD_DISTRIB, MULT_RIGHT_1]).
- rewrite last assumption.
- rewrite with [ADD_ASSOC].
- we show 'SUC n + SUC n = 2 * (SUC n)' using (simplify).
- rewrite last assumption.
- rewrite once [MULT_COMM].
- rewrite with [GSYM REAL_MUL, GSYM REAL_ADD, GSYM REAL_DIV_ADD].
- rewrite with [real_div].
- simplify with [GSYM REAL_MUL_ASSOC, REAL_MUL_RINV].
- simplify with [REAL_MUL_ASSOC].’
- (* Induct_on `n`
- \\ fs[sum_def, REAL_DIV_LZERO]
- \\ pop_assum (fn thm=> once_rewrite_tac [GSYM thm] \\ assume_tac thm)
- \\ fs[MULT]
- \\ qspec_then `n` (fn thm => once_rewrite_tac [thm]) MULT_SYM
- \\ `SUC n + 1 = SUC (SUC n)`
- by (pop_assum kall_tac \\ Induct_on `n` \\ fs[])
- \\ qpat_x_assum `SUC n + 1 = _` (fn thm => once_rewrite_tac [thm])
- \\ `SUC (SUC n) * n = n + n + n * n`
- by (fs[MULT])
- \\ qpat_x_assum `SUC (SUC n) * _ = _` (fn thm => once_rewrite_tac [thm])
- \\ `n + n + n * n + 1 = SUC n + n * (n + 1)`
- by (once_rewrite_tac [ADD1] \\ once_rewrite_tac [LEFT_ADD_DISTRIB]
- \\ rewrite_tac [ADD_ASSOC, MULT_RIGHT_1] \\ fs[])
- \\ qpat_x_assum `n + n + _ + _ = _` (fn thm => once_rewrite_tac [thm])
- \\ rewrite_tac [ADD_ASSOC]
- \\ `SUC n + SUC n = 2 * (SUC n)`
- by (fs[])
- \\ qpat_x_assum `SUC n + _ = _` (fn thm => once_rewrite_tac [thm])
- \\ once_rewrite_tac [MULT_COMM]
- \\ rewrite_tac [GSYM REAL_MUL, GSYM REAL_ADD]
- \\ rewrite_tac [GSYM REAL_DIV_ADD]
- \\ rewrite_tac [real_div]
- \\ rewrite_tac [GSYM REAL_MUL_ASSOC]
- \\ fs[REAL_MUL_RINV]
- \\ fs[REAL_MUL_ASSOC] *)
-QED
-
-Theorem pow_3:
- n pow 3 = n * n * n
-Proof
- LassieLib.nltac `
- we show '3 = SUC 2' using (simplify).
- rewrite last assumption. simplify with [pow, POW_2]. trivial.`
- (*
- `3 = SUC 2` by (fs[])
- \\ pop_assum rw_th
- \\ fs[pow, POW_2] \\ REAL_ASM_ARITH_TAC *)
-QED
-
-(**
- The sum of cubed numbers up to n is the squared sum
-**)
-Theorem sum_of_cubes_is_squared_sum:
- ! n. sum_of_cubes n = (sum n) pow 2
-Proof
- LassieLib.nltac ‘
- induction on 'n'.
- simplify conclusion with [sum_of_cubes_def, sum_def].
- rewrite with [POW_2, REAL_LDISTRIB, REAL_RDISTRIB, REAL_ADD_ASSOC].
- showing '&SUC n pow 3 = &SUC n * &SUC n + &SUC n * sum n + sum n * &SUC n'
- closes the proof because (simplify conclusion with [REAL_EQ_LADD]).
- we know '& SUC n * sum n + sum n * &SUC n = 2 * (sum n * & SUC n)'.
- rewrite once [<- REAL_ADD_ASSOC].
- rewrite last assumption.
- rewrite with [pow_3, closed_form_sum, real_div, REAL_MUL_ASSOC].
- we know '2 * &n * (1 + &n) * inv 2 = 2 * inv 2 * & n * (1 + &n)'.
- rewrite last assumption.
- simplify conclusion with [REAL_MUL_RINV].
- we show 'n + 1 = SUC n' using (simplify conclusion).
- rewrite last assumption. simplify conclusion.
- we show '2 = (SUC (SUC 0))' using (simplify conclusion).
- rewrite last assumption. rewrite last assumption.
- rewrite with [EXP].
- we show 'SUC n = n + 1' using (simplify conclusion).
- rewrite last assumption.
- rewrite with [GSYM REAL_OF_NUM_ADD, pow_3].
- rewrite with [REAL_OF_NUM_ADD, REAL_OF_NUM_MUL, MULT_RIGHT_1,
- RIGHT_ADD_DISTRIB, LEFT_ADD_DISTRIB, MULT_LEFT_1].
- simplify.’
-QED
-
-(*
-Induct_on ‘n’ \\ simp [sum_of_cubes_def, sum_def, ]
- \\ fs[pow_3]
- \\ once_rewrite_tac [REAL_ADD_ASSOC]
- \\ pop_assum rw_th
- \\ once_rewrite_tac [closed_form_sum]
- \\ once_rewrite_tac [real_div]
- \\ rewrite_tac [REAL_MUL_ASSOC]
- \\ `2 * &n * (1 + &n) * inv 2 = 2 * inv 2 * & n * (1 + &n)` by (REAL_ASM_ARITH_TAC)
- \\ pop_assum rw_th
- \\ simp [REAL_MUL_RINV]
- \\ `(SUC n) ** 3 = (SUC n)**2 + (SUC n)**2 * n`
- by (`3= SUC (SUC (SUC 0))` by (fs[]) \\ pop_assum rw_th
- \\ `2 = SUC(SUC 0)` by (fs[]) \\ pop_assum rw_th
- \\ rewrite_tac[EXP]
- \\ `SUC n = n + 1` by (fs[])
- \\ pop_assum rw_th
- \\ rewrite_tac [MULT_RIGHT_1, RIGHT_ADD_DISTRIB, LEFT_ADD_DISTRIB, MULT_LEFT_1]
- \\ fs[])
- \\ pop_assum rw_th
- \\ `n + 1 = SUC n` by (fs[])
- \\ pop_assum rw_th \\ fs[]
-QED
- *)
-
-val _ = export_theory();
diff --git a/examples/lassie/examples/caseStudy3IntervalLibScript.sml b/examples/lassie/examples/caseStudy3IntervalLibScript.sml
deleted file mode 100644
index fb3c28da1c..0000000000
--- a/examples/lassie/examples/caseStudy3IntervalLibScript.sml
+++ /dev/null
@@ -1,216 +0,0 @@
-open BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic monadsyntax
- boolTheory bossLib;
-
-open realTheory arithmeticTheory realLib RealArith;
-
-open LassieLib realTacticsLib logicTacticsLib;
-
-val _ = new_theory "caseStudy3IntervalLib";
-
-val _ = (LassieLib.loadJargon "Reals"; LassieLib.loadJargon "Logic");
-
-Definition min4_def:
-min4 a b c d = min a (min b (min c d))
-End
-
-Definition max4_def:
- max4 a b c d = max a (max b (max c d))
-End
-
-val _ = temp_overload_on("abs",``real$abs``);
-val _ = temp_overload_on("max",``real$max``);
-val _ = temp_overload_on("min",``real$min``);
-(**
- Define validity of an interval, requiring that the lower bound is less than or equal to the upper bound.
- Containement is defined such that if x is contained in the interval, it must lie between the lower and upper bound.
-**)
-Definition valid_def:
- valid ((lo,hi):(real # real)) = (lo <= hi)
-End
-
-Definition contained_def:
- contained (a:real) (lo,hi) = (lo <= a /\ a <= hi)
-End
-
-Definition absIntvUpd_def:
-absIntvUpd (op:real->real->real) (iv1:real#real) (iv2:real#real) =
-(
- min4 (op (FST iv1) (FST iv2))
- (op (FST iv1) (SND iv2))
- (op (SND iv1) (FST iv2))
- (op (SND iv1) (SND iv2)),
- max4 (op (FST iv1) (FST iv2))
- (op (FST iv1) (SND iv2))
- (op (SND iv1) (FST iv2))
- (op (SND iv1) (SND iv2))
-)
-End
-
-Definition widenInterval_def:
-widenInterval (iv:real#real) (v:real) = ((FST iv - v), (SND iv + v))
-End
-
-Definition negateInterval_def:
-negateInterval (iv:real#real) = ((- SND iv), (- FST iv))
-End
-
-Definition invertInterval_def:
- invertInterval (iv:real#real) = (1 /(SND iv), 1 /(FST iv))
-End
-
-Definition addInterval_def:
- addInterval (iv1:real#real) (iv2:real#real) = absIntvUpd (+) iv1 iv2
-End
-
-Definition subtractInterval_def:
- subtractInterval (iv1:real#real) (iv2:real#real) = addInterval iv1 (negateInterval iv2)
-End
-
-Definition multInterval_def:
- multInterval (iv1:real#real) (iv2:real#real) = absIntvUpd ( * ) iv1 iv2
-End
-
-Definition divideInterval_def:
- divideInterval iv1 iv2 = multInterval iv1 (invertInterval iv2)
-End
-
-Definition minAbsFun_def:
- minAbsFun iv = min (abs (FST iv)) (abs (SND iv))
-End
-
-Theorem contained_implies_valid:
- !(a:real) (iv:real#real).
- contained a iv ==> valid iv
-Proof
- LassieLib.nltac `
- introduce variables.
- case split for 'iv'.
- trivial using [contained_def, valid_def, REAL_LE_TRANS].`
-QED
-
-Theorem min4_correct:
- ! a b c d.
- let m = min4 a b c d in
- m <= a /\ m <= b /\ m <= c /\ m <= d
-Proof
- LassieLib.nltac `
- introduce variables. simplify with [min4_def]. perform a case split.
- try simplify with [REAL_MIN_LE1].
- use transitivity for 'min b (min c d)'.
- simplify with [REAL_MIN_LE1, REAL_MIN_LE2].
- use transitivity for 'min c d'.
- simplify with [REAL_MIN_LE1, REAL_MIN_LE2].`
-QED
-
-Theorem max4_correct:
- !a b c d.
- let m = max4 a b c d in
- a <= m /\ b <= m /\ c <= m /\ d <= m
-Proof
- LassieLib.nltac `
- introduce variables. simplify with [max4_def]. perform a case split.
- try simplify with [REAL_LE_MAX1].
- use transitivity for 'max b (max c d)'.
- simplify with [REAL_LE_MAX1, REAL_LE_MAX2].
- use transitivity for 'max c d'.
- simplify with [REAL_LE_MAX1, REAL_LE_MAX2].`
-QED
-
-Theorem interval_negation_valid:
- ! iv a.
- contained a iv ==> contained (- a) (negateInterval iv)
-Proof
- LassieLib.nltac `
- introduce variables. case split for 'iv'.
- simplify with [contained_def, negateInterval_def, REAL_LE_TRANS].`
-QED
-
-Theorem iv_neg_preserves_valid:
- !iv.
- valid iv ==> valid (negateInterval iv)
-Proof
- LassieLib.nltac `
- introduce variables.
- case split for 'iv'.
- simplify with [valid_def, negateInterval_def].`
-QED
-
-(*
-gt `! x y. 0 < x /\ 0 < y ==> (inv x <= inv y <=> y <= x)`
-
-proveInteractive();
-
-introduce assumptions
-we show 'inv x < inv y <=> y < x' using (use REAL_INV_LT_ANTIMONO THEN follows trivially)
-*)
-Theorem nonzerop_EQ1_I'[simp]:
- 0 < r ==> (nonzerop r = 1)
-Proof
- rw[nonzerop_def]
-QED
-
-val REAL_LE_IMP_LT = curry save_thm "REAL_LE_IMP_LT" (fst (EQ_IMP_RULE (Drule.SPEC_ALL REAL_LE_LT)));
-
-Theorem REAL_INV_LE_ANTIMONO[local]:
- ! x y.
- 0 < x /\ 0 < y ==>
- (inv x <= inv y <=> y <= x)
-Proof
- LassieLib.nltac `
- introduce assumptions.
- we show 'inv x < inv y <=> y < x' using (use REAL_INV_LT_ANTIMONO THEN follows trivially).
- case split.
- simplify with [REAL_LE_LT].
- introduce assumptions.
- simplify with [REAL_INV_INJ]. trivial.`
- (* More verbose version using subgoal selectors:
- LassieLib.nltac ‘
- introduce assumptions.
- we show 'inv x < inv y <=> y < x'
- using (use REAL_INV_LT_ANTIMONO then follows trivially).
- case split. introduce assumptions.
- Case 'inv x ≤ inv y'.
- resolve with REAL_LE_IMP_LT.
- Case 'inv x = inv y'. follows from [REAL_INV_INJ]. End.
- Case 'inv x < inv y'. trivial. End.
- Case 'y ≤ x'.
- resolve with REAL_LE_IMP_LT.
- Case 'y = x'. follows from [REAL_INV_INJ]. End.
- Case 'y < x'. trivial. End.’ *)
-QED
-
-Theorem interval_inversion_valid:
- ∀ iv a.
- (SND iv < 0 ∨ 0 < FST iv) ∧ contained a iv ⇒
- contained (inv a) (invertInterval iv)
-Proof
- LassieLib.nltac ‘
- introduce variables.
- case split for 'iv'.
- simplify with [contained_def, invertInterval_def].
- introduce assumptions.
- rewrite once [<- REAL_INV_1OVER].
- Next Goal.
- rewrite once [ <- REAL_LE_NEG]. we know 'a < 0'. thus 'a <> 0'.
- we know 'r < 0'. thus 'r <> 0'.
- 'inv(-a) <= inv (-r) <=> (- r) <= -a' using
- (use REAL_INV_LE_ANTIMONO THEN simplify).
- resolve with REAL_NEG_INV. rewrite assumptions. follows trivially.
- Next Goal.
- rewrite once [<- REAL_LE_NEG].
- we know 'a < 0'. thus 'a <> 0'. we know 'q <> 0'.
- resolve with REAL_NEG_INV.
- 'inv (-q) <= inv (-a) <=> (-a) <= (-q)' using
- (use REAL_INV_LE_ANTIMONO THEN simplify THEN trivial).
- rewrite assumptions. follows trivially.
- Next Goal.
- rewrite with [<- REAL_INV_1OVER].
- 'inv r <= inv a <=> a <= r' using (use REAL_INV_LE_ANTIMONO THEN trivial).
- follows trivially.
- Next Goal.
- rewrite with [<- REAL_INV_1OVER].
- 'inv a <= inv q <=> q <= a' using (use REAL_INV_LE_ANTIMONO THEN trivial).
- follows trivially.’
-QED
-
-val _ = export_theory();
diff --git a/examples/lassie/examples/caseStudy4NaprochePowersetScript.sml b/examples/lassie/examples/caseStudy4NaprochePowersetScript.sml
deleted file mode 100644
index 6ab7748cd7..0000000000
--- a/examples/lassie/examples/caseStudy4NaprochePowersetScript.sml
+++ /dev/null
@@ -1,59 +0,0 @@
-open BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic monadsyntax
- boolTheory bossLib arithmeticTheory;
-
-open realTheory arithmeticTheory realLib RealArith;
-
-open LassieLib logicTacticsLib;
-
-val _ = new_theory "caseStudy4NaprochePowerset";
-
-val _ = LassieLib.loadJargon "Logic";
-
-Theorem cantor:
- ∀ f:'a -> ('a -> bool).
- ~ (∀ y:'a -> bool. ∃ x:'a. f x = y)
-Proof
- LassieLib.nltac ‘
- assume the contrary. simplify.
- we know '∃ x. f x = λ x . ~ (x IN (f x))'.
- simplify.
- case split for 'x IN f x'.
- simplify with [IN_DEF]. trivial.’
- (* CCONTR_TAC \\ fs[]
- \\ first_x_assum (qspec_then `\ x. ~ (x IN (f x))` assume_tac)
- \\ fs[]
- \\ Cases_on `x IN f x`
- >- (
- pop_assum mp_tac \\ fs[IN_DEF] \\ metis_tac[])
- >- (fs[IN_DEF] \\ metis_tac[]) *)
-QED
-
-(*
-Let M denote a set.
-Let f denote a function.
-Let the value of f at x stand for f[x].
-Let f is defined on M stand for Dom(f) = M.
-Let the domain of f stand for Dom(f). *)
-
-(* Axiom. The value of f at any element of the domain of f is a set. *)
-(** This axiom can be encoded by giving f the type :'a -> 'b set option **)
-
-(* Definition.
-A subset of M is a set N such that every element of N is an element of M. *)
-
-(* Definition.
-The powerset of M is the set of subsets of M. *)
-
-(* Definition.
-f surjects onto M iff every element of M is equal to the value of f at some element of the domain of f. *)
-
-(* Proposition.
-No function that is defined on M surjects onto the powerset of M.
-Proof.
-Assume the contrary.
-Take a function f that is defined on M and surjects onto the powerset of M.
-Define N = { x in M | x is not an element of f[x] }.
-Then N is not equal to the value of f at any element of M.
-Contradiction. qed. *)
-
-val _ = export_theory();
diff --git a/examples/lassie/examples/gaussScript.sml b/examples/lassie/examples/gaussScript.sml
deleted file mode 100644
index 770a6caa9f..0000000000
--- a/examples/lassie/examples/gaussScript.sml
+++ /dev/null
@@ -1,35 +0,0 @@
-open BasicProvers Defn HolKernel Parse Tactic
- arithmeticTheory boolLib boolSimps bossLib;
-open LassieLib arithTacticsLib realTacticsLib logicTacticsLib;
-
-val _ = new_theory "gauss";
-
-val _ = LassieLib.loadJargon "Arithmetic";
-val _ = LassieLib.loadJargon "Logic";
-
-Definition sum_def:
- sum (0:num) = 0 ∧
- sum n = n + sum (n-1)
-End
-
-Theorem closed_form_sum:
- ∀ n.
- sum n = (n * (n + 1)) DIV 2
-Proof
- nltac
- ‘Induction on 'n'.
- use [sum_def] to simplify.
- use [sum_def, GSYM ADD_DIV_ADD_DIV] to simplify.
- '2 * SUC n + n * (n + 1) = SUC n * (SUC n + 1)'
- suffices to show the goal.
- show 'SUC n * (SUC n + 1) = (SUC n + 1) + n * (SUC n + 1)'
- using (simplify with [MULT_CLAUSES]).
- simplify.
- show 'n * (n + 1) = SUC n * n'
- using (trivial using [MULT_CLAUSES, MULT_SYM]).
- '2 * SUC n = SUC n + SUC n' follows trivially.
- 'n * (SUC n + 1) = SUC n * n + n' follows trivially.
- rewrite assumptions. simplify.’
-QED
-
-val _ = export_theory();
diff --git a/examples/lassie/examples/logicTacticsLib.sml b/examples/lassie/examples/logicTacticsLib.sml
deleted file mode 100644
index 122502fa2a..0000000000
--- a/examples/lassie/examples/logicTacticsLib.sml
+++ /dev/null
@@ -1,63 +0,0 @@
-structure logicTacticsLib =
-struct
-
- open LassieLib;
-
- local open realTheory in end;
- val _ =
- let
- fun jargon () =
- let
- val _ =
- map (uncurry def) [
- (* Case splitting *)
- (‘split conjuncts’, ‘conj_tac THEN rpt conj_tac’),
- (`case split`, `(split conjuncts) ORELSE (EQ_TAC ORELSE Cases)`),
- (`case split for 's'`,`Cases_on 's'`),
- (`perform a case split`,`case split`),
- (`specialize for 'T'`,`first_x_assum qspec_then ' T ' assume_tac`),
- (`assume the contrary`,`CCONTR_TAC`),
- (* Automation a la textbook *)
- (`trivial`,`metis_tac [ ]`),
- (`trivial using [CONJ_COMM]`, `metis_tac [ CONJ_COMM ]`),
- (`follows trivially`,`fs [ ]`),
- (`follows from [ADD_COMM]`, `fs [ ADD_COMM ]`),
- (* Simplification *)
- (`simplify`, `fs [ ]`),
- (`simplify with [CONJ_COMM]`, `fs [ CONJ_COMM ]`),
- (`simplify conclusion`, `simp [ ]`),
- (`simplify conclusion with [CONJ_COMM]`, `simp [ CONJ_COMM ]`),
- (* lc aliases *)
- (`try gen_tac`, `TRY gen_tac`),
- (* `try solving with [CONJ_COMM]` [`TRY simp [CONJ_COMM]`]; *)
- (* Textbook style tactics for existentials, modus ponens, ... *)
- (`choose 'e'`, `qexists_tac ' e '`),
- (`use transitivity for 'x'`, `irule REAL_LE_TRANS THEN qexists_tac ' x '`),
- (`use REAL_LE_TRANS`, `irule REAL_LE_TRANS`),
- (`resolve with REAL_NEG_INV`, `imp_res_tac REAL_NEG_INV`),
- (`induction on 'n'`, `Induct_on ' n '`),
- (* rewriting *)
- (`rewrite once [REAL_INV_1OVER]`, `once_rewrite_tac [ REAL_INV_1OVER ]`),
- (`rewrite once [<- REAL_INV_1OVER]`, `once_rewrite_tac [ GSYM REAL_INV_1OVER ]`),
- (`rewrite with [REAL_INV_1OVER]`, `rewrite_tac [REAL_INV_1OVER]`),
- (`rewrite with [<- REAL_INV_1OVER]`, `rewrite_tac [GSYM REAL_INV_1OVER]`),
- (`rewrite assumptions`, `asm_rewrite_tac []`),
- (`rewrite assumptions and [ADD_ASSOC] `, `asm_rewrite_tac [ADD_ASSOC]`),
- (* subgoals *)
- (`we show first 'T'`, `sg 'T'`),
- (`we show next 'T'`, `we show first 'T'`),
- (`we show 'T' using (gen_tac)`, `'T' by gen_tac`),
- (`we know 'T'`, `'T' by (fs [ ])`),
- (`thus 'T'`, `we know 'T'`),
- (`'T' using (cheat)`, `'T' by (cheat)`),
- (`showing 'T' closes the proof because (gen_tac)`, `'T' suffices_by (gen_tac)`),
- (‘Case 'x'’, ‘Goal 'x'’),
- (‘cheat then cheat’, ‘cheat THEN cheat’),
- (‘Next Goal’, ‘Goal 1’)
- ]
- in () end;
- in
- LassieLib.registerJargon "Logic" (jargon)
- end
-
-end;
diff --git a/examples/lassie/examples/realTacticsLib.sml b/examples/lassie/examples/realTacticsLib.sml
deleted file mode 100644
index 62d4cfacc7..0000000000
--- a/examples/lassie/examples/realTacticsLib.sml
+++ /dev/null
@@ -1,29 +0,0 @@
-structure realTacticsLib =
-struct
-
- open LassieLib;
-
- local open realTheory RealArith in end;
- val _ =
- let
- fun jargon () =
- let val _ = LassieLib.addCustomTactic RealArith.REAL_ASM_ARITH_TAC "REAL_ASM_ARITH_TAC"
- val _ = LassieLib.addCustomTactic DECIDE_TAC "DECIDE_TAC"
- val rw_th = fn thm => once_rewrite_tac[thm];
- val _ = LassieLib.addCustomThmTactic rw_th "rw_th";
- val _ =
- map (uncurry def) [
- (* intro tactics *)
- (`introduce variables`, `rpt gen_tac`),
- (`introduce assumptions`, `rpt strip_tac`),
- (* Custom tactic *)
- (`rewrite last assumption`, `pop_assum rw_th`),
- (`rewrite ADD_ASSOC for 'n'`, `qspec_then 'n' rw_th ADD_ASSOC`),
- (‘trivial’, ‘REAL_ASM_ARITH_TAC’),
- (`we know 'T'`, `'T' by (REAL_ASM_ARITH_TAC ORELSE DECIDE_TAC)`)
- ]
- in () end
- in
- LassieLib.registerJargon "Reals" jargon
- end;
-end;
diff --git a/examples/lassie/examples/tacticsCaseStudyLib.sml b/examples/lassie/examples/tacticsCaseStudyLib.sml
deleted file mode 100644
index d8b3c70fe6..0000000000
--- a/examples/lassie/examples/tacticsCaseStudyLib.sml
+++ /dev/null
@@ -1,93 +0,0 @@
-structure tacticsCaseStudyLib =
-struct
-
-(** Below we add some natural language tactics to Lassie first, then we showcase
- how Lassie generalizes them using SEMPRE **)
-
-(* First, add some custom tactics, this is also how a hand crafted decision
- procedure can be added *)
-val _ = LassieLib.addCustomTactic "REAL_ASM_ARITH_TAC";
-val _ = LassieLib.addCustomTactic "impl_tac";
-val _ = LassieLib.addCustomTactic "cheat";
-val _ = LassieLib.addCustomTactic "EQ_TAC";
-
-val _ = LassieLib.def `introduce variables` [`rpt gen_tac`];
-val _ = LassieLib.def `introduce variables and assumptions` [`rpt strip_tac`];
-val _ = LassieLib.def `case split for 's'` [`Cases_on 's'`];
-val _ = LassieLib.def `case split` [`(rpt conj_tac ORELSE EQ_TAC) ORELSE Cases`];
-val _ = LassieLib.def `trivial using [CONJ_COMM]` [`metis_tac [CONJ_COMM]`];
-val _ = LassieLib.def `simplify with [CONJ_COMM]` [`simp [CONJ_COMM]`];
-val _ = LassieLib.def `try solving with [CONJ_COMM]` [`TRY simp [CONJ_COMM]`];
-val _ = LassieLib.def `choose 'e'` [`qexists_tac 'e'`];
-val _ = LassieLib.def `use transitivity for 'x'` [`irule REAL_LE_TRANS THEN qexists_tac 'x'`];
-val _ = LassieLib.def `use REAL_LE_TRANS` [`irule REAL_LE_TRANS`];
-val _ = LassieLib.def `perform a case split` [`rpt conj_tac`];
-val _ = LassieLib.def `we show first 'T'` [`sg 'T'`];
-val _ = LassieLib.def `we show 'T' using (gen_tac)` [`'T' by (gen_tac)`];
-val _ = LassieLib.def `introduce assumptions` [`rpt strip_tac`];
-val _ = LassieLib.def `rewrite once [REAL_INV_1OVER]` [`once_rewrite_tac [REAL_INV_1OVER]`];
-val _ = LassieLib.def `rewrite once [<- REAL_INV_1OVER]` [`once_rewrite_tac [GSYM REAL_INV_1OVER]`];
-val _ = LassieLib.def `rewrite with [REAL_INV_1OVER]` [`rewrite_tac [REAL_INV_1OVER]`];
-val _ = LassieLib.def `rewrite with [<- REAL_INV_1OVER]` [`rewrite_tac [GSYM REAL_INV_1OVER]`];
-val _ = LassieLib.def `we show next 'T'` [`we show first 'T'`];
-val _ = LassieLib.def `'T' using (fs[])` [`'T' by ( fs[] )`];
-val _ = LassieLib.def `we know 'T'` [`'T' by (REAL_ASM_ARITH_TAC)`];
-val _ = LassieLib.def `thus 'T'` [`we know 'T'`];
-val _ = LassieLib.def `resolve with REAL_NEG_INV` [`imp_res_tac REAL_NEG_INV`];
-val _ = LassieLib.def `follows from [CONJ_COMM]` [`asm_rewrite_tac [CONJ_COMM] THEN fs[CONJ_COMM]`];
-val _ = LassieLib.def `gen_tac . gen_tac` [`gen_tac THEN gen_tac`];
-val _ = LassieLib.def `gen_tac .` [`gen_tac THEN all_tac`];
-
-(*
-local open LassieLib;
-in
-val _ = LassieLib.def "introduce variables" ["rpt gen_tac"];
-val _ = LassieLib.def "introduce assumptions" ["rpt strip_tac"];
-end;
-
-val _ = LassieLib.def "introduce variables and assumptions" ["introduce variables THEN introduce assumptions"];
-val _ = LassieLib.def "we show `T` using (gen_tac)" ["`T` by (gen_tac)"];
-
-val _ = LassieLib.def "case split" ["rpt conj_tac ORELSE EQ_TAC"];
-val _ = LassieLib.def "case split for `s`" ["Cases_on `s`"];
-
-val _ = LassieLib.nltac "case split for `t`.";
-val _ = LassieLib.nltac "case split for `A and B`.";
-
-val _ = LassieLib.def "trivial using [CONJ_COMM]" ["metis_tac [CONJ_COMM]"];
-
-val _ = LassieLib.nltac "trivial using [REAL_ADD_ASSOC].";
-val _ = LassieLib.nltac "trivial using [REAL_ADD_ASSOC, CONJ_COMM, REAL_LDISTRIB].";
-
-(** The below tactics generalize for arbitrary list similarly *)
-val _ = LassieLib.def "simplify with [MULT]" ["simp [MULT]"];
-val _ = LassieLib.def "solve with [MULT]" ["simp [MULT]"];
-val _ = LassieLib.def "try solve with [MULT]" ["TRY solve with [MULT]"];
-
-(* Note that the above generalizes "try" for any! tactic *)
-val _ = LassieLib.nltac "try simplify with [MULT].";
-
-val _ = LassieLib.def "choose `e`" ["qexists_tac `e`"];
-val _ = LassieLib.def "use REAL_LE_TRANS" ["irule REAL_LE_TRANS"];
-val _ = LassieLib.def "perform a case split" ["rpt conj_tac"];
-val _ = LassieLib.def "we show first `T`" ["sg `T`"];
-val _ = LassieLib.def "use transitivity for `x`" ["irule REAL_LE_TRANS THEN qexists_tac `x`"];
-
-val _ = LassieLib.def "rewrite once [REAL_INV_1OVER]" ["once_rewrite_tac [REAL_INV_1OVER]"];
-val _ = LassieLib.def "rewrite once [<- REAL_INV_1OVER]" ["once_rewrite_tac [GSYM REAL_INV_1OVER]"];
-
-val _ = LassieLib.nltac "rewrite once [<- MULT].";
-(* FIXME: LassieLib.nltac "solve with [<- MULT]." *)
-
-val _ = LassieLib.def "rewrite with [REAL_INV_1OVER]" ["rewrite_tac [REAL_INV_1OVER]"];
-val _ = LassieLib.def "rewrite with [<- REAL_INV_1OVER]" ["rewrite_tac [GSYM REAL_INV_1OVER]"];
-
-val _ = LassieLib.def "we show next `T`" ["we show first `T`"];
-val _ = LassieLib.def "`T` using (fs[])" ["`T` by (fs[])"];
-val _ = LassieLib.def "we know `T`" ["`T` by (REAL_ASM_ARITH_TAC)"];
-val _ = LassieLib.def "thus `T`" ["we know `T`"];
-val _ = LassieLib.def "resolve with REAL_NEG_INV" ["imp_res_tac REAL_NEG_INV"];
-val _ = LassieLib.def "follows from [CONJ_COMM]" ["asm_rewrite_tac [CONJ_COMM] THEN fs[CONJ_COMM]"];
-*)
-
-end
diff --git a/examples/lassie/examples/tutorialScript.sml b/examples/lassie/examples/tutorialScript.sml
deleted file mode 100644
index 53bd06f3d4..0000000000
--- a/examples/lassie/examples/tutorialScript.sml
+++ /dev/null
@@ -1,37 +0,0 @@
-open BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic boolTheory
- bossLib arithmeticTheory;
-open LassieLib arithTacticsLib logicTacticsLib;
-
-val _ = new_theory "tutorial";
-
-val _ = loadJargon "Arithmetic";
-val _ = loadJargon "Logic";
-
-Definition sum_def:
- sum (n:num) = if n = 0 then 0 else sum (n-1) + n
-End
-
-Definition sumEq_def:
- sumEq (0:num) = 0 /\
- sumEq n = n + sumEq (n-1)
-End
-
-Theorem closed_form_sum:
- ! n. sumEq n = n * (n + 1) DIV 2
-Proof
- nltac `Induction on 'n'.`
- \\ nltac `simplify with [sumEq_def].`
- \\ nltac
- `simplify with [sumEq_def, GSYM ADD_DIV_ADD_DIV].`
- \\ nltac `'2 * SUC n + n * (n + 1) = SUC n * (SUC n + 1)'
- suffices to show the goal.`
- \\ nltac
- `show 'SUC n * (SUC n + 1) = (SUC n + 1) + n * (SUC n + 1)'
- using (simplify with [MULT_CLAUSES]).`
- \\ nltac `simplify.`
- \\ nltac `show 'n * (n + 1) = SUC n * n' using (trivial using [MULT_CLAUSES,
- MULT_SYM]).`
- \\ nltac `rewrite assumptions. simplify.`
-QED
-
-val _ = export_theory();
diff --git a/examples/lassie/regression/Holmakefile b/examples/lassie/regression/Holmakefile
deleted file mode 100644
index 5f2fec6c4f..0000000000
--- a/examples/lassie/regression/Holmakefile
+++ /dev/null
@@ -1,8 +0,0 @@
-INCLUDES = ../src/
-CLINE_OPTIONS=-j1
-TACTIC_WORLD = ../sempre/classes/interactive/edu/stanford/nlp/sempre/interactive/lassie/TacticWorld.class
-
-all: $(DEFAULT_TARGETS)
-.PHONY: all
-
-caseStudy1EuclidTheory.sml: $(TACTIC_WORLD)
diff --git a/examples/lassie/regression/arithTacticsLib.sml b/examples/lassie/regression/arithTacticsLib.sml
deleted file mode 100644
index a558493bbc..0000000000
--- a/examples/lassie/regression/arithTacticsLib.sml
+++ /dev/null
@@ -1,44 +0,0 @@
-structure arithTacticsLib =
-struct
- open LassieLib;
-
- local open arithmeticTheory in end;
- fun fs_all g = let val thms = map (fn (a,th) => th) (DB.theorems "-") in fs thms g end;
- val _ =
- let
- fun jargon () =
- let
- val _ = LassieLib.addCustomTactic fs_all "fs_all";
- val _ =
- map (uncurry def) [
- (`simplify`, `fs [ ]`),
- (`simplify with [ADD_ASSOC]`, `fs [ ADD_ASSOC ]`),
- (`use [ADD_ASSOC] to simplify`, `fs [ ADD_ASSOC ]`),
- (`follows from [ADD_ASSOC]`, `metis_tac [ ADD_ASSOC ]`),
- (`rewrite [ADD_ASSOC]` ,`rw [ADD_ASSOC]`),
- (`[ADD_ASSOC] solves the goal`,
- `all_tac THEN ( fs [ ADD_ASSOC ] THEN NO_TAC) ORELSE (rw [ ADD_ASSOC ] THEN NO_TAC) ORELSE metis_tac [ ADD_ASSOC ]`),
- (‘trivial’, ‘[] solves the goal’),
- (`perform an induction on 't'`, `Induct_on ' t '`),
- (`Induction on 't'`, `Induct_on ' t '`),
- (`perform a case split`, `Cases`),
- (`perform a case split for 't'`, `Cases_on ' t '`),
- (`Complete Induction on 't'`, `completeInduct_on ' t '`),
- (`suppose not`, `spose_not_then assume_tac`),
- (`show 'T' using (gen_tac)` ,`' T ' by gen_tac`),
- (‘show 'T' using [ CONJ_COMM ]’, ‘ ' T ' by ([ CONJ_COMM ] solves the goal)’),
- (‘'T' follows trivially’, ‘show 'T' using (trivial)’),
- (`we further know 'T'`, `' T ' by rw [ ]`),
- (`we can derive 'T' from [ADD_ASSOC]`, `' T ' by rw [ ADD_ASSOC ]`),
- (`thus ADD_ASSOC for 'n'`, `qspec_then ' n ' assume_tac ADD_ASSOC`),
- (‘'T' suffices to show the goal’, ‘'T' suffices_by (fs[])’),
- (`it suffices to show that the arguments are equal`, `AP_TERM_TAC`),
- (`it suffices to show that the functions are equal`, `AP_THM_TAC`),
- (‘cheat and cheat’, ‘cheat THEN cheat’)
- ]
- in () end;
- in
- LassieLib.registerJargon "Arithmetic" (jargon)
- end
-
-end;
diff --git a/examples/lassie/regression/caseStudy1EuclidScript.sml b/examples/lassie/regression/caseStudy1EuclidScript.sml
deleted file mode 100644
index 82ef9cab4e..0000000000
--- a/examples/lassie/regression/caseStudy1EuclidScript.sml
+++ /dev/null
@@ -1,280 +0,0 @@
-(** Taken from the HOL4 distribution (original file: HOL4/examples/euclid.sml **)
-
-(*===========================================================================*)
-(* Euclid's theorem: for every prime, there is another one that is larger. *)
-(* This proof has been excerpted and adapted from John Harrison's proof of *)
-(* a special case (n=4) of Fermat's Last Theorem. *)
-(* *)
-(*===========================================================================*)
-
-(*---------------------------------------------------------------------------*)
-(* First, open required context: the theory of arithmetic. This theory is *)
-(* automatically loaded when HOL starts, but the ML module arithmeticTheory *)
-(* needs to be opened before the definitions and theorems of the theory are *)
-(* available without supplying the "arithmeticTheory." prefix. *)
-(*---------------------------------------------------------------------------*)
-
-open BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic monadsyntax
- boolTheory bossLib arithmeticTheory;
-
-open LassieLib arithTacticsLib;
-
-val _ = new_theory "caseStudy1Euclid";
-
-val _ = LassieLib.loadJargon "Arithmetic";
-(*---------------------------------------------------------------------------*)
-(* Divisibility. *)
-(*---------------------------------------------------------------------------*)
-
-set_fixity "divides" (Infix(NONASSOC, 450));
-
-Definition divides_def:
-(a divides b) = (? x. b = a * x)
-End
-
-
-(*---------------------------------------------------------------------------*)
-(* Primality. *)
-(*---------------------------------------------------------------------------*)
-
-Definition prime_def:
- prime p = (p<>1 /\ !x . x divides p ==> (x=1) \/ (x=p))
-End
-
-(*---------------------------------------------------------------------------*)
-(* A sequence of basic theorems about the "divides" relation. *)
-(*---------------------------------------------------------------------------*)
-
-Theorem DIVIDES_0:
- ! x . x divides 0
-Proof
- LassieLib.nltac `
- [divides_def, MULT_CLAUSES] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES] *)
-QED
-
-Theorem DIVIDES_ZERO:
- ! x . (0 divides x) = (x = 0)
-Proof
- LassieLib.nltac `
- [divides_def, MULT_CLAUSES] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES] *)
-QED
-
-Theorem DIVIDES_ONE:
- ! x . (x divides 1) = (x = 1)
-Proof
- LassieLib.nltac
- `[divides_def, MULT_CLAUSES, MULT_EQ_1] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES,MULT_EQ_1] *)
-QED
-
-Theorem DIVIDES_REFL:
- ! x . x divides x
-Proof
- LassieLib.nltac `
- [divides_def, MULT_CLAUSES] solves the goal.`
- (* metis_tac [divides_def,MULT_CLAUSES] *)
-QED
-
-Theorem DIVIDES_TRANS:
- ! a b c . a divides b /\ b divides c ==> a divides c
-Proof
- LassieLib.nltac `
- [divides_def, MULT_ASSOC] solves the goal.`
- (* metis_tac [divides_def,MULT_ASSOC] *)
-QED
-
-Theorem DIVIDES_ADD:
- ! d a b . d divides a /\ d divides b ==> d divides (a + b)
-Proof
- LassieLib.nltac `
- [divides_def, LEFT_ADD_DISTRIB] solves the goal.`
- (* metis_tac [divides_def, LEFT_ADD_DISTRIB] *)
-QED
-
-Theorem DIVIDES_SUB:
- !d a b . d divides a /\ d divides b ==> d divides (a - b)
-Proof
- LassieLib.nltac `
- [divides_def, LEFT_SUB_DISTRIB] solves the goal.`
- (* metis_tac [divides_def,LEFT_SUB_DISTRIB] *)
-QED
-
-Theorem DIVIDES_ADDL:
- !d a b . d divides a /\ d divides (a + b) ==> d divides b
-Proof
- LassieLib.nltac `
- [ADD_SUB, ADD_SYM, DIVIDES_SUB] solves the goal.`
- (* metis_tac [ADD_SUB,ADD_SYM,DIVIDES_SUB] *)
-QED
-
-Theorem DIVIDES_LMUL:
- !d a x . d divides a ==> d divides (x * a)
-Proof
- LassieLib.nltac `
- [divides_def, MULT_ASSOC, MULT_SYM] solves the goal.`
- (* metis_tac [divides_def,MULT_ASSOC,MULT_SYM] *)
-QED
-
-Theorem DIVIDES_RMUL:
- !d a x . d divides a ==> d divides (a * x)
-Proof
- LassieLib.nltac `
- [MULT_SYM,DIVIDES_LMUL] solves the goal.`
- (* metis_tac [MULT_SYM,DIVIDES_LMUL] *)
-QED
-
-Theorem DIVIDES_LE:
- !m n . m divides n ==> m <= n \/ (n = 0)
-Proof
- LassieLib.nltac ‘
- rewrite [divides_def].
- [] solves the goal.’
- (* rw [divides_def] >> rw[] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Various proofs of the same formula *)
-(*---------------------------------------------------------------------------*)
-val NOT_X_LE = save_thm ("NOT_X_LE", DECIDE ``! x. ~(x < x)``);
-
-Theorem DIVIDES_FACT:
- !m n . 0 < m /\ m <= n ==> m divides (FACT n)
-Proof
- LassieLib.nltac ‘
- rewrite [LESS_EQ_EXISTS].
- perform an induction on 'p'.
- [FACT, NOT_X_LE, num_CASES, DIVIDES_RMUL, DIVIDES_LMUL, DIVIDES_REFL, ADD_CLAUSES]
- solves the goal.’
- (*
- rw [LESS_EQ_EXISTS]
- >> Induct_on `p`
- >> metis_tac [FACT, DECIDE ``!x. ~(x < x)``, num_CASES,
- DIVIDES_RMUL,DIVIDES_LMUL,DIVIDES_REFL,ADD_CLAUSES] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Zero and one are not prime, but two is. All primes are positive. *)
-(*---------------------------------------------------------------------------*)
-
-Theorem NOT_PRIME_0:
- ~prime 0
-Proof
- LassieLib.nltac `rewrite [prime_def, DIVIDES_0].`
- (* rw [prime_def,DIVIDES_0] *)
-QED
-
-Theorem NOT_PRIME_1:
- ~prime 1
-Proof
- LassieLib.nltac `rewrite [prime_def].`
- (* rw [prime_def] *)
-QED
-
-val two_prime_eqs = curry save_thm "two_prime_eqs" (DECIDE ``~(2=1) /\ ~(2=0) /\ ((x <=2) = (x = 0) \/ (x = 1) \/ (x = 2))``);
-
-Theorem PRIME_2:
- prime 2
-Proof
- LassieLib.nltac `
- rewrite [prime_def].
- [DIVIDES_LE, DIVIDES_ZERO, two_prime_eqs] solves the goal.`
- (* rw [prime_def] >>
- metis_tac [DIVIDES_LE, DIVIDES_ZERO,
- DECIDE``~(2=1) /\ ~(2=0) /\ (x<=2 = (x=0) \/ (x=1) \/ (x=2))``] *)
-QED
-
-Theorem PRIME_POS:
- !p . prime p ==> 0> rw [NOT_PRIME_0] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Every number has a prime factor, except for 1. The proof proceeds by a *)
-(* "complete" induction on n, and then considers cases on whether n is *)
-(* prime or not. The first case (n is prime) is trivial. In the second case, *)
-(* there must be an "x" that divides n, and x is not 1 or n. By DIVIDES_LE, *)
-(* n=0 or x <= n. If n=0, then 2 is a prime that divides 0. On the other *)
-(* hand, if x <= n, there are two cases: if x ?p . prime p /\ p divides n
-Proof
- LassieLib.nltac ‘
- Complete Induction on 'n'.
- rewrite [].
- perform a case split for 'prime n'.
- Goal 1. [DIVIDES_REFL] solves the goal. End.
- Goal 1.
- show '? x. x divides n and x <> 1 and x <> n' using (follows from [prime_def]).
- [LESS_OR_EQ, PRIME_2, DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0] solves the goal.
- End.’
- (*
- completeInduct_on `n`
- >> rw []
- >> Cases_on `prime n` >|
- [metis_tac [DIVIDES_REFL],
- `?x. x divides n /\ x<>1 /\ x<>n` by metis_tac[prime_def] >>
- metis_tac [LESS_OR_EQ, PRIME_2,
- DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0]] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* In the following proof, metis_tac automatically considers cases on *)
-(* whether n is prime or not. *)
-(*---------------------------------------------------------------------------*)
-
-Theorem PRIME_FACTOR:
- !n . n<>1 ==> ?p . prime p /\ p divides n
-Proof
- LassieLib.nltac ‘
- Complete Induction on 'n'.
- [DIVIDES_REFL,prime_def,LESS_OR_EQ, PRIME_2,
- DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0] solves the goal.’
- (*
- completeInduct_on `n` >>
- metis_tac [DIVIDES_REFL,prime_def,LESS_OR_EQ, PRIME_2,
- DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0] *)
-QED
-
-(*---------------------------------------------------------------------------*)
-(* Every number has a prime greater than it. *)
-(* Proof. *)
-(* Suppose not; then there's an n such that all p greater than n are not *)
-(* prime. Consider FACT(n) + 1: it's not equal to 1, so there's a prime q *)
-(* that divides it. q also divides FACT n because q is less-than-or-equal *)
-(* to n. By DIVIDES_ADDL, this means that q=1. But then q is not prime, *)
-(* which is a contradiction. *)
-(*---------------------------------------------------------------------------*)
-
-val neq_zero = curry save_thm "neq_zero" (DECIDE ``~(x=0) = (0 < x)``);
-
-Theorem EUCLID:
- !n . ?p . n < p /\ prime p
-Proof
- LassieLib.nltac‘
- suppose not. simplify.
- we can derive 'FACT n + 1 <> 1' from [FACT_LESS, neq_zero].
- thus PRIME_FACTOR for 'FACT n + 1'.
- we further know '?q. prime q and q divides (FACT n + 1)'.
- show 'q <= n' using [NOT_LESS_EQUAL].
- show '0 < q' using [PRIME_POS] .
- show 'q divides FACT n' using [DIVIDES_FACT].
- show 'q=1' using [DIVIDES_ADDL, DIVIDES_ONE].
- show 'prime 1' using (simplify).
- [NOT_PRIME_1] solves the goal.’
- (*
- spose_not_then strip_assume_tac
- >> mp_tac (SPEC ``FACT n + 1`` PRIME_FACTOR)
- >> rw [FACT_LESS, DECIDE ``~(x=0) = (0> metis_tac [DIVIDES_FACT, DIVIDES_ADDL, DIVIDES_ONE,
- NOT_PRIME_1, NOT_LESS, PRIME_POS] *)
-QED
-
-val _ = export_theory();
diff --git a/examples/lassie/sempre/.gitignore b/examples/lassie/sempre/.gitignore
deleted file mode 100644
index 2335baeab2..0000000000
--- a/examples/lassie/sempre/.gitignore
+++ /dev/null
@@ -1,48 +0,0 @@
-lib
-fig
-sfig
-refdb
-virtuoso-opensource
-
-classes
-libsempre
-sempre.jar
-module-classes.txt
-
-state
-out
-test-output
-
-.project
-.classpath
-.settings
-.idea
-semparse.iml
-*~
-*.swp
-*.bak
-*.pyc
-*.cache
-*.DS_Store
-java.hprof.txt
-
-# Don't put papers here
-/papers
-
-# Symlinks
-/c
-/e
-/t
-/x
-scr
-rdf
-
-# interactive outputs
-int-output*
-int-backup
-interactive/.ipynb_checkpoints
-interactive/lassie.lexicon
-interactive/sempre-out-socket.sml
-# Community server logs
-community-server/data
-community-server/data-backup
diff --git a/examples/lassie/sempre/DOCUMENTATION.md b/examples/lassie/sempre/DOCUMENTATION.md
deleted file mode 100644
index 31bbffe15a..0000000000
--- a/examples/lassie/sempre/DOCUMENTATION.md
+++ /dev/null
@@ -1,1236 +0,0 @@
-# SEMPRE 2.0 documentation
-
-This document describes SEMPRE 2.0 in detail. See
-[the tutorial](TUTORIAL.md) for a more engaging introduction. This document
-assumes a modest understanding of how SEMPRE works.
-
-If you find any bugs, please report them or fix them (file a GitHub issue or
-submit a pull request)!
-
-## Code organization
-
-SEMPRE is designed to be modular so that one can plug in various types of
-parsers, logical forms, executors, etc.
-
-### Modules
-
-The SEMPRE code is broken up into a set of modules (see `Makefile` to see the
-list). The code of the core module is in:
-
- src/edu/stanford/nlp/sempre
-
-The code for each of the other non-essential modules is in:
-
- src/edu/stanford/nlp/sempre/
-
-- core: contains all the basic code (this is kept to a minimum)
-- cache: allows us to run a cache server (implements a simple key-value store for things like SPARQL results)
-- corenlp: contains the glue code that allows us to use Stanford CoreNLP
-- freebase: needed to handle logical forms which are database queries (SPARQL, Freebase)
-
-### Java classes
-
-Here are the basic Java classes in `core`, organized by function:
-
-Logical forms:
-
-- `Formula` (`ValueFormula`, `SuperlativeFormula`, ...): logical form
-- `Derivation`: contains `Formula` and the way it was constructed
-- `SemanticFn` (`JoinFn`, `NumberFn`, ...): takes multiple `Derivation`s and combines them into one
-- `Rule`: associated with a `SemanticFn` which specifies how to combine `Derivation`s
-- `Grammar`: a set of `Rule`s
-
-Execution:
-
-- `Value` (`NameValue`, `ListValue`, ...): represents a denotation
-- `Executor` (`JavaExecutor`, `freebase.SparqlExecutor`): takes a `Formula` and returns a value
-- `ValueEvaluator` (`ExactValueEvaluator`, `freebase.FreebaseValueEvaluator`): evaluates how correct a denotation is (with respect to the correct answer)
-
-Parsing:
-
-- `Example`: specifies an utterance and a `ContextValue`
-- `LanguageAnalyzer` (`SimpleLanguageAnalyzer`, `corenlp.CoreNLPAnalyzer`): does basic linguistic analysis on an `Example`
-- `FeatureExtractor`: takes an `Example` and `Derivation` and extracts features for scoring
-- `Params`: parameters of the semantic parser
-- `Parser` (`BeamParser`, `FloatingParser`, `ReinforcementParser`): takes `Example`s and produces `Derivation`s, scoring them using `FeatureExtractor` and `Params`
-
-Learning:
-
-- `Dataset`: specifies a set of `Example`s
-- `Learner`: takes a `Dataset` and produces parameters `Params`
-
-# Logical forms
-
-There are two types of logical forms, depending on the application:
-
-- Lambda DCS logical forms for querying databases (declarative); use `freebase.SparqlExecutor`
-- Simple Java logical forms for doing everything else (procedural); use `JavaExecutor`
-
-The interpretation/denotation of a logical form depends on the `Executor` that
-is being used (specified via the `-Builder.executor` option). `Executor`s
-(i.e., classes that extend `Executor`) define how logical forms are mapped to
-denotations. `JavaExecutor` treats the logical forms as simple Java
-code and just runs it. `SparqlExecutor` treats the logical forms as lambda DCS
-expressions, which are used to query a database (e.g., via SPARQL, and e.g.,
-Freebase).
-
-Logical forms are defined recursively. In the base case, we have primitive
-formulas, which are either variables are values. In the recursive case, we
-build up larger formulas out of smaller formulas using various composition
-constructs. It is useful to think of the logical form as a tree, where the
-leaves are the primitive formulas and each non-leaf subtree as corresponpding
-to one composition operation.
-
-## Primitive logical forms
-
-### ValueFormula
-
-A `ValueFormula` is a formula that wraps a specific denotation `Value`.
-The possible `Value`s, along with an example are as follows:
-
-- `BooleanValue`: standard boolean value. For example:
-
- (boolean true)
- (boolean false)
-
-- `NumberValue`: standard floating point number with optional units. For example:
-
- (number 2)
- (number 2.5)
- (number 2.5 fb:en.meter)
-
-- `StringValue`: standard UTF-8 string. For example:
-
- (string hello)
- (string "hello")
- (string "hello world")
- (string hello\ world)
-
- Note that the first two and the last two are identical.
-
-- `DateValue`: year-month-day representation of a date. For example:
-
- (date 2014 12 21) # December 21, 2014
- (date 2014 -1 -1) # 2014
- (date -1 12 21) # December 21
- (date -1 12 -1) # December
-
- In general:
-
- (date )
-
-- `NameValue`: represents a predicate symbol (either representing an entity or relation in a knowledge base);
- the symbol has an optional description. For example:
-
- fb:en.barack_obama
- (name fb:en.barack_obama)
- (name fb:en.barack_obama "Barack Obama")
-
- all refer to the same symbol. Note: the first one is only valid as a string
- representation of a `Formula` (which represent a `Value`) — to be used
- in logical forms. The second two are valid representations of a `Value`
- — usually returned from `Executor`s.
-
-- `ListValue`: represents a list of values. For example:
-
- (list)
- (list (number 1) (number 2) (string hello))
-
- In general:
-
- (list ... )
-
-- `TableValue`: represents a table (matrix) of values, where each column has a string. Here is an example table:
-
- (table (State Capital) ((name fb:en.california) (name fb:en.sacramento)) ((name fb:en.oregon) (name fb:en.salem)))
-
- In general:
-
- (table ( ... ) ( ... ) ...)
-
-There are some more arcane `Value`s (see `Values.java` for a list), but they
-are not that important from the point of view of specifying a logical form.
-
-### VariableFormula
-
-Besides `ValueFormula`s, the other primitive formula is a `VariableFormula`,
-which represent variables in lambda expressions. An example `VariableFormula` is:
-
- (var x)
-
-which simply represents a variable with the name `x`. On their own, these
-formulas are rather uninteresting. However, they are integral subcomponents of
-`LambdaFormula`s which are described later.
-
-## Compositional logical forms
-
-Now we describe the compositional logical forms, those that allow us to
-construct larger logical forms from smaller ones.
-
-For executing simple Java programs (`JavaExecutor`), the only relevant
-composition is `CallFormula`. The rest are for building lambda DCS documents
-for execution using the `freebase.SparqlExecutor`.
-
-### CallFormula
-
-A `CallFormula` has the following form:
-
- (call ... )
-
-The `` is a string specifying any Java function and the
-`` entries are logical forms. The function is one of the following:
-
-- A static method:
-
- (call java.lang.Math.cos (number 0))
-
-- An instance method (`arg-1` is used as `this`):
-
- (call .length (string hello)) # (number 5)
- (call .indexOf (string "what is this?") (string is)) # (number 5)
-
-- A shortcut, which maps onto to a static method in `JavaExecutor.BasicFunctions`:
-
- (call < (number 3) (number 4)) # (boolean true)
- (call + (number 3) (number 4)) # (number 7)
- (call + (string 3) (string 4) (string 5)) # (string 345)
-
- Note that operator overloading is supported, and resolution is based on the
- argument types. Conditionals are supported but both true and false branches
- are evaluated:
-
- (call if (call < (number 3) (number 4)) (string yes) (string no)) # (string yes)
-
- We can perform iteration via functional programming. These list functions
- take a `ListValue` and a `LambdaFormula` as arguments:
-
- (call map (list (number 3) (number 4)) (lambda x (call * (var x) (var x)))) # (list (number 9) (number 16))
- (call select (list (number 3) (number 4)) (lambda x (call < (var x) (number 3.5))))) # (list (number 3))
- (call reduce (list (number 3) (number 4)) (lambda x (lambda y (call + (var x) (var y)))))) # (number 7)
-
- To create a list of indices:
-
- (call range (number 0) (number 3)) # (list (number 0) (number 1) (number 2))
-
- Note that the goal is not to support the ability to write arbitrarily complex
- programs using this fairly verbose language. In practice, you would write
- your own custom modules, and use these mechanisms to glue a small set of modules together.
-
-### JoinFormula
-
-Now we embark on our tour of lambda DCS logical forms. See the [lambda DCS
-documentation](http://arxiv.org/pdf/1309.4408.pdf) for a more mathematical
-description.
-
-A brief note about terminology in lambda DCS. Unaries and binaries are logical
-forms which represent sets and (binary) relations:
-
-- Unary (e.g., `(fb:type.object.type fb:people.person)`): denotes a set of entities
-- Binary (e.g., `fb:location.location.area`): denotes a set of entity-pairs (includes functions too).
- We consider the first argument the *head* and the second argument the *modifier*. For example:
-
- fb:location.location.containedby denotes {(fb:en.san_francisco, fb:en.california), ...}
- fb:people.person.place_of_birth denotes {(fb:en.barack_obama, fb:en.honolulu), ...}
- !fb:people.person.place_of_birth denotes {(fb:en.honolulu, fb:en.barack_obama), ...}
-
- The notational convention is that `!` reverses the head and modifier.
-
- In general:
-
- denotes {(, ), ...}
-
-A `JoinFormula` combines a binary with a unary:
-
- ( )
-
-This is a database join on the second argument of the binary and the unary, and
-a projection onto the first argument of the binary.
-
-Here are some examples:
-
- (fb:location.location.containedby fb:en.california)
- (!fb:people.person.place_of_birth fb:en.barack_obama)
- (fb:people.person.place_of_birth (fb:location.location.containedby fb:en.california))
-
-Sometimes, the binary is special, and the resulting logical form denotes an
-infinite set:
-
- (!= fb:en.california) # denotes entities not equal to California
- (> (number 5)) # denotes numbers greater than 5
- (STRSTARTS (string A)) # denotes strings starting with "A"
-
-Note: One might be tempted to think of `JoinFormula` as function application.
-This is sometimes valid, but one has to be very careful about which is the head
-and which is the modifier. When the binary is a `LambdaFormula`, then function
-application is generally the right mental model.
-
-### MergeFormula
-
-A `MergeFormula` combines two formulas and represents either their set
-intersection (and) or set union (or):
-
- (and )
- (or )
-
-For example, *scientists born in Seattle*:
-
- (and (fb:people.person.profession fb:en.scientist) (fb:people.person.place_of_birth fb:en.seattle))
-
-Here are *people who are born in Honolulu or Seattle*:
-
- (or (fb:people.person.place_of_birth fb:en.honolulu) (fb:people.person.place_of_birth fb:en.seattle))
-
-### NotFormula
-
-A `NotFormula` takes a formula denoting a set and denotes the complement of that set:
-
- (not )
-
-For example, *cities not in California*:
-
- (and (fb:type.object.type fb:location.citytown) (not (fb:location.location.containedby fb:en.california)))
-
-### AggregateFormula
-
-An `AggregateFormula` takes a formula representing a set and performs some operation. The general form is:
-
- ( )
-
-where `` defines the type of aggregation to be performed while
-`` denotes/defines the set that we are aggregating over. The possible
-modes (with their corresponding semantics) are listed below:
-
-- `count`: Returns the cardinality of a set.
-- `sum` : Returns the sum of the elements in the set.
-- `avg` : Returns the average/mean of the elements in the set.
-- `min` : Returns the minimum element of a set.
-- `max` : Returns the maximum element of a set.
-
-Note that the latter four modes can only be applied to logical forms denoting sets of numbers.
-
-For example, *number of people born in Honolulu*:
-
- (count (fb:people.person.place_of_birth fb:en.honolulu)) # (number 570)
-
-Here is the *maximum height of any mountain*
-
- (max (!fb:geography.mountain.elevation (fb:type.object.type fb:geography.mountain))) # (number 8848 fb:en.meter)
-
-### ArithmeticFormula
-
-An `ArithmeticFormula` combines two logical forms denoting numbers and also
-denotes a number.
-
-The form of an `ArithmeticFormula` is as follows:
-
- ( )
-
-The `` entry is either `+`, `-`, `*`, or `/`, and the two arguments
-are formulas that denote numeric values (including dates, although the support
-there is a bit sketchy). Here are some examples:
-
- (+ (number 5) (number 3)) # (number 8)
- (* (number -1) (number 3)) # (number -3)
-
-Here's how to compute the difference in height between two people:
-
- (- (!fb:people.person.height_meters fb:en.michael_jordan) (!fb:people.person.height_meters fb:en.barack_obama)) # (number 0.130 fb:en.meter)
-
-Note that we could not define these arithmetic formulas via `JoinFormula`
-because they are ternary relations rather than binary ones.
-
-### ReverseFormula
-
-A `ReversalFormula` takes a binary logical form denoting a set of head-modifier
-pairs and denotes the corresponding set of modifier-head pairs.
-
-Recall:
-
- fb:people.person.place_of_birth denotes {(fb:en.barack_obama, fb:en.honolulu), ...}
-
-The following is equivalent to `!fb:people.person.place_of_birth`:
-
- (reverse fb:people.person.place_of_birth) denotes {(fb:en.honolulu, fb:en.barack_obama), ...}
-
-But reversal can be applied to compositional binaries built using `LambdaFormula`:
-
- (reverse (lambda x (fb:people.person.places_lived (fb:people.place_lived.location (var x)))))
-
-You can check that the above is equivalent to:
-
- (lambda x (!fb:people.place_lived.location (!fb:people.person.places_lived (var x))))
-
-In both logical forms, the location is in the head position and person is in
-the modifier position.
-
-### LambdaFormula
-
-Now the serious stuff begins. Up until now, all the compositional logical
-forms were unaries (which denote sets). Lambda abstraction allows us to
-construct logical forms that denote binary, ternary, and
-other higher-order relations.
-
-The general form includes a variable and body formula which uses the variable:
-
- (lambda )
-
-If the body is a unary, then the resulting logical form is a binary, where the
-unary represents the head and the variable represents the modifier. Let us see some examples.
-
-The first one is equivalent to `fb:people.person.place_of_birth`:
-
- (lambda x (fb:people.person.place_of_birth (var x)))
-
-This logical form denotes a binary relation where the head is the person and
-the modifier is the location:
-
- (lambda x (fb:people.person.places_lived (fb:people.place_lived.location (var x))))
-
-The more complex (but very useful) example represents a binary where the head
-is a person and the modifier is the number of children the person has:
-
- (reverse (lambda x (count (!fb:people.person.children (var x))))) denotes {(fb:en.barack_obama, 2), ...}
-
-#### Macro substitution
-
-Another more syntactic view of `LambdaFormula`s is that they are just logical
-forms with holes. In this case, a `JoinFormula` where the binary is a
-`LambdaFormula` performs macro substitution. Here is an example of a join
-of a `LambdaFormula` binary and an unary:
-
- ((lambda x (fb:people.person.places_lived (fb:people.place_lived.location (var x)))) fb:en.seattle)
-
-In the macro substitution view, the variable `x` becomes bound to `fb:en.seattle`, and the resulting logical form is:
-
- (fb:people.person.places_lived (fb:people.place_lived.location fb:en.seattle))
-
-which is equivalent. This process is called beta-reduction. But one must
-exercise care, since the macro substitution view and the original higher-order
-relation view are different. Consider:
-
- ((lambda x (and (!fb:people.person.place_of_birth (var x)) (!fb:people.deceased_person.place_of_death (var x)))) (fb:type.object.type fb:people.person))
-
-In the higher-order relation view, the binary relates locations (head) to
-people (modifier). The resulting logical form denotes the set of locations
-which are both the place of birth and place of death of some person. However,
-if we do macro substitution, then we get the set of locations which are either
-the place of birth of someone or the place of death of someone (possibly
-different).
-
-Macro substitution is triggered by explicit beta reduction (see `JoinFn` with
-`betaReduce` below), and this is typically during the intermediate steps of
-constructing logical forms.
-
-We can construct logical forms that have more than one argument:
-
- (lambda binary (lambda unary ((var binary) (var unary))))
-
-We can apply this ternary logical form to two arguments,
-
- (((lambda binary (lambda unary ((var binary) (var unary)))) fb:people.person.place_of_birth) fb:en.seattle)
-
-which after beta reduction results in the very mundane
-
- (fb:people.person.place_of_birth fb:en.seattle)
-
-In lambda DCS, all logical forms are either unaries or binaries. Ternaries and
-beyond are exclusively used for macro substitution to construct logical forms
-in a controlled compositional way.
-
-### SuperlativeFormula
-
-A `SuperlativeFormula` formula takes a unary denoting a set and a binary
-denoting a relation between elements of that set (head) and a number
-(modifier), and denotes a set representing extreme elements based on the
-relation.
-
-Here is the general form:
-
- ( )
-
-The different pieces are as follows:
-
-- `` is either `argmin` or `argmax`
-- `` is an integer indicating the offset in the sorted list of the entities
-- `` specifies the number of elements to return
-- `` is the base set that we're drawing from
-- `` specifies the relation by which we sort the elements
-
-Here is *the city with the largest area*:
-
- (argmax 1 1 (fb:type.object.type fb:location.citytown) fb:location.location.area)
-
-The *second largest city by area*:
-
- (argmax 2 1 (fb:type.object.type fb:location.citytown) fb:location.location.area)
-
-The *five largest cities by area*:
-
- (argmax 1 5 (fb:type.object.type fb:location.citytown) fb:location.location.area)
-
-The *person who has the most number of children* (who, in Freebase, turns out
-to be Chulalongkorn with a whopping 62):
-
- (argmax 1 1 (fb:type.object.type fb:people.person) (reverse (lambda x (count (!fb:people.person.children (var x))))))
-
-### MarkFormula
-
-In a way, `MarkFormula` essentially allows us to do anaphora. If we think of
-simple lambda DCS (joins and merges) as producing tree-structured logical
-forms, `MarkFormula` allows us to have non-tree edges between the root of a
-subtree and a node in that subtree.
-
-Recall `LambdaFormula` creates a binary from a unary. A `MarkFormula` creates
-a unary from a unary, which simply binds the body unary to the variable (which
-appears in the body).
-
-The general form:
-
- (mark )
-
-Here is *those whose place of birth is the same as their place of death*:
-
- (mark x (fb:people.person.place_of_birth (!fb:people.deceased_person.place_of_death (var x))))
-
-Note that `x` binds to the head of `fb:people.person.place_of_birth`,
-representing the person in question. This allows us to use this head again
-deeper in the logical form. Here's a pictorial representation:
-
- x -- [fb:people.person.place_of_birth] --> ?
- ? -- [!fb:people.deceased_person.place_of_death] --> x
-
-where `?` denotes an unnamed intermediate variable.
-
-# Semantic functions
-
-From the tutorial, recall that a grammar is a set of rules of the following
-form:
-
- (rule ( ... ) )
-
-Basically, these rules specify how derivations belonging to the source categories are combined
-into derivations that correspond to the target category.
-Semantic functions are the workhorses of these rules:
-they take in a set of source derivations and apply transformations (defined via Java code) on these derivations
-in order to produce a derivation that is a member of the target category.
-
-Since semantic functions are built from arbitrary Java code (any class extending `SemanticFn`), there is a great deal of flexibility,
-and knowing how to properly use semantic functions is perhaps the most important step in working with SEMPRE.
-This section defines the semantic functions that come pre-packaged with SEMPRE.
-In all likelihood, these semantic functions will provide all the functionality that you need.
-
-Some of these semantic functions will rely on other packages/classes/options being used/set in order to function properly.
-For example, many semantic functions require that the Stanford CoreNLP package is loaded (via the `-languageAnalyzer corenlp.CoreNLPAnalyzer` option);
-this package contains many general purpose NLP algorithms that extract linguistic information (e.g., parts of speech) from utterances.
-Dependences on packages such as CoreNLP will be noted when necessary.
-
-## Special categories:
-
-Some special categories that you should now in order to effectively write grammars and use semantic functions:
-
-- `$TOKEN`: selects a single atomic word from the utterance.
-- `$PHRASE`: selects any subsequence of tokens/words from the utterance.
-- `$LEMMA_TOKEN`: selects any atomic word from the utterance and lemmatizes the word. For example, "arriving" would become "arrive".
-- `$LEMMA_PHRASE`: selects any subsequence of tokens/words and lemmatizes them.
-
-Both of the special categories that rely on lemmatization will only function
-properly if the `corenlp.CoreNLPAnalyzer` is loaded. Otherwise, the
-lemmatization will simply amount to making everything lowercase.
-
-There are two broad informal classes of semantic functions: primitive semantic
-functions and compositional semantic functions. The primitive ones take
-phrases in the natural language utterance, filters them, and produces some
-derivation generally with a simple logical form. The compositional ones take
-these simple derivations and combines them into larger derivations,
-usually generating larger logical forms.
-
-## Primitive semantic functions
-
-Primitives are basic semantic functions that directly map spans (i.e., subsequences) of an utterance to logical forms.
-Most grammars will rely on primitives as the "bottom" rules, i.e., the rules that have some span of the utterance as their right hand side (RHS)
-and which will other rules build off of.
-
-### ConstantFn
-
-This is a basic primitive function which allows for you to hard-code basic rules, such as
-
- (rule $ROOT (barack obama) (ConstantFn fb:en.barack_obama fb:people.person))
-
-which would parse the following utterance into its corresponding entity (i.e., logical form):
-
- barack obama # (name fb:en.barack_obama)
-
-Note the form that `ConstantFn` takes, i.e. `(ConstantFn formula type)`, and that the `type` argument is optional, meaning that
-
- (rule $ROOT (barack obama) (ConstantFn fb:en.barack_obama))
-
-would also parse the above utterance.
-However, note that if types are not explicitly added, the system relies on automatic type inference (see the section on Types below).
-
-Another example of `ConstantFn` would be the following:
-
- (rule $ROOT (born in) (ConstantFn fb:people.person.place_of_birth (-> fb:location.location fb:people.person))))
-
-which would parse the phrase `born in` to a relation/binary logical form (as opposed to an entity) as follows:
-
- born in # (name fb:people.person.place_of_birth)
-
-Lastly, note that in both these cases the parsed logical form is prefixed with `name`.
-This denotes that the logical form has a `NameValue` denotation, which simply means that it represents a logical predicate/entity
-and not some other primitive (e.g., a `NumberValue` or `DateValue`).
-
-### SimpleLexiconFn (reliant on having a SimpleLexicon)
-
-This function allows you to map phrases/tokens to logical entities in a more scalable manner than hard-coding everything with `ConstantFn` directly in your grammar.
-Suppose you have a `SimpleLexicon` loaded from a JSON file containing the entries:
-
- {'lexeme' : 'barack obama', 'formula' : 'fb:en.barack_obama', 'type' : 'fb:people.person'}
- {'lexeme' : 'born in', 'formula' : 'fb:people.person.place_of_birth', 'type' : '(-> fb:location.location fb:people.person)'}
-
-then the rule
-
- (rule $ROOT ($PHRASE) (SimpleLexiconFn (type fb:people.person)))
-
-will parse the following:
-
- barack obama # (name fb:en.barack_obama)
-
-and the rule
-
- (rule $ROOT ($PHRASE) (SimpleLexiconFn (type (-> fb:location.location fb:people.person))))
-
-will parse
-
- born in # (name fb:people.person.place_of_birth)
-
-Thus, the function of `SimpleLexiconFn` is similar to `ConstantFn`, but it facilitates more modularity
-since the lexical items are contained within the `SimpleLexicon` (loaded from a JSON) instead of being hard-coded into the grammar.
-
-In the above examples, this type annotation is not particularly important, but consider the case where we have the following lexical entries:
-
- {"lexeme" : "Lincoln", "formula" : "fb:en.abraham_lincoln", "type" : "fb:people.person"}
- {"lexeme" : "Lincoln", "formula" : "fb:en.lincoln_nevada", "type" : "fb:location.location"}
-
-Both of these lexical entries have the same trigger phrase (i.e., lexeme).
-However, they correspond to very distinct entities (one is a former president, while the other is a city in Nevada).
-By leveraging the type annotation, we can specify which entity we actually want to trigger.
-For example, the rule
-
- (rule $ROOT ($PHRASE) (SimpleLexiconFn (type fb:location.location)))
-
-would ensure that we only trigger the entity that corresponds to the city.
-Alternatively, if we wanted both entities to be triggered (e.g., if type-checking later on will handle the ambiguity),
-then we could write:
-
- (rule $ROOT ($PHRASE) (SimpleLexiconFn (type fb:type.any)))
-
-### NumberFn (partially reliant on the CoreNLPAnalyzer)
-
-`NumberFn` is the basic primitive function for parsing numbers from an utterance.
-For example,
-
- (rule $ROOT (NumberFn))
-
-would parse the following strings into the following logical forms:
-
-
- 2.3 # (number 2)
- four # (number 4)
- 3 million # (number 3000000)
-
-The last one works only if `-languageAnalyzer corenlp.CoreNLPAnalyzer` is set.
-
-### DateFn (reliant on the CoreNLPAnalyzer)
-
-`DateFn` is the basic primitive function for parsing date values.
-For example,
-
- (rule $ROOT (DateFn))
-
-would parse the following strings into the following logical forms:
-
- Thursday, December 4th # (date -1 12 4)
- The 12th of Nov, 2012 # (date 2012 11 12)
- August # (date -1 8 -1)
-
-Note that the logical representation of dates here (defined in the `DateValue` class) is distinct from Java's date (or JodaTime etc.)
-and that only dates not times are represented.
-The logical form representation of a `DateValue` is simply `(date year month day)`, with one-based indexing for the months.
-The above examples also illustrate how missing aspects of dates are treated:
-if any part of a date (day, month, or year) is left unspecified, then the `DateValue` logical representation inserts -1s in those positions.
-
-## Filtering semantic functions
-
-You might find that your grammar is generating far too many candidate
-derivations, resulting in the correct derivations falling off the beam. After
-all, the number of derivations does tend to grow exponentially with the
-sentence length.
-
-The semantic functions described below help to ameliorate this issue by
-allowing you to filter down the phrases that are considered. In other words,
-they help control how many logical forms you generate by allowing you to
-specify more precise situations in which rules should fire.
-
-This is particularly important when your lexicon (like our EMNLP 2013 system)
-contains a lot of noisy entries.
-
-### FilterSpanLengthFn
-
-This semantic function allows you to filter out the length of spans that you trigger on. For example,
-
- (rule $Length2Span ($PHRASE) (FilterSpanLengthFn 2))
-
-produces a new category `$Length2Span` which contains only phrases of length 2,
-which is useful for limiting the number of phrases you compute on.
-For instance, we could combine this with the simple lexicon function we used above and say
-
- (rule $ROOT ($Length2Span) (SimpleLexiconFn (type fb:type.any)))
-
-and this would parse
-
- barack obama # (name fb:en.barack_obama)
-
-but would make running the grammar faster than if we replaced `$Length2Span` with `$PHRASE`, since `$PHRASE` will try all possible lengths,
-and we know that our lexicon only contains length 2 phrases.
-
-### FilterPosTagFn (relies on CoreNLPAnalyzer)
-
-`FilterPosTagFn` allows you to extract spans or tokens that are composed only of certain parts of speech (POS) tags.
-For example,
-
- (rule $ProperNoun ($TOKEN) (FilterSpanPosTag token NNP NNPS))
-
-produces a new category `$ProperNoun` which contains words that are proper nouns.
-This would accept phrases like:
-
- honolulu
- obama
-
-and assign them to the `$ProperNoun` category.
-
-Note the options that are passed: `token` specifies that we want to look at single tokens and `NNP NNPS` are the POS tags for proper nouns.
-If you wanted to get multi-word proper nouns then you would use
-
- (rule $ProperNounPhrase ($PHRASE) (FilterSpanPosTag span NNP NNPS))
-
-Note that we both changed the RHS category to `$PHRASE` and changed the `token` option to `span`.
-This would accept things like
-
- honolulu hawaii
- barack obama
-
-but note that the entire span must have the same POS tag (that is in one of the accepted categories).
-Also, it will only accept the maximal span, meaning that `barack obama` will NOT be parsed three times as `barack`, `obama`, and `barack obama`.
-
-Note also that, unlike the previous examples for simpler semantic functions, the logical form is not written out next to the phrases.
-This is because the above rule to does not rewrite to `$ROOT` (i.e., it does not have `$ROOT` as a LHS),
-and thus, this rule would accept the example phrases above, but it does not parse them directly to a logical form.
-Other rules which take `$ProperNounPhrase` as a RHS are necessary to complete a grammar with this rule.
-Most of the filtering functions discussed below will also have this flavor.
-
-### FilterNerSpanFn (relies on CoreNLPAnalyzer)
-
-This `SemanticFn` allows you to extract spans that are named entities (NEs).
-For example,
-
- (rule $Person ($Phrase) (FilterNerSpan PERSON))
-
-produces a new category (`$Person`) which contains phrases that the CoreNLPAnalyzer labels as referring to people.
-This would accept phrases like
-
- barack obama
- michelle obama
-
-Note that unlike our earlier examples where we parsed these phrases corresponding to an entity/person,
-the LHS side of our rule in this case is a new category `$Person`.
-The idea is that you would use this new category to restrict what you apply rules on further up in the derivation.
-For example, you may want to change our earlier `SimpleLexiconFn` example rule to
-
- (rule $ROOT ($Person) (SimpleLexiconFn (type fb:people.person)))
-
-since you know that this rule should be restricted to spans that may contain a mention of a person.
-
-### ConcatFn
-
-This function allows you to concatenate strings, giving you more fine-grained control over how categories are constructed over spans,
-which is useful for doing things that are not possible with the other filter functions.
-Concretely, say you wanted to look for spans of the utterance that may correspond to binaries,
-you would probably want to look at verbs (e.g., "lived", "born").
-However, triggering only on verbs is too restrictive; for example, some binaries take their meaning from verb-preposition pairs.
-In fact, the example of "born in" used previously is exactly such a phrase.
-In order to handle this case, we could use `ConcatFn` with the following rules:
-
- (rule $Verb ($TOKEN) (FilterSpanPosTag token VB VBD VBN VBG VBP VBZ))
- (rule $Prep ($TOKEN) (FilterSpanPosTag token IN))
- (rule $VerbPrep ($Verb $Prep) (ConcatFn " "))
-
-These rules would create a new category (`$VerbPrep`) that contains two word phrases consisting of a verb followed by a preposition.
-One way we could leverage this category would be with a rule that uses `SimpleLexiconFn`, such as the following:
-
- (rule $Relation ($VerbPrep) (SimpleLexiconFn (type (-> fb:type.any fb:type.any))))
-
-This rule basically says that when we look for binaries, we shouldn't look at any phrase, we should restrict to phrases consisting
-of verbs followed by prepositions.
-Of course, there are other grammatical constructions that could give rise to a binary, and you would need to add new rules/categories for these.
-Nevertheless, using filtering to narrow down to the spans which trigger certain rules is a very powerful tool.
-
-## Compositional semantic functions
-
-Compositional semantic functions are used to create larger derivations from
-smaller ones.
-
-It is important to distinguish these semantic functions, which also work
-compositionally, from the definition of the recursive definition of logical
-forms in the previous section. One semantic function could easily construct a
-logical form that involved multiple logical compositions, for example, going
-from *city* (`fb:location.citytown`) to *largest city* (`(argmax 1 1
-(fb:type.object.type fb:location.citytown) fb:location.location.area)`).
-
-### IdentityFn
-
-`IdentityFn` takes a logical form and returns the same logical form.
-
-This is the most basic composition function, useful for refactoring grammar categories.
-For example, suppose you have the following rule that parses things into entities.
-
- (rule $Entity ...)
-
-You can then write:
-
- (rule $ROOT ($Entity) (IdentityFn))
-
-### JoinFn
-
-`JoinFn` can be used in a number of different ways.
-
-#### Joining binaries and unaries
-
-The first way in which `JoinFn` combines a binary and a unary is as follows.
-Recall that each binary (e.g., `fb:people.person.place_of_birth`) has a head
-(also called arg0 or return) and modifier (also called arg1 and argument).
-
-Just for clarity, the concrete edge in the knowledge graph is:
-
- head -- [fb:people.person.place_of_birth] --> modifier
-
-and the type of `fb:people.person.place_of_birth` is
-
- (-> modifier_type head_type)
-
-The way to think about a binary is not a function that returns the places of
-births of people, but rather as a relation connecting people (in the head
-position) with locations (in the modifier position).
-
-When applying `JoinFn`, the unary can be joined with either `arg0` or `arg1`,
-and either the binary can come before the unary in the sentence or vice-versa.
-Thus, there are four ways in which a binary may be joined with a unary.
-These four possibilities are defined via the following two options:
-
- - Ordering: either `binary,unary` or `unary,binary`
- - Position: `unaryCanBeArg0` or `unaryCanBeArg1` or both
-
-To illustrate the two most common settings for these options,
-suppose we have the following setup:
-
- (rule $Entity (barack obama) (ConstantFn fb:en.barack_obama))
- (rule $Entity (honolulu) (ConstantFn fb:en.honolulu))
- (rule $Binary (birthplace) (ConstantFn fb:people.person.place_of_birth))
-
-then we can write
-
- (rule $ROOT ($Binary $Entity) (JoinFn binary,unary unaryCanBeArg1))
-
-These rules will parse the following utterance as follows:
-
- birthplace honolulu # (fb:people.person.place_of_birth fb:en.honolulu)
-
-This corresponds to standard forward application of a binary, and indeed we can
-equivalently write:
-
- (rule $ROOT ($Relation $Entity) (JoinFn forward))
-
-Alternatively, we can alter the arguments and write
-
- (rule $ROOT ($Entity $Relation) (JoinFn unary,binary unaryCanBeArg1))
-
-or equivalently
-
- (rule $ROOT ($Entity $Relation) (JoinFn backward))
-
-and this will parse the following into the same logical form:
-
- honolulu birthplace # (fb:people.person.place_of_birth fb:en.honolulu)
-
-If we use
-
- (rule $ROOT ($Relation $Entity) (JoinFn binary,unary unaryCanBeArg0))
-
-we can parse:
-
- birthplace barack obama # (!fb:people.person.place_of_birth fb:en.barack_obama)
-
-#### Macro substitution
-
-The second way to use `JoinFn` is as macro substitution. Simply add the
-`betaReduce` flag. For example:
-
- (rule $LambdaRelation (birthplace) (ConstantFn (lambda x (!fb:people.person.place_of_birth (var x)))))
- (rule $ROOT ($LambdaRelation $Entity) (JoinFn forward betaReduce))
-
-This will parse:
-
- birthplace barack obama # (!fb:people.person.place_of_birth fb:en.barack_obama)
-
-#### Multi-argument macro substitution
-
-So far, `JoinFn` takes two arguments, but we can also specify one of the arguments:
-
- (rule $ROOT (birthplace $Entity) (JoinFn forward betaReduce (arg0 (lambda x (!fb:people.person.place_of_birth (var x))))))
-
-This rule also parses *birthplace barack obama* in the expected way. An
-equivalent and much clearer way to write this is the following, where we omit
-`JoinFn` completely:
-
- (rule $ROOT (birthplace $Entity) (lambda x (!fb:people.person.place_of_birth (var x))))
-
-Here is another example that takes multiple arguments and forms the set
-containing two entities:
-
- (rule $ROOT ($Entity and $Entity) (lambda x (lambda y (or (var x) (var y)))))
-
-Going forward, you are encouraged to use this last form since it is most
-transparent. In the future, it might even be backed by another `SemanticFn`
-since `JoinFn` is getting a bit out of hand.
-
-### MergeFn
-
-`MergeFn` simply constructs a `MergeFormula`. For example, consider the
-following rules:
-
- (rule $Set (female) (ConstantFn (fb:people.person.gender fb:en.female)))
- (rule $Set (scientist) (ConstantFn (fb:people.person.profession fb:en.scientist)))
- (rule $Set ($Set $Set) (MergeFn and))
-
-We could then parse:
-
- female scientist # (and (fb:people.person.gender fb:en.female) (fb:people.person.profession fb:en.scientist))
-
-We can also use the following rule
-
- (rule $Set ($Set or $Set) (MergeFn or))
-
-to do set union:
-
- female or scientist # (or (fb:people.person.gender fb:en.female) (fb:people.person.profession fb:en.scientist))
-
-### SelectFn
-
-`SelectFn` acts as a utility composition function that aids in refactoring grammars.
-More specifically, it can be used to skip over certain categories or parts of an utterance (e.g., stop words) in a controlled manner.
-For example, in a question-answering setup, you may have many utterances that
-start with the word "what" (or "who" etc.), but suppose this word does not
-really convey any semantic content (this is not quite true).
-To handle this,
-
- (rule $Wh (what) (ConstantFn null))
- (rule $Wh (who) (ConstantFn null))
- (rule $ROOT ($Wh $Set) (SelectFn 1))
-
-These rules allow us to simply ignore the presence of *what* or *who*.
-
-### Freebase-specific semantic functions
-
-There are two semantic functions, `freebase.LexiconFn` and `freebase.BridgeFn`
-which are used in our first sematic parsing applications, but they probably
-should be avoided unless you're specifically doing Freebase QA. Even in that
-case, the main thing you should think about is:
-
- (rule $Entity ($PHRASE) (LexiconFn fbsearch))
-
-which uses the Freebase Search API to look up entities. Be aware here that the
-API will generously return many candidate entities for any string you give it,
-so if you are getting too many results, you should use filtering to constrain
-the number of spans you look at.
-
-### Context-specific semantic functions
-
-`FuzzyMatchFn` is used for matching words with a context-specific graph.
-More documentation coming soon.
-
-#### ContextFn
-
-`ContextFn` generates logical forms from the context.
-Concretely, an `Example` optionally has an associated `ContextValue`, which contains an ordered list of `n` `Exchange`s.
-Each `Exchange` contains an utterance, a logical form (i.e., a `Formula`), and its denotation (i.e., a `Value`).
-
-A `ContextValue` thus represents information that is known prior to parsing the utterance in an `Example`.
-For example, when running SEMPRE in interactive mode, the `ContextValue`
-contains information about the last (`n`) utterance(s) that was/were parsed.
-`ContextValue`s can also be provided in a dataset.
-
-`ContextFn` can be used to resolve anaphora.
-For example, suppose you are running SEMPRE in interactive mode:
-
- User: where has barack obama lived
- System: ((fb:people.person.places_lived fb:en.barack_obama)
-The `ContextValue` of the interactive system now contains an `Exchange` corresponding to this utterance, logical form, and the computed denotation,
-i.e. a list of cities including `fb:en.honolulu` and `fb:en.washington_dc`.
-(Note that by default only one `Exchange`, specifically the most recent one, is stored in the system's `ContextValue`).
-
-Now, suppose that the you then say: `where was he born`.
-Parsing this utterance requires resolving the anaphoric reference `he`, and `ContextFn` facilitates this.
-Specifically, we would make the following rule:
-
- (rule $ContextEntity (he) (ContextFn (depth 0) (type fb:people.person)))
-
-This rule will trigger on the word `he` and retrieve the unary `fb:en.barack_obama` from the logical
-formula in the `ContextValue` (since it has type `fb:people.person`).
-The `depth` argument specifies how deep/tall of a logical form subtree you want to retrieve.
-In the above example, a depth of 0 was specified since we wanted to retrieve a
-single bare entity (i.e., a leaf).
-
-Alternatively, you could have said: `and which of those cities is the biggest?`.
-Here, we would want to essentially "pull out" the entire logical form from the context.
-Or more specifically, we want to pull out the join of the `fb:people.person.places_lived` binary and the `fb:en.barack_obama` entity.
-To do this, we could make the following rule:
-
- (rule $ContextSetFromJoin (those cities) (ContextFn (depth 1) (type fb:places_lived)))
-
-This rule would trigger on the phrase `those cities` and retrieve the logical form `(fb:people.person.places_lived fb:en.barack_obama)`.
-Note that compared to the previous example, we changed both the type and the depth arguments.
-Here, a depth of 1 indicated that we want a subtree of depth 1 (i.e., a tree with one level before the leaves),
-which corresponds, for example, to a logical form resulting from a single join.
-
-# Grammar
-
-So far, we have talked about grammars as being a set of rules. But SEMPRE
-`Grammar`s have additional supporting functionality which make it easier to
-use. A grammar is specified in a `.grammar` file and is loaded by the
-command-line flag `-Grammar.inPaths`.
-
-## Binarization
-
-First, the `Grammar` performs automatic binarization of the grammar, so if you have a rule:
-
- (rule $ROOT ($Subject $Verb $Object) ...)
-
-This rule gets converted to a binarized grammar where each right-hand-side has at most two elements:
-
- (rule $ROOT ($Subject $Intermediate) ...)
- (rule $Intermediate (Verb $Object) ...)
-
-The consequence is that the grammar you write will not be exactly the same as
-the grammar that the parser receives.
-
-## Macros
-
-If you find yourself writing a lot of repeated elements:
-
- (rule (person) (ConstantFn (fb:type.object.type fb:people.person)))
- (rule (place) (ConstantFn (fb:type.object.type fb:location.location)))
- (rule (location) (ConstantFn (fb:type.object.type fb:location.location)))
-
-then you might want to use macros (which are all prefixed with `@`):
-
- (def @type fb:type.object.type)
- (def @person (@type fb:people.person))
- (def @place (@type fb:location.location))
-
-so that you can simply write the three rules as follows:
-
- (rule (person) (ConstantFn @person))
- (rule (place) (ConstantFn @location))
- (rule (location) (ConstantFn @location))
-
-The general form for defining a macro:
-
- (def @ )
-
-Note that macros cannot take arguments.
-
-## For loops
-
-If you are defining multiple rules, with small variations, then you can use for
-loops to create many rules. For example:
-
- (for @x (place location)
- (rule (@x) (ConstantFn (fb:type.object.type fb:location.location)))
- )
-
-which is equivalent to:
-
- (rule (place) (ConstantFn (fb:type.object.type fb:location.location)))
- (rule (location) (ConstantFn (fb:type.object.type fb:location.location)))
-
-The general form is:
-
- (for @ ( ... )
-
- ...
-
- )
-
-## Conditionals
-
-Grammar files do not have full conditionals (the point is not to develop a
-full-blown programming language here). But if you want a grammar which is
-parametrized by complexity, then you can use conditionals to include or exclude
-statements:
-
- (when compositional
- (rule $Set ($Set $Set) (MergeFn and))
- )
-
- (when (not compositional)
- (rule $Set ($Entity $Entity) (MergeFn and))
- )
-
-To enable the first rule (and disable the second), you would pass
-`-Grammar.tags compositional` on the command-line.
-
-In general:
-
- (when
-
- ...
-
- )
-
-where is one of the following
-
-
- (not )
- (and )
-
-## Includes
-
-You can use the statement:
-
- (include )
-
-to break up your grammar file into multiple files. It is not advisable to use
-many small files; rather use the `when` construction.
-
-# Types
-
-SEMPRE uses a type system to associate each logical form with a type, which is
-used to rule out obviously bad logical forms (e.g., `(+ fb:en.barack_obama 3)`
-or `(fb:location.location.containedby fb:en.barack_obama)`).
-
-Types are in a sense redundant with the grammar categories (we could very well
-use `$Int` to capture only logical forms that compute integers. But there are
-a few differences:
-
-- Categories could be based on how the natural language, whereas types are a
- pure function of the logical forms (e.g., `$Preposition` and `$Verb` might
- both generate logical forms that map to the type `(-> fb:type.any
- fb:type.any)`.
-
-- The parser can handle categories efficiently (e.g., for coarse-to-fine
- parsing); it is not necessary to compute the logical form. Types only exist
- with logical forms.
-
-Each type is an instance of `SemType`.
-
-## Atomic types (`AtomicSemType`)
-
-All the **atomic types** are related via a partial ordering (the subtype
-relation), which is easiest to think of as a tree structure:
-
- | fb:type.any
- | | fb:type.boolean
- | | fb:type.number
- | | | fb:type.int
- | | | fb:type.float
- | | fb:type.datetime
- | | fb:type.text
- | | fb:common.topic
- | | | fb:people.person
- | | | fb:location.location
- | | | ...
-
-Atomic types can be combined to create higher-order types:
-
-## Pair types (`FuncSemType`)
-
-A **pair type** looks like this:
-
- (-> )
-
-and is generally used to represent a binary relation, such as
-`fb:people.person.place_of_birth`:
-
- (-> fb:location.location fb:people.person)
-
-This type might seem a bit backwards, but it is important to remember that we
-should think of binaries not as functions but as relations.
-
-In fact, the pair type looks like a function, but really behaves like a pair
-type (this is more appropriate for database queries and makes it easier to
-reason about).
-
-## Union types (`UnionSemType`)
-
-A **union type** represent a disjunction over many types:
-
- (union ... )
-
-Note that `(union fb:type.int fb:type.float)` is a supertype of `fb:type.int`.
-
-## Special types
-
-- Top type (top): corresponds to the most general type (including all atomic
- and function types).
-
-- Bottom type (bot): corresponds to type failure.
-
-## Other notes
-
-Some of these types are inherited from Freebase (e.g., `fb:type.float`), but
-others are SEMPRE-specific and made in the spirit of the Freebase names.
-Identifiers begin with `fb:` even if you are working with an application which
-has little to do with Freebase, just for notational compatibility.
-
-Types are assigned to logical forms via type inference (class `TypeInference`
-in SEMPRE), and are importantly not part of the logical form itself. This
-gives us the flexibility of experimenting with different type systems without
-actually changing the meaning. Type inference in general is computationally
-expensive, so the default implementation of `TypeInference` sometimes just
-punt.
-
-The main operation one can perform with two types is to compute their *meet*,
-which is the most general type which is the superset of both types. For example:
-
- (-> fb:location.location fb:type.any) meet (-> top fb:people.person)
-
-is
-
- (-> fb:location.location fb:people.person)
-
-# Running SEMPRE
-
-The main entry point to SEMPRE is `run`. Run is based on the execrunner Ruby
-library from fig, which provides a small domain-specific language for
-generating command-line options. (See `fig/lib/execrunner.rb` for more
-documentation).
-
- ./run @mode= ...
-
-The mode specifies the specific way you want to use SEMPRE.
-
-## Execution directories
-
-When you run something like `./run @mode=freebase ...`, an execution directory
-will be created in
-
- state/execs/.exec,
-
-where is a unique identifier. This directory contains the stdout in the
-`log` file, as well as the grammar and the parameters.
-
-## Web interface
-
-If you want to launch a demo, then you probably want to use the web interface,
-which can be triggered by using the `-server` option. For example:
-
- ./run @mode=simple -interactive false -server true
diff --git a/examples/lassie/sempre/LICENSE.txt b/examples/lassie/sempre/LICENSE.txt
deleted file mode 100644
index 49f81325f3..0000000000
--- a/examples/lassie/sempre/LICENSE.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-Copyright (c) 2013, Stanford University.
-
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software distributed
-under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
diff --git a/examples/lassie/sempre/README.md b/examples/lassie/sempre/README.md
deleted file mode 100644
index 64dba683e4..0000000000
--- a/examples/lassie/sempre/README.md
+++ /dev/null
@@ -1,188 +0,0 @@
-# SEMPRE 2.4: Semantic Parsing with Execution
-
-## What is semantic parsing?
-
-A semantic parser maps natural language utterances into an intermediate logical
-form, which is "executed" to produce a denotation that is useful for some task.
-
-A simple arithmetic task:
-
-- Utterance: *What is three plus four?*
-- Logical form: `(+ 3 4)`
-- Denotation: `7`
-
-A question answering task:
-
-- Utterance: *Where was Obama born?*
-- Logical form: `(place_of_birth barack_obama)`
-- Denotation: `Honolulu`
-
-A virtual travel agent task:
-
-- Utterance: *Show me flights to Montreal leaving tomorrow.*
-- Logical form: `(and (type flight) (destination montreal) (departure_date 2014.12.09))`
-- Denotation: `(list ...)`
-
-By parsing utterances into logical forms, we obtain a rich representation that
-enables much deeper, context-aware understanding beyond the words. With the
-rise of natural language interfaces, semantic parsers are becoming increasingly
-more powerful and useful.
-
-## What is SEMPRE?
-
-SEMPRE is a toolkit that makes it easy to develop semantic parsers for new
-tasks. The main paradigm is to learn a feature-rich discriminative semantic
-parser from a set of utterance-denotation pairs. One can also quickly
-prototype rule-based systems, learn from other forms of supervision, and
-combine any of the above.
-
-If you use SEMPRE in your work, please cite:
-
- @inproceedings{berant2013freebase,
- author = {J. Berant and A. Chou and R. Frostig and P. Liang},
- booktitle = {Empirical Methods in Natural Language Processing (EMNLP)},
- title = {Semantic Parsing on {F}reebase from Question-Answer Pairs},
- year = {2013},
- }
-
-SEMPRE has been used in the following papers:
-
-- J. Berant and A. Chou and R. Frostig and P. Liang. [Semantic parsing on
- Freebase from question-answer
- pairs](http://cs.stanford.edu/~pliang/papers/freebase-emnlp2013.pdf). EMNLP,
- 2013.
- This paper introduced SEMPRE 1.0, applied it to question answering on
- Freebase, and created the WebQuestions dataset. The paper focuses on scaling
- up semantic parsing via alignment and bridging, and does not talk about the
- SEMPRE framework at all. To reproduce those results, check out SEMPRE 1.0.
-- J. Berant and P. Liang. [Semantic Parsing via
- Paraphrasing](http://cs.stanford.edu/~pliang/papers/paraphrasing-acl2014.pdf).
- ACL, 2014.
- This paper also used SEMPRE 1.0. The paraphrasing model is somewhat of a
- offshoot, and does not use many of the core learning and parsing utiltiies in
- SEMPRE. To reproduce those results, check out SEMPRE 1.0.
-
-Please refer to the [project page](https://nlp.stanford.edu/software/sempre/) for a more complete list.
-
-## Where do I go next?
-
-- If you're new to semantic parsing, you can learn more from the [background
- reading section of the tutorial](TUTORIAL.md).
-- Install SEMPRE using the instructions under **Installation** below.
-- Walk through the [tutorial](TUTORIAL.md)
- to get a hands-on introduction to semantic parsing through SEMPRE.
-- Read the complete [documentation](DOCUMENTATION.md)
- to learn about the different components in SEMPRE.
-
-# Installation
-
-## Requirements
-
-You must have the following already installed on your system.
-
-- Java 8 (not 7)
-- Ant 1.8.2
-- Ruby 1.8.7 or 1.9
-- wget
-- make (for compiling fig and Virtuoso)
-- zip (for unzip downloaded dependencies)
-
-Other dependencies will be downloaded as you need them. SEMPRE has been tested
-on Ubuntu Linux 12.04 and MacOS X. Your mileage will vary depending on how
-similar your system is.
-
-## Easy setup
-
-1. Clone the GitHub repository:
-
- git clone https://github.com/percyliang/sempre
-
-2. Download the minimal core dependencies (all dependencies will be placed in `lib`):
-
- ./pull-dependencies core
-
-3. Compile the source code (this produces `libsempre/sempre-core.jar`):
-
- ant core
-
-4. Run an interactive shell:
-
- ./run @mode=simple
-
- You should be able to type the following into the shell and get the answer `(number 7)`:
-
- (execute (call + (number 3) (number 4)))
-
-To go further, check out the [tutorial](TUTORIAL.md) and then the [full
-documentation](DOCUMENTATION.md).
-
-## Virtuoso graph database
-
-If you will be using natural language to query databases (e.g., Freebase), then
-you will also need to setup your own Virtuoso database (unless someone already
-has done this for you):
-
-For Ubuntu, follow this:
-
- sudo apt-get install -y automake gawk gperf libtool bison flex libssl-dev
-
- # Clone the repository
- ./pull-dependencies virtuoso
-
- # Make and install
- cd virtuoso-opensource
- ./autogen.sh
- ./configure --prefix=$PWD/install
- make
- make install
- cd ..
-
-on OS/X you can install virtuoso using homebrew by following the instructions
-[here](http://carsten.io/virtuoso-os-on-mac-os/)
-
-To have SEMPRE interact with Virtuoso, the required modules need to be compiled as follow:
-
- ./pull-dependencies core corenlp freebase
- ant freebase
-
-# Contribute
-
-To contribute code or resource to SEMPRE:
-
-- Create a fork of the repository. If you already have a fork,
- it is a good idea to sync with the upstream repository first.
-- Push your changes to a new branch in your fork.
-- Start a pull request: go to your branch on the GitHub website,
- then click "New pull request". Please specify the `develop` branch
- of the upstream repository.
-
-# ChangeLog
-
-Changes from SEMPRE 1.0 to SEMPRE 2.0:
-
-- Updated tutorial and documentation.
-- Refactored into a core part for building semantic parsers in general;
- interacting with Freebase and Stanford CoreNLP are just different modules.
-- Removed fbalignment (EMNLP 2013) and paraphrase (ACL 2014) components to
- avoid confusion. If you want to reproduce those systems, use SEMPRE 1.0.
-
-Changes from SEMPRE 2.0 to SEMPRE 2.1:
-
-- Added the `tables` package for the paper *Compositional semantic parsing on semi-structured tables* (ACL 2015).
-- Add and `overnight` package for the paper *Building a semantic parser overnight* (ACL 2015).
-
-Changes from SEMPRE 2.1 to SEMPRE 2.2:
-
-- Added code for the paper *Inferring Logical Forms From Denotations* (ACL 2016).
-
-Changes from SEMPRE 2.2 to SEMPRE 2.3:
-
-- Added the `interactive` package for the paper *Naturalizing a programming language through interaction* (ACL 2017).
-
-Changes from SEMPRE 2.3 to SEMPRE 2.3.1:
-
-- Modified the `tables` module to resemble SEMPRE 2.1, effectively making it work again.
-
-Changes from SEMPRE 2.3.1 to SEMPRE 2.4:
-
-- Added the `cprune` package for the paper *Macro Grammars and Holistic Triggering for Efficient Semantic Parsing* (EMNLP 2017).
diff --git a/examples/lassie/sempre/TUTORIAL.md b/examples/lassie/sempre/TUTORIAL.md
deleted file mode 100644
index 75151e07c5..0000000000
--- a/examples/lassie/sempre/TUTORIAL.md
+++ /dev/null
@@ -1,855 +0,0 @@
-# SEMPRE 2.0 tutorial
-
-In this tutorial, we will provide a brief tour of SEMPRE. This tutorial is
-very much about the mechanics of the system, not about the linguistics or
-semantic parsing from a research point of view (for those, see the recommended
-readings at the end of this document). Once you have gone through the tutorial,
-you can read the [full documentation](DOCUMENTATION.md).
-
-We will construct a semantic parser to understand a toy subset of natural
-language. Concretely, the system we will build will have the following
-behavior:
-
-- Input: *What is three plus four?*
-- Output: 7
-
-Recall that in semantic parsing, *natural language utterances* are mapped into
-*logical forms* (think programs), which are executed to produce some
-*denotation* (think return value).
-
-We have assumed you have already [installed](README.md#installation)
-SEMPRE and can open up a shell:
-
- ./run @mode=simple
-
-This will put you in an interactive prompt where you can develop a system and
-parse utterances into tiny Java programs. Note: you might find it convenient
-to use `rlwrap` to get readline support.
-
-Just to provide a bit of transparency: The `run` script simply creates a
-shell command and executes it. To see which command is run, do:
-
- ./run @mode=simple -n
-
-This should print out:
-
- java -cp libsempre/*:lib/* -ea edu.stanford.nlp.sempre.Main -Main.interactive
-
-You can pass in additional options:
-
- ./run @mode=simple -Parser.verbose 3 # Turn on more verbose debugging for the parser
- ./run @mode=simple -help # Shows all options and default values
-
-## Section 1: Logical forms and denotations
-
-A **logical form** (class `Formula` in SEMPRE) is a hierarchical expression.
-In the base case, we have primitive logical forms for representing concrete
-values (booleans, numbers, strings, dates, names, and lists):
-
- (boolean true)
- (number 3)
- (string "hello world")
- (date 2014 12 8)
- fb:en.barack_obama
- (list (number 1) (number 2))
-
-Logical forms can be constructed recursively using `call`, which takes a
-function name followed by arguments, which are themselves logical forms:
-
- (call + (number 3) (number 4))
- (call java.lang.Math.cos (number 0))
- (call .indexOf (string "what is this?") (string is))
- (call .substring (string "what is this?") (number 5) (number 7))
- (call if (call < (number 3) (number 4)) (string yes) (string no))
-
-In general:
-
- (call ... )
-
-Later, we will see other ways (besides `call`) of building more complex logical
-forms from simpler logical forms.
-
-Note that each logical form is painfully explicit about types. You would
-probably not want to program directly in this language (baby Java using
-LISP-like notation), but that is not the point; we will later generate these
-logical forms automatically from natural language.
-
-We can execute a logical form by typing the following into the interactive
-prompt:
-
- (execute (call + (number 3) (number 4)))
-
-In general:
-
- (execute )
-
-This should print out `(number 7)`, which we refer to as the *denotation*
-(class `Value` in SEMPRE) of the logical form. Try to execute the other
-logical forms and see what you get.
-
-**Exercise 1.1**: write a logical form that computes the first word
-("compositionality") in the string "compositionality is key".
-
-### Lambda expressions
-
-So far, we have been representing logical forms that produce a single output
-value (e.g., "compositionality"). But one of the key ideas of having programs
-(logical forms) is the power of abstraction — that we can represents
-*functions* that compute an output value for each input value.
-
-For example, the following logical form denotes a function that takes a number
-and returns its square:
-
- (lambda x (call * (var x) (var x)))
-
-If you execute this logical form directly, you will get an error, because the
-denotation of this logical form is a function, which is not handled by the
-`JavaExecutor`. However, we can apply this function to an argument `(number
-3)`:
-
- ((lambda x (call * (var x) (var x))) (number 3))
-
-This logical form now denotes a number. Executing this logical form should
-yield `(number 9)`.
-
-In general:
-
- ( )
-
-**Exercise 1.2**: Adapt your logical form form Exercise 1.1 to compute the
-first word of any string. Your answer should be `(lambda x ...)`. Create a
-logical form that applies this on the argument `(string "compositionality is
-key")`.
-
-Technical note: these lambda expressions are actually just doing macro
-substitution, not actually representing higher-order functions; since there are
-no side effects here, there is no difference.
-
-This concludes the section on logical forms and denotations. We have presented
-one system of logical forms, which are executed using `JavaExecutor`. The
-system supports other types of logical forms, for example, those which encode
-SPARQL database queries for question answering (we will get to that later).
-Note that there is no mention of natural language yet...
-
-## Section 2: Parsing utterances to logical forms
-
-Having established the nature of logical forms and their denotations, let us
-turn to the problem of mapping a natural language utterance into a logical
-form. Again, the key framework is *compositionality*, which roughly says that
-the meaning of a full sentence is created by combining the meanings of its
-parts. For us, meanings are represented by logical forms.
-
-We will start by defining a **grammar** (class `Grammar` in SEMPRE), which is a
-set of **rules** (class `Rule` in SEMPRE), which specify how to combine logical
-forms to build more complex ones in a manner that is guided by the natural
-language.
-
-We will run through some examples to give you a feel for how things work,
-and then go into the details. First, let us add a rule to the grammar by
-typing the following into the interactive prompt:
-
- (rule $ROOT (three) (ConstantFn (number 3)))
-
-Now to parse an utterance, just type it in to the interactive prompt:
-
- three
-
-The parser should print out (among other information) a line that shows that
-the utterance was parsed successfully into a **derivation** (class `Derivation`
-in SEMPRE), which importantly carries the correct logical form `(number 3.0)`:
-
- (derivation (formula (number 3.0)) (value (number 3.0)) (type fb:type.number))
-
-Now type in the utterance:
-
- four
-
-You should get no results because no rule matches `four`. To fix that, let
-us create a more general rule:
-
- (rule $ROOT ($PHRASE) (NumberFn))
-
-This rule says for any phrase (sequence of consecutive tokens), pass it to a special
-function called `NumberFn`, which will transform the phrase string into a new
-derivation representing a number.
-
-Now, you can parse the following:
-
- four
- 20
-
-Note: if you now type in `three`, you should get two derivations that yield the
-same answer, one coming from each rule. Note that `twenty-five million` will
-not parse because we are using `SimpleLanguageAnalyzer`. Later, we can using
-Stanford CoreNLP to improve the basic linguistic capabilities.
-
-So far, we have only parsed utterances using one rule, but the true power of
-these grammars come from combining multiple rules. Copy and paste in the
-following rules:
-
- (rule $Expr ($PHRASE) (NumberFn))
- (rule $Operator (plus) (ConstantFn (lambda y (lambda x (call + (var x) (var y))))))
- (rule $Operator (times) (ConstantFn (lambda y (lambda x (call * (var x) (var y))))))
- (rule $Partial ($Operator $Expr) (JoinFn forward))
- (rule $Expr ($Expr $Partial) (JoinFn backward))
- (rule $ROOT ((what optional) (is optional) $Expr (? optional)) (IdentityFn))
-
-Now try typing in:
-
- What is three plus four?
-
-The output should be:
-
- (number 7)
-
-We can parse longer sentences. Type in:
-
- What is three plus four times two?
-
-There should be two derivations, yielding `(number 14)` and `(number 11)`,
-corresponding to either combining *three plus four* first or *four times two*
-first. Note that this is expected because we have not encoded any order of
-operations anywhere.
-
-Hopefully that should give you a sense of what parsing looks like. Let us now
-take a closer look. At the end of the day, a grammar declaratively specifies a
-mapping from utterances to a set of candidate derivations. A **parser** (class
-`Parser` in SEMPRE) is an actual algorithm that takes the grammar and generates
-those derivations. Recall that a derivation looks like this:
-
- (derivation (formula (number 3.0)) (value (number 3.0)) (type fb:type.number))
-
-Formally, each derivation produced by the parser has the following properties:
-
-1. Span i:j (e.g., 0:1): specifies the contiguous portion of the input
- utterance (tokens i to j-1) that the Derivation is constructed from.
-2. Category (e.g., `$ROOT`): categories place hard constraints on what
- Derivations can be combined.
-3. Type (e.g., `(fb:type.number)`): typically more fine-grained than the
- category, and is generated dynamically.
-4. Logical form (e.g., `(call + (number 3) (number 4))`): what we normally
- think of as the output of semantic parsing.
-5. Value (e.g., `(number 7)`): the result of executing the logical form.
-
-There are some special categories:
-
-1. `$TOKEN`: matches a single token of the utterance. Formally, the parser
- builds a Derivation with category `$TOKEN` and logical form corresponding to
- the token (e.g., `(string three)`) for each token in the utterance.
-2. `$PHRASE`: matches any contiguous subsequence of tokens. The logical form created
- is the concatenation of those tokens (e.g., `(string "twenty-five million")`).
-3. `$LEMMA_TOKEN`: like `$TOKEN`, but the logical form produced is a lemmatized
- version of the token (for example $TOKEN would yield *cows*, while
- $LEMMA_TOKEN would yield *cow*).
-4. `$LEMMA_PHRASE`: the lemmatized version of `$PHRASE`.
-5. `$ROOT` Derivations that have category `$ROOT` and span the entire utterance
- are executed, scored, and sent back to the user.
-
-Now let us see how a grammar specifies the set of derivations.
-A grammar is a set of rules, and each rule has the following form:
-
- (rule ( ... ) )
-
-1. Target category (e.g., `$ROOT`): any derivation produced by this rule is
- labeled with this category. `$ROOT` is the designated top-level category.
- Derivations of type `$ROOT` than span the entire utterance are returned to the
- user.
-2. Source sequence (e.g., `three`): in general, this is a sequence of tokens and categories
- (all categories start with `$` by convention). Tokens (e.g., `three`) are
- matched verbatim, and categories (e.g., `$PHRASE`) match any derivation that
- is labeled with that category and has a span at that position.
-3. Semantic function (`SemanticFn`): a semantic function takes a sequence of
- derivations corresponding to the categories in the children and produces a set
- of new derivations which are to be labeled with the target category.
- Semantic functions run arbitrary Java code, and allow the parser to integrate
- custom logic in a flexible modular way. In the example above, `ConstantFn`
- is an example of a semantic function which always returns one derivation
- with the given logical form (e.g., `(number 3)`). `JoinFn` produces a
- derivation whose logical form is the composition of the logical forms of the
- two source derivations.
-
-Derivations are built recursively: for each category and span, we construct a
-set of Derivations. We can apply a rule if there is some segmentation of the
-span into sub-spans $s_1, \dots, s_k$ and a derivation $d_i$ on each span $s_i$
-with category |source_i|. In this case, we pass the list of derivations as
-input into the semantic function. The output is a set of derivations (possibly
-zero).
-
-The first rule is a familiar one that just parses strings such as *three*
-into the category `$Expr`:
-
- (rule $Expr ($PHRASE) (NumberFn))
-
-Specifically, one derivation with logical form `(string three)` is created
-with category `$PHRASE` and span 0:1. This derivation is passed into
-`NumberFn`, which returns one derivation with logical form `(number 3)` and
-category `$Expr` and span 0:1. The same goes for *four* on span 2:3.
-
-The next two rules map the tokens *plus* and *times* to a static logical form
-(returned by `ConstantFn`):
-
- (rule $Operator (plus) (ConstantFn (lambda y (lambda x (call + (var x) (var y))))))
- (rule $Operator (times) (ConstantFn (lambda y (lambda x (call * (var x) (var y))))))
-
-The next two rules are the main composition rules:
-
- (rule $Partial ($Operator $Expr) (JoinFn forward))
- (rule $Expr ($Expr $Partial) (JoinFn backward))
-
-The semantic function `(JoinFn forward)` takes two a lambda term `$Operator`
-and an argument `$Expr` and returns a new derivation by forward application:
-
- Source $Operator: (lambda y (lambda x (call + (var x) (var y))))
- Source $Expr: (number 4)
- Target $Partial: (lambda x (call + (var x) (number 4)))
-
-The semantic function `(Join backward)` takes an argument `$Expr` and a lambda
-term `$Partial` and returns a new derivation by backward application:
-
- Source $Expr: (number 3)
- Source $Partial: (lambda x (call + (var x) (number 4)))
- Target $Expr: (call + (number 3) (number 4))
-
- (rule $ROOT ((what optional) (is optional) $Expr (? optional)) (IdentityFn))
-
-We allow some RHS elements to be optional, so that we could have typed in
-`three plus four` or `three plus four?`. `IdentityFn` simply takes the logical
-form corresponding to `$Expr` and passes it up.
-
-The complete derivation for *three plus four* is illustrated here:
-
- $ROOT : (call + (number 3) (number 4)))
- | [IdentityFn]
- $Expr : (call + (number 3) (number 4)))
- | [JoinFn backward]
- +-------------------------+-------------------------+
- | |
- | $Partial : (lambda x (call + (var x) (number 4)))
- | | [JoinFn forward]
- | +-----------------------------+------------------------------+
- | | |
- $Expr : (number 3) $Operator : (lambda y (lambda x (call + (var x) (var y)))) $Expr : (number 4)
- | [NumberFn] | [ConstantFn] | [NumberFn]
- $PHRASE: three | $PHRASE : four
- | [built-in] | | [built-in]
- three plus four
-
-
-**Exercise 2.1**: write rules that can parse the following utterances into
-into the category `$Expr`:
-
- length of hello world # 11
- length of one # 3
-
-Your rules should look something like:
-
- (rule $Function (length of) ...)
- (rule $Expr ($Function $PHRASE) ...)
-
-**Exercise 2.2**: turn your "first word" program into a rule so that you can
-parse the following utterances into `$String`:
-
- first word in compositionality is key # compositionality
- first word in a b c d e # a
-
-**Exercise 2.3**: combine all the rules that you have written to produce one grammar
-that can parse the following:
-
- two times length of hello world # 22
- length of hello world times two # (what happens here?)
-
-To summarize, we have shown how to connect natural language utterances and
-logical forms using grammars, which specify how one can compositionally form
-the logical form incrementally starting from the words in the utterance. Note
-that we are dealing with grammars in the computer science sense, not in the
-linguistic sense, as we are not developing a linguistic theory of
-grammaticality; we are merely trying to parse some useful subset of utterances
-for some task. Given an utterance, the grammar defines an entire set of
-derivations, which reflect both the intrinsic ambiguity of language as well as
-the imperfection of the grammar. In the next section, we will show how to
-learn a semantic parser that can resolve these ambiguities.
-
-### Saving to a file (optional)
-
-You can put a set of grammar rules in a file (e.g.,
-`data/tutorial-arithmetic.grammar`) and load it:
-
- ./run @mode=simple -Grammar.inPaths data/tutorial-arithmetic.grammar
-
-If you edit the grammar, you can reload the grammar without exiting the
-prompt by typing:
-
- (reload)
-
-### Using CoreNLP (optional)
-
-Recall that we were able to parse *four*, but not *twenty-five million*,
-because we used the `SimpleLanguageAnalyzer`. In this section, we will show
-how to leverage Stanford CoreNLP, which provides us with more sophisticated
-linguistic processing on which we can build more advanced semantic parsers.
-
-First, we need to do download an additional dependency (this could take a while
-to download because it loads all of the Stanford CoreNLP models for
-part-of-speech tagging, named-entity recognition, syntactic dependency parsing,
-etc.):
-
- ./pull-dependencies corenlp
-
-Compile it:
-
- ant corenlp
-
-Now we can load the SEMPRE interactive shell with `CoreNLPAnalyzer`:
-
- ./run @mode=simple -languageAnalyzer corenlp.CoreNLPAnalyzer -Grammar.inPaths data/tutorial-arithmetic.grammar
-
-The following utterances should work now (the initial utterance will take a few
-seconds while CoreNLP models are being loaded):
-
- twenty-five million
- twenty-five million plus forty-two
-
-## Section 3: Learning
-
-So far, we have used the grammar to generate a set of derivations given an
-utterance. We could work really hard to make the grammar not overgenerate, but
-this will in general be hard to do without tons of manual effort. So instead, we will
-use machine learning to learn a model that can choose the best derivation (and
-thus logical form) given this large set of candidates. So the philosophy is:
-
-- Grammar: small set of manual rules, defines the candidate derivations
-- Learning: automatically learn to pick the correct derivation using features
-
-In a nutshell, the learning algorithm (class `Learner` in SEMPRE) uses
-stochastic gradient descent to optimize the conditional log-likelihood of the
-denotations given the utterances in a training set. Let us unpack this.
-
-### Components of learning
-
-First, for each derivation, we extract a set of **features** (formally a map
-from strings to doubles — 0 or 1 for indicator features) using a feature
-extractor (class `FeatureExtractor` in SEMPRE), which is an arbitrary function
-on the derivation. Given a parameter vector theta (class `Params` in SEMPRE),
-which is also a map from strings to doubles, the inner product gives us a
-score:
-
- Score(x, d) = features(x, d) dot theta,
-
-where x is the utterance and d is a candidate derivation.
-
-Second, we define a **compatibility function** (class `ValueEvaluator` in SEMPRE)
-between denotations, which returns a number between 0 and 1. This allows us
-learn with approximate values (e.g., "3.5 meters" versus "3.6 meters") and
-award partial credit.
-
-Third, we have a dataset (class `Dataset` in SEMPRE) consisting of **examples**
-(class `Example` in SEMPRE), which specifies utterance-denotation pairs.
-Datasets can be loaded from files; here is what
-`data/tutorial-arithmetic.grammar` looks like:
-
- (example
- (utterance "three and four")
- (targetValue (number 7))
- )
-
-Intuitively, the learning algorithm will tune the parameter vector theta so
-that derivations with logical forms whose denotations have high compatibility
-with the target denotation are assigned higher scores. For the mathematical
-details, see the learning section of this
-[paper](http://www.stanford.edu/~cgpotts/manuscripts/liang-potts-semantics.pdf).
-
-### No learning
-
-As a simple example, imagine that a priori, we do not know what the word *and*
-means: it could be either plus or times. Let us add two rules to capture the
-two possibilities (this is reflected in `data/tutorial-arithmetic.grammar`):
-
- (rule $Operator (and) (ConstantFn (lambda y (lambda x (call * (var x) (var y)))) (-> fb:type.number (-> fb:type.number fb:type.number))))
- (rule $Operator (and) (ConstantFn (lambda y (lambda x (call + (var x) (var y)))) (-> fb:type.number (-> fb:type.number fb:type.number))))
-
-Start the interactive prompt:
-
- ./run @mode=simple -Grammar.inPaths data/tutorial-arithmetic.grammar
-
-and type in:
-
- three and four
-
-There should be two derivations each with probability 0.5 (the system arbitrarily chooses one):
-
- (derivation (formula (((lambda y (lambda x (call * (var x) (var y)))) (number 4.0)) (number 3.0))) (value (number 12.0)) (type fb:type.number)) [score=0, prob=0.500]
- (derivation (formula (((lambda y (lambda x (call + (var x) (var y)))) (number 4.0)) (number 3.0))) (value (number 7.0)) (type fb:type.number)) [score=0, prob=0.500]
-
-### Batch learning
-
-To perform (batch) learning, we run SEMPRE:
-
- ./run @mode=simple -Grammar.inPaths data/tutorial-arithmetic.grammar -FeatureExtractor.featureDomains rule -Dataset.inPaths train:data/tutorial-arithmetic.examples -Learner.maxTrainIters 3
-
-The `rule` feature domain tells the feature extractor to increment the feature
-each time the grammar rule is applied in the derivation. `Dataset.inPaths`
-specifies the examples file to train on, and `-Learner.maxTrainIters 3`
-specifies that we will iterate over all the examples three times.
-
-Now type:
-
- three and four
-
-The correct derivation should now have much higher score and probability:
-
- (derivation (formula (((lambda y (lambda x (call + (var x) (var y)))) (number 4)) (number 3))) (value (number 7)) (type fb:type.any)) [score=18.664, prob=0.941]
- (derivation (formula (((lambda y (lambda x (call * (var x) (var y)))) (number 4)) (number 3))) (value (number 12)) (type fb:type.any)) [score=15.898, prob=0.059]
-
-You will also see the features that are active for the predicted derivation.
-For example, the following line represents the feature indicating that we
-applied the rule mapping *and* to `+`:
-
- [ rule :: $Operator -> and (ConstantFn (lambda y (lambda x (call + (var x) (var y))))) ] 1.383 = 1 * 1.383
-
-The feature value is 1, the feature weight is 1.383, and their product is the
-additive contribution to the score of this derivation. You can look at the score of the other derivation:
-
- (select 1)
-
-The corresponding feature there is:
-
- [ rule :: $Operator -> and (ConstantFn (lambda y (lambda x (call * (var x) (var y))))) ] -1.383 = 1 * -1.383
-
-This negative contribution to the score is why we favored the `+` derivation
-over this `*` one.
-
-We can also inspect the parameters:
-
- (params)
-
-### Online learning
-
-Finally, you can also do (online) learning directly in the prompt:
-
- (accept 1)
-
-This will accept the `*` derivation as the correct one and update the
-parameters on the fly. If you type:
-
- three and four
-
-again, you will see that the probability of the `+` derivation has decreased.
-If you type `(accept 1)` a few more times, the `*` derivation will dominate
-once more.
-
-## Section 4: Lambda DCS and SPARQL
-
-So far, we used `JavaExecutor` to map logical forms to denotations by executing
-Java code. A major application of semantic parsing (and indeed the initial one
-that gave birth to SEMPRE) is where the logical forms are database queries. In
-this section, we will look at querying graph databases.
-
-A graph database (e.g., Freebase) stores information about entities
-and their properties; concretely, it is just a set of triples $(s, p, o)$,
-where $s$ and $o$ are entities and $p$ is a property. For example:
-
- fb:en.barack_obama fb:place_of_birth fb:en.honolulu
-
-is one triple. If we think of the entities as nodes in a directed graph, the
-each triple is a directed edge between two nodes labeled with the property.
-
-See `freebase/data/tutorial.ttl` for an example of a tiny subset of the Freebase graph
-pertaining to geography about California.
-
-First, pull the dependencies needed for Freebase:
-
- ./pull-dependencies freebase
-
-### Setting up your own Virtuoso graph database
-
-We use the graph database engine, Virtuoso, to store these triples and allow
-querying. Follow these instructions if you want to create your own Virtuoso instance.
-
-First, make sure you have Virtuoso installed — see the Installation
-section of the [readme](README.md).
-
-Then start the server:
-
- freebase/scripts/virtuoso start tutorial.vdb 3001
-
-Add a small graph to the database:
-
- freebase/scripts/virtuoso add freebase/data/tutorial.ttl 3001
-
-Now you can query the graph (this should print out three items):
-
- ./run @mode=query @sparqlserver=localhost:3001 -formula '(fb:location.location.containedby fb:en.california)'
-
-To stop the server:
-
- freebase/scripts/virtuoso stop 3001
-
-### Setting up a copy of Freebase
-
-The best case is someone already installed Freebase for you and handed you a
-host:port. Otherwise, to run your own copy of the entire Freebase graph (a
-2013 snapshot), read on.
-
-Download it (this is really big and takes a LONG time):
-
- ./pull-dependencies fullfreebase-vdb
-
-Then you can start the server (make sure you have at least 60GB of memory):
-
- freebase/scripts/virtuoso start lib/fb_data/93.exec/vdb 3093
-
-### Lambda DCS
-
-SPARQL is the standard language for querying graph databases, but it will be
-convenient to use a language more tailored for semantic parsing. We will use
-[lambda DCS](http://arxiv.org/pdf/1309.4408.pdf), which is based on a mix
-between lambda calculus, description logic, and dependency-based compositional
-semantics (DCS).
-
-We assume you have started the Virtuoso database:
-
- freebase/scripts/virtuoso start tutorial.vdb 3001
-
-Then start up a prompt:
-
- ./run @mode=simple-freebase-nocache @sparqlserver=localhost:3001
-
-The simplest logical formula in lambda DCS is a single entity such as `fb:en.california`.
-To execute this query, simply type the following into the interactive prompt:
-
- (execute fb:en.california)
-
-This should return:
-
- (list (name fb:en.california California))
-
-The result is a list containing the single entity. Here, `fb:en.california` is
-the canonical Freebase ID (always beginning with the prefix `fb:`) and
-`California` is the name (look at `data/tutorial.ttl` to see where this comes
-from).
-
-Let us try a more complex query which will fetch all the cities (in the database);
-
- (execute (fb:type.object.type fb:location.citytown))
-
-This should return the three cities, Seattle, San Francisco, and Los Angeles.
-We can restrict to *cities in California*:
-
- (execute (and (fb:type.object.type fb:location.citytown) (fb:location.location.containedby fb:en.california)))
-
-This should return the two cities satisfying the restriction: San Francisco and Los Angeles.
-
-We can count the number of cities (should return 3):
-
- (execute (count (fb:type.object.type fb:location.citytown)))
-
-We can also get the city with the largest area:
-
- (execute (argmax 1 1 (fb:type.object.type fb:location.citytown) fb:location.location.area))
-
-Now let us take a closer look at what is going on with these logical forms
-under the hood. We are using a logical language called lambda DCS.
-
-Here are the following types of logical forms:
-
-1. Primitive (e.g., `fb:en.seattle`): denotes a set containing that single entity.
-1. Intersection `(and |u1| |u2|)`: denotes the intersection of the sets denoted
- by unary logical forms `u1` and `u2`.
-1. Join `(|b| |u|)`: denotes the set of $x$ which are connected to some $y$ via
- a binary $b$ and $y$ is in the set denoted by unary $u$.
-1. Count `(count |u|)`: denotes the set containing the cardinality of the set denoted by `u`.
-1. Superlative `(argmax |rank| |count| |u| |b|)`: sort the elements of `z` by decreasing `b`
- and return `count` elements starting at offset `rank` (1-based).
-1. Mu abstraction `(mark (var |v|) |u|)`: same as the unary |u| denoting
- entities |x|, with the exception that |x| must be equal to all occurrences
- of the variable |v| in |u|.
-1. Lambda abstraction `(lambda (var |v|) |u|)`: produces a binary (x,y) where
- `x` is in the set denoted by `u` and `y` is the value taken on by variable
- `v`.
-
-See `src/edu/stanford/nlp/sempre/freebase/test/SparqlExecutorTest.java` for
-many more examples (which only work on the full Freebase).
-
-**Exercise 4.1**: write lambda DCS logical forms for the following utterances:
-
- `city with the largest area`
-
- `top 5 cities by area`
-
- `countries whose capitals have area at least 500 squared kilometers`
-
- `states bordering Oregon and Washington`
-
- `second tallest mountain in France`
-
- `country with the most number of rivers`
-
-You should familiarize yourself with the [Freebase
-schema](http://www.freebase.com/schema) to see which predicates to use.
-Execute these on the full Freebase to find out the answer!
-
-### Parsing
-
-So far, we have described the denotations of logical forms for querying a graph
-database. Now we focus on parsing natural language utterances into these
-logical forms.
-
-The core challenge is at the lexical level: mapping natural language phrases
-(e.g., *born in*) to logical predicates (e.g.,
-`fb:people.person.place_of_birth`). It is useful to distinguish between two
-types of lexical items:
-
-- Entities (e.g., `fb:en.barack_obama`): There are generally a huge number of
- entities (Freebase has tens of millions). Often, string matching gets you
- part of the way there (for example, *Obama* to `fb.en:barack_obama`), but
- there is often quite a bit of ambiguity (Obama is also a city in Japan).
-
-- Non-entities (e.g., `fb:people.person.place_of_birth`), which include unary
- and binary predicates: There are fewer of these, but string matching is
- unlikely to get you very far.
-
-We could always add grammar rules like this:
-
- (rule $Entity (the golden state) (ConstantFn fb:en.california))
- (rule $Entity (california) (ConstantFn fb:en.california))
-
-but grammars are supposed to be small, so this approach does not scale, so we
-are not going to do this.
-One way is to create a **lexicon**, which is a mapping from words to predicates
-(see `freebase/data/tutorial-freebase.lexicon`), with entries like this:
-
- {"lexeme": "california", "formula": "fb:en.california"}
- {"lexeme": "the golden state", "formula": "fb:en.california"}
- {"lexeme": "cities", "formula": "(fb:type.object.type fb:location.citytown)"}
- {"lexeme": "towns", "formula": "(fb:type.object.type fb:location.citytown)"}
- {"lexeme": "in", "formula": "fb:location.location.containedby"}
- {"lexeme": "located in", "formula": "fb:location.location.containedby"}
-
-Then we can add the following rules (see
-`freebase/data/tutorial-freebase.grammar`):
-
- (rule $Unary ($PHRASE) (SimpleLexiconFn (type fb:type.any)))
- (rule $Binary ($PHRASE) (SimpleLexiconFn (type (-> fb:type.any fb:type.any))))
- (rule $Set ($Unary) (IdentityFn))
- (rule $Set ($Unary $Set) (MergeFn and))
- (rule $Set ($Binary $Set) (JoinFn forward))
- (rule $ROOT ($Set) (IdentityFn))
-
-The `SimpleLexiconFn` looks up the phrase and returns all formulas that have the given type. To check the type, use:
-
- (type fb:en.california) # fb:common.topic
- (type fb:location.location.containedby) # (-> fb:type.any fb:type.any)
-
-`MergeFn` takes the two (unary) logical forms |u| and |v| (in this case, coming from `$Unary` and `$Set`),
-and forms the intersection logical form `(and |u| |v|)`.
-
-`JoinFn` takes two logical forms (one binary and one unary) and returns the
-logical form `(|b| |v|)`. Note that before we were using `JoinFn` as function
-application. In lambda DCS, `JoinFn` produces an actual logical form that
-corresponds to joining |b| and |v|. The two bear striking similarities, which
-is the basis for the overloading.
-
-Now start the interactive prompt:
-
- ./run @mode=simple-freebase-nocache @sparqlserver=localhost:3001 -Grammar.inPaths freebase/data/tutorial-freebase.grammar -SimpleLexicon.inPaths freebase/data/tutorial-freebase.lexicon
-
-We should be able to parse the following utterances:
-
- california
- the golden state
- cities in the golden state
- towns located in california
-
-In general, how does one create grammars? One good strategy is to start with a
-single rule mapping the entire utterance to the final logical form. Then
-decompose the rule into parts. For example, you might start with:
-
- (rule $ROOT (cities in california) (ConstantFn (and (fb:type.object.type fb:location.citytown) (fb:location.location.containedby fb:en.california))))
-
-Then you might factor it into two pieces, in order to generalize:
-
- (rule $ROOT (cities in $Entity) (lambda e (and (fb:type.object.type fb:location.citytown) (fb:location.location.containedby (var e)))))
- (rule $Entity (california) (ConstantFn fb:en.california))
-
-Note that in the first rule, we are writing `(lambda x ...)` directly. This
-means, take the logical form for the source (`$Entity`) and substitute it in
-for `x`.
-
-We can refactor the first rule:
-
- (rule $ROOT ($Unary in $Entity) (lambda u (lambda e (and (var u) (fb:location.location.containedby (var e))))))
- (rule $Unary (cities) (ConstantFn (fb:type.object.type fb:location.citytown)))
-
-and so on...
-
-**Exercise 4.2**: Write a grammar that can parse the utterances from Exercise
-4.1 into a set of candidates containing the true logical form you annotated.
-Of course you can trivially write one rule for each example, but try to
-decompose the grammars as much as possible. This is what will permit
-generalization.
-
-**Exercise 4.3**: Train a model so that the correct logical forms appear at the
-top of the candidate list on the training examples. Remember to add features.
-
-## Debugging
-
-In the beginning, SEMPRE grammars can be difficult to debug. This is primarily
-because everything is dynamic, which means that minor typos result in empty
-results rather than errors.
-
-The first you should do is to check that you do not have typos. Then, try to
-simplify your grammar as much as possible (comment things out) until you have
-the smallest example that fails. Then you should turn on more debugging
-output:
-
-Only derivations that reach `$ROOT` over the entire span of the sentence are
-built. You can also turn on debugging to print out all intermediate
-derivations so that you can see where something is failing:
-
- (set Parser.verbose 3) # or pass -Parser.verbose 3 on the command-line
-
-Often derivations fail because an intermediate combination does not type check.
-This option will print out all combinations which are tried. You might find
-that you are combining two logical forms in the wrong way:
-
- (set JoinFn.verbose 3)
- (set JoinFn.showTypeCheckFailures true)
- (set MergeFn.verbose 3)
- (set MergeFn.showTypeCheckFailures true)
-
-## Appendix: Background reading
-
-So far this tutorial has provided a very operational view of semantic parsing
-based on SEMPRE. The following references provide a broader look at the area
-of semantic parsing as well as the linguistic and statistical foundations.
-
-* **Natural language semantics**: The question of how to represent natural
- language utterances using logical forms has been well-studied in linguistics
- under formal (or compositional) semantics. Start with the
- [CS224U course notes from Stanford](http://www.stanford.edu/class/cs224u/readings/cl-semantics-new.pdf)
- to get a brief taste of the various phenomena in natural language.
- The [Bos/Blackburn book](http://www.let.rug.nl/bos/comsem/book1.html)
- (also see this [related article](http://www.coli.uni-saarland.de/publikationen/softcopies/Blackburn:1997:RIN.pdf))
- gives more details on how parsing to logical forms works (without any
- learning); Prolog code is given too.
-
-* **Log-linear models**: Our semantic parser is based on log-linear models,
- which is a very important tool in machine learning and statistical natural
- language processing. Start with [a tutorial by Michael
- Collins](http://www.cs.columbia.edu/~mcollins/loglinear.pdf), which is geared
- towards applications in NLP.
-
-* **Semantic parsing**: finally, putting the linguistic insights from formal
- semantics and the computational and statistical tools from machine learning,
- we get semantic parsing. There has been a lot of work on semantic parsing,
- we will not attempt to list fully here. Check out the [ACL 2013 tutorial by
- Yoav Artzi and Luke
- Zettlemoyer](http://yoavartzi.com/pub/afz-tutorial.acl.2013.pdf), which
- focuses on how to build semantic parsers using Combinatory Categorical
- Grammar (CCG). Our [EMNLP 2013
- paper](http://cs.stanford.edu/~pliang/papers/freebase-emnlp2013.pdf) is the
- first paper based on SEMPRE. This [Annual Reviews
- paper](http://www.stanford.edu/~cgpotts/manuscripts/liang-potts-semantics.pdf)
- provides a tutorial of how to learn a simple model of compositional semantics
- ([Python code](https://github.com/cgpotts/annualreview-complearning) is
- available) along with a discussion of compositionality and generalization.
diff --git a/examples/lassie/sempre/build.xml b/examples/lassie/sempre/build.xml
deleted file mode 100644
index c6a7cc524f..0000000000
--- a/examples/lassie/sempre/build.xml
+++ /dev/null
@@ -1,130 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/examples/lassie/sempre/interactive/README.md b/examples/lassie/sempre/interactive/README.md
deleted file mode 100644
index 4a343be237..0000000000
--- a/examples/lassie/sempre/interactive/README.md
+++ /dev/null
@@ -1,115 +0,0 @@
-# README
-
-This `interactive` package is the code for our paper
-*Naturalizing a programming language through interaction* (ACL 2017).
-A live demo is at [www.voxelurn.com](http://www.voxelurn.com).
-
-voxelurn is a language interface to a voxel world.
-This server handles commands used to learn from definitions, and other interactive queries.
-In this setting, the system begin with the dependency-based action language (`dal.grammar`), and gradually expand the language through interacting with it users.
-
-## Overview of the components
-
-### sempre.interactive
-
-The `edu.stanford.nlp.sempre.interactive` package live in this repo contains code for
-* running interactive commands (such as query, accept, reject, definition)
-* executor for the dependency-based action (DAL) language
-* voxelurn specific code in `edu.stanford.nlp.sempre.interactive.voxelurn` for actually generating the voxel and manipulating them
-Utilties and resources such as the grammar and run script are in this directory, and the code in in the regular `sempre/src` directory.
-
-### voxelurn client
-
-It queries the server, and renders the voxels to a browser. A live version is at [www.voxelurn.com](http://www.voxelurn.com), which queries our server. You can also find a client for localhost at [http://local.voxelurn.com](http://local.voxelurn.com), which is the same client, but with queries going to `http://localhost:8410` instead.
-Code for the client at `https://github.com/sidaw/shrdlurn`. See its [README.md](https://github.com/sidaw/shrdlurn/blob/master/README.md) if you want to work with and build the client yourself.
-
-
-### voxelurn community server
-Located at `interactive/community-server`, the community server
-handles other functionalities such as logging client actions, leaderboard, submiting structures, authentication etc. and generally functions not related to parsing. This server is needed for running interactive experiments, but is not required just for trying out voxelurn.
-
-
-## Running the SEMPRE server for Voxelurn
-
-0. Setup SEMPRE dependencies and compile
-
- ./pull-dependencies core
- ant interactive
-
-1. Start the server
-
- ./interactive/run @mode=voxelurn -server -interactive
-
- things in the core language such as `add red left`, `repeat 3 [select left]` should work.
-
-2. Feed the server existing definitions, which should take less than 2 minutes.
-
- ./interactive/run @mode=simulator @server=local @sandbox=none @task=freebuilddef -maxQueries 2496
-
- try `add dancer` now.
-
-### Interacting with the server
-
-After you run the above, there are 3 ways to interact and try your own commands.
-
-* The visual way is to use the client: [http://local.voxelurn.com](http://local.voxelurn.com).
- Code for the client is at `https://github.com/sidaw/shrdlurn` (see its [README.md](https://github.com/sidaw/shrdlurn/blob/master/README.md)).
- Try `[add dancer; front 5] 3 times`.
-
-* Hit `Ctrl-D` on the terminal running the server, and type `add red top`, or `add green monster`
-
-* On a browser, type `http://localhost:8410/sempre?q=(:q add green monster)`
-
-
-## Experiments in ACL2017
-
-1. Start the server
-
- ./interactive/run @mode=voxelurn -server -interactive
-
-2. Feed the server all the query logs
-
- ./interactive/run @mode=simulator @server=local @sandbox=none @task=freebuild -maxQueries 103874
-
- This currently takes just under 30 minutes. Decrease maxQuery for a quicker experiment. This generate `plotInfo.json` in `./state/execs/${lastExec}.exec/` where `lastExec` is `cat ./state/lastExec`.
-
-3. Taking `../state/execs/${lastExec}.exec/plotInfo.json` as input, we can analyze the data and produce some plots using the following ipython notebook
-
- ipython notebook interactive/analyze_data.ipynb
-
- which prints out basic statistics and generates the plots used in our paper. The plots are saved at `../state/execs/${lastExec}.exec/`
-
-
-## Misc.
-
-There are some unit tests
-
- ./interactive/run @mode=test
-
-To specify a specific test class and verbosity
-
- ./interactive/run @mode=test @class=DALExecutorTest -verbose 5
-
-Clean up or backup data
-
- ./interactive/run @mode=backup # save previous data logs
- ./interactive/run @mode=trash # deletes previous data logs
-
-Data, in .gz can be found in queries.
-
-* `./interactive/queries/freebuild.def.json.gz`
-has 2495 definitions combining just over 10k utterances.
-* `./interactive/queries/freebuild.json.gz` has 103873 queries made during the main experiment.
-
-## Voxelurn community server (optional and in development)
-
-This server helps with client side logging, leaderboard, authentication etc. basically anything that is not directly related to parsing.
-This component is only required if you want to run the interactive experiment yourself. It is fairly coupled with the [voxelurn client](http://github.com/sidaw/shrdlurn), which sends the request to this server.
-
- cd interactive/community-server
- python install-deps.py
- python server.py --port 8403
-
- # required keys for authentication
- export SEMPRE_JWT_SECRET=ANY_RANDOM_SEQEUNCE
- export SLACK_OAUTH_SECRET=OAUTH_KEY_FROM_SLACK
diff --git a/examples/lassie/sempre/interactive/lassie.db b/examples/lassie/sempre/interactive/lassie.db
deleted file mode 100644
index f0e36b5ac1..0000000000
--- a/examples/lassie/sempre/interactive/lassie.db
+++ /dev/null
@@ -1,752 +0,0 @@
-############################################################################
-# Domain knowledge is written here in a mix of whitespace- and #
-# comma-separated values. For each line, the first token is a HOL #
-# component and the second is the attribute we want to specify. What #
-# follows is a comma-separated list of values which characterize this #
-# attribute of that component. In the list (and nowhere else) can tokens #
-# contain whitespaces. This allows SML types and expressions of more than #
-# one word to be represented naturally. #
-# #
-# The `type` attribute is the only one required for each component and #
-# gives rise to litteral lexemes to be parsed into their fitting type in #
-# the grammar; e.g. `asm_rewrite_tac` is given type `thm list -> tactic` #
-# which produces a lexeme #
-# #
-# lexeme: `asm_rewrite_tac` #
-# formula: `asm_rewrite_tac` #
-# type: `thmlist->tactic` #
-# #
-# Calling SimpleLexiconFn on (type thmlist->tactic) captures all #
-# instances of asm_rewrite_tac (and other functions of the same type) into #
-# a category of choice. Note that internally, those types have their #
-# whitespaces removed and parentheses turned into square brackets so type #
-# #
-# term quotation list -> (thm -> tactic) -> thm -> tactic #
-# #
-# is actually fetched from SimpleLexiconFn with #
-# #
-# (type termquotationlist->[thm->tactic]->thm->tactic) #
-# #
-# into a category potentially called #
-# #
-# $termquotationlist->[thm->tactic]->thm->tactic #
-############################################################################
-
-
-#########################
-# HOL4 Tactics - Types: #
-#########################
-
-# rewriting
-asm_rewrite_tac type thm list -> tactic
-rewrite_tac type thm list -> tactic
-once_rewrite_tac type thm list -> tactic
-once_asm_rewrite_tac type thm list -> tactic
-
-# simplification
-simp type thm list -> tactic
-fs type thm list -> tactic
-rfs type thm list -> tactic
-rw type thm list -> tactic
-
-# thm tactics
-imp_res_tac type thm -> tactic
-assume_tac type thm -> tactic
-irule type thm -> tactic
-drule type thm -> tactic
-match_mp_tac type thm -> tactic
-mp_tac type thm -> tactic
-
-# automation tactics
-res_tac type tactic
-metis_tac type thm list -> tactic
-MESON_TAC type thm list -> tactic
-
-# pattern based tactics
-qpat_x_assum type term quotation -> (thm -> tactic) -> tactic
-qpat_assum type term quotation -> (thm -> tactic) -> tactic
-
-# tacticals
-first_x_assum type (thm -> tactic) -> tactic
-first_assum type (thm -> tactic) -> tactic
-last_x_assum type (thm -> tactic) -> tactic
-last_assum type (thm -> tactic) -> tactic
-rpt type tactic -> tactic
-TRY type tactic -> tactic
-
-# other
-Cases type tactic
-Induct type tactic
-cheat type tactic
-gen_tac type tactic
-strip_tac type tactic
-conj_tac type tactic
-all_tac type tactic
-NO_TAC type tactic
-EQ_TAC type tactic
-CCONTR_TAC type tactic
-AP_TERM_TAC type tactic
-AP_THM_TAC type tactic
-Induct_on type term quotation -> tactic
-Cases_on type term quotation -> tactic
-completeInduct_on type term quotation -> tactic
-qexists_tac type term quotation -> tactic
-sg type term quotation -> tactic
-subgoal type term quotation -> tactic
-qspec_then type term quotation -> (thm -> tactic) -> thm -> tactic
-qspecl_then type term quotation list -> (thm -> tactic) -> thm -> tactic
-pop_assum type (thm -> tactic) -> tactic
-spose_not_then type (thm -> tactic) -> tactic
-rename type term quotation list -> tactic
-ntac type int -> tactic -> tactic
-by type term quotation * tactic -> tactic
-suffices_by type term quotation * tactic -> tactic
-
-###################
-# Tactic chaining #
-###################
-THEN type tactic -> tactic -> tactic
-ORELSE type tactic -> tactic -> tactic
-
-
-########################
-# HOL4 - Rules : Types #
-########################
-GSYM type thm -> thm
-EVAL_RULE type thm -> thm
-Once type thm -> thm
-
-############################
-# Interactive mode : Types #
-############################
-b type command
-
-#################################
-# HOL4 Tactics - Name features: #
-#################################
-# rewriting
-#rewrite_tac VP rewrite
-#rewrite_tac OBJ goal
-#rewrite_tac PREARG with
-#
-#asm_rewrite_tac VP rewrite
-#asm_rewrite_tac OBJ goal
-#asm_rewrite_tac CP with assumptions
-#asm_rewrite_tac PREARG with
-#
-#once_rewrite_tac VP rewrite
-#once_rewrite_tac OBJ goal
-#once_rewrite_tac CP once
-#once_rewrite_tac PREARG with
-#
-#once_asm_rewrite_tac VP rewrite
-#once_asm_rewrite_tac OBJ goal
-#once_asm_rewrite_tac CP once
-#once_asm_rewrite_tac CP with assumptions
-#once_asm_rewrite_tac PREARG with
-#
-## simplification
-#simp VP simplify
-#simp OBJ goal
-#simp CP with assumptions
-#simp PREARG with
-#
-#fs AV full, fully
-#fs VP simplify
-#fs OBJ goal, all of goal, assumptions
-#fs CP with assumptions
-#fs PREARG with
-#
-#rfs AV reverse, full, fully
-#rfs VP simplify
-#rfs OBJ goal, all of goal, assumptions
-#rfs CP with assumptions, in reverse order
-#rfs PREARG with
-#
-## thm tactics
-#imp_res_tac VP enrich assumptions, resolve theorem
-#imp_res_tac PREARG with
-#
-#res_tac VP enrich, resolve
-#res_tac OBJ assumptions
-#res_tac CP together, with eachother
-#
-#assume_tac VP assume, have, add
-#assume_tac OBJ assumption
-#assume_tac CP to goal, to assumptions
-#
-#irule VP reduce
-#irule OBJ goal
-#irule CP with matching
-#irule PREARG with, with implication
-#
-#drule name resolve with
-#
-#match_mp_tac name modus ponens
-#match_mp_tac VP reduce
-#match_mp_tac OBJ goal
-#match_mp_tac CP with matching, without normalization, without normalizing
-#match_mp_tac PREARG with, with implication
-#
-## automation tactics
-#res_tac VP enrich, resolve
-#res_tac OBJ assumptions
-#res_tac CP together, with eachother
-#
-#MESON_TAC name meson
-#MESON_TAC AV auto, automatic
-#MESON_TAC VP proof search, search
-#MESON_TAC OBJ proof
-#MESON_TAC PREARG with
-#
-#metis_tac name metis
-#metis_tac AV auto, automatic, ordered, fancy
-#metis_tac VP proof search, search
-#metis_tac OBJ proof
-#metis_tac PREARG with
-#
-## pattern based tactics
-#qpat_assum VP find, use
-#qpat_assum OBJ assumption, matching assumption
-#qpat_assum PREARG with pattern
-#
-#qpat_x_assum VP spend, find, use
-#qpat_x_assum OBJ assumption, matching assumption
-#qpat_x_assum CP and remove it
-#qpat_x_assum PREARG with pattern
-#
-## tacticals
-#first_x_assum VP map, spend, use
-#first_x_assum OBJ assumption, matching assumption
-#first_x_assum CP over assumptions
-#
-#last_x_assum AV reverse
-#last_x_assum VP map, spend, use
-#last_x_assum OBJ assumption, matching assumption, last matching assumption
-#last_x_assum CP over assumptions
-#
-#ntac VP apply
-#ntac CP times
-#
-#rpt AV infinitely, indefinitely
-#rpt VP repeat, keep applying
-#
-## other
-#subgoal VP produce, add, show
-#subgoal OBJ subgoal
-#subgoal CP as subgoal
-#
-#by name by, shown by
-#suffices_by name suffices to show
-#
-#Cases name case analysis, case, cases
-#Cases VP split
-#Cases OBJ goal
-#
-#Induct AV by
-#Induct VP induct, induction, do induction
-#
-#Induct_on AV by
-#Induct_on VP induct, induction, do induction
-#Induct_on OBJ on variable
-#Induct_on PREARG on
-#
-#strip_tac name intros
-#strip_tac VP remove, strip
-#strip_tac OBJ quantifier
-#
-#rename name alpha conversion
-#rename VP rename, change
-#rename OBJ variable names, free variables
-#rename CP in goal
-#rename PREARG into, to, with
-#
-#qexists_tac name exists, exists_tac
-#qexists_tac VP reduce, instantiate, use witness, have witness
-#qexists_tac OBJ existential
-#qexists_tac PREARG with
-#
-#qspec_then name specialize for
-#qspecl_then name specialize for all
-#
-#########################
-## HOL4 - Rules : Types #
-#########################
-#GSYM name symmetry, gsym
-#EVAL_RULE name eval_rule, evaluate
-#Once name only once, once
-
-#######################################
-# HOL4 - Real number theorems : Types #
-#######################################
-SUP_LEMMA3 type thm
-SUP_LEMMA2 type thm
-SUP_LEMMA1 type thm
-SUP_EPSILON type thm
-SUM_ZERO type thm
-SUM_TWO type thm
-SUM_SUBST type thm
-SUM_SUB type thm
-SUM_REINDEX type thm
-SUM_POS_GEN type thm
-SUM_POS type thm
-SUM_PERMUTE_0 type thm
-SUM_OFFSET type thm
-SUM_NSUB type thm
-SUM_NEG type thm
-SUM_LE type thm
-sum_ind type thm
-SUM_GROUP type thm
-SUM_EQ type thm
-SUM_DIFF type thm
-sum_compute type thm
-SUM_CMUL type thm
-SUM_CANCEL type thm
-SUM_BOUND type thm
-SUM_ADD type thm
-SUM_ABS_LE type thm
-SUM_ABS type thm
-SUM_2 type thm
-SUM_1 type thm
-SUM_0 type thm
-sum type thm
-SETOK_LE_LT type thm
-REAL_THIRDS_BETWEEN type thm
-REAL_SUP_UBOUND_LE type thm
-REAL_SUP_UBOUND type thm
-REAL_SUP_SOMEPOS type thm
-REAL_SUP_MAX type thm
-REAL_SUP_LE type thm
-REAL_SUP_EXISTS_UNIQUE type thm
-REAL_SUP_EXISTS type thm
-REAL_SUP_CONST type thm
-REAL_SUP_ALLPOS type thm
-REAL_SUP type thm
-REAL_SUMSQ type thm
-REAL_SUB_TRIANGLE type thm
-REAL_SUB_SUB2 type thm
-REAL_SUB_SUB type thm
-REAL_SUB_RZERO type thm
-REAL_SUB_RNEG type thm
-REAL_SUB_REFL type thm
-REAL_SUB_RDISTRIB type thm
-REAL_SUB_RAT type thm
-REAL_SUB_NEG2 type thm
-REAL_SUB_LZERO type thm
-REAL_SUB_LT type thm
-REAL_SUB_LNEG type thm
-REAL_SUB_LE type thm
-REAL_SUB_LDISTRIB type thm
-REAL_SUB_INV2 type thm
-REAL_SUB_ADD2 type thm
-REAL_SUB_ADD type thm
-REAL_SUB_ABS type thm
-REAL_SUB_0 type thm
-REAL_SUB type thm
-REAL_RNEG_UNIQ type thm
-REAL_RINV_UNIQ type thm
-REAL_RDISTRIB type thm
-REAL_POW_POW type thm
-REAL_POW_MONO_LT type thm
-REAL_POW_LT2 type thm
-REAL_POW_LT type thm
-REAL_POW_INV type thm
-REAL_POW_DIV type thm
-REAL_POW_ADD type thm
-REAL_POW2_ABS type thm
-REAL_POS_POS type thm
-REAL_POS_NZ type thm
-REAL_POS_MONO type thm
-REAL_POS_LE_ZERO type thm
-REAL_POS_INFLATE type thm
-REAL_POS_ID type thm
-REAL_POS_EQ_ZERO type thm
-REAL_POS type thm
-REAL_POASQ type thm
-REAL_OVER1 type thm
-REAL_OF_NUM_SUC type thm
-REAL_OF_NUM_POW type thm
-REAL_OF_NUM_MUL type thm
-REAL_OF_NUM_LE type thm
-REAL_OF_NUM_EQ type thm
-REAL_OF_NUM_ADD type thm
-REAL_NZ_IMP_LT type thm
-REAL_NOT_LT type thm
-REAL_NOT_LE type thm
-REAL_NEGNEG type thm
-REAL_NEG_THIRD type thm
-REAL_NEG_SUB type thm
-REAL_NEG_RMUL type thm
-REAL_NEG_NEG type thm
-REAL_NEG_MUL2 type thm
-REAL_NEG_MINUS1 type thm
-REAL_NEG_LT0 type thm
-REAL_NEG_LMUL type thm
-REAL_NEG_LE0 type thm
-REAL_NEG_INV type thm
-REAL_NEG_HALF type thm
-REAL_NEG_GT0 type thm
-REAL_NEG_GE0 type thm
-REAL_NEG_EQ0 type thm
-REAL_NEG_EQ type thm
-REAL_NEG_ADD type thm
-REAL_NEG_0 type thm
-REAL_MUL_SYM type thm
-REAL_MUL_SUB2_CANCEL type thm
-REAL_MUL_SUB1_CANCEL type thm
-REAL_MUL_RZERO type thm
-REAL_MUL_RNEG type thm
-REAL_MUL_RINV type thm
-REAL_MUL_RID type thm
-REAL_MUL_LZERO type thm
-REAL_MUL_LNEG type thm
-REAL_MUL_LINV type thm
-REAL_MUL_LID type thm
-REAL_MUL_COMM type thm
-REAL_MUL_ASSOC type thm
-REAL_MUL type thm
-REAL_MIN_SUB type thm
-REAL_MIN_REFL type thm
-REAL_MIN_MAX type thm
-REAL_MIN_LT type thm
-REAL_MIN_LE_LIN type thm
-REAL_MIN_LE2 type thm
-REAL_MIN_LE1 type thm
-REAL_MIN_LE type thm
-REAL_MIN_ALT type thm
-REAL_MIN_ADD type thm
-REAL_MIN_ACI type thm
-REAL_MIDDLE2 type thm
-REAL_MIDDLE1 type thm
-REAL_MEAN type thm
-REAL_MAX_SUB type thm
-REAL_MAX_REFL type thm
-REAL_MAX_MIN type thm
-REAL_MAX_LT type thm
-REAL_MAX_LE type thm
-REAL_MAX_ALT type thm
-REAL_MAX_ADD type thm
-REAL_MAX_ACI type thm
-REAL_LTE_TRANS type thm
-REAL_LTE_TOTAL type thm
-REAL_LTE_ANTSYM type thm
-REAL_LTE_ANTISYM type thm
-REAL_LTE_ADD2 type thm
-REAL_LTE_ADD type thm
-REAL_LT_TRANS type thm
-REAL_LT_TOTAL type thm
-REAL_LT_SUB_RADD type thm
-REAL_LT_SUB_LADD type thm
-REAL_LT_RMUL_IMP type thm
-REAL_LT_RMUL_0 type thm
-REAL_LT_RMUL type thm
-REAL_LT_REFL type thm
-REAL_LT_RDIV_EQ type thm
-REAL_LT_RDIV_0 type thm
-REAL_LT_RDIV type thm
-REAL_LT_RADD type thm
-REAL_LT_NZ type thm
-REAL_LT_NEGTOTAL type thm
-REAL_LT_NEG type thm
-REAL_LT_MULTIPLE type thm
-REAL_LT_MUL2 type thm
-REAL_LT_MUL type thm
-REAL_LT_MIN type thm
-REAL_LT_MAX type thm
-REAL_LT_LMUL_IMP type thm
-REAL_LT_LMUL_0 type thm
-REAL_LT_LMUL type thm
-REAL_LT_LE type thm
-REAL_LT_LDIV_EQ type thm
-REAL_LT_LADD type thm
-REAL_LT_INV_EQ type thm
-REAL_LT_INV type thm
-REAL_LT_IMP_NE type thm
-REAL_LT_IMP_LE type thm
-REAL_LT_IADD type thm
-REAL_LT_HALF2 type thm
-REAL_LT_HALF1 type thm
-REAL_LT_GT type thm
-REAL_LT_FRACTION_0 type thm
-REAL_LT_FRACTION type thm
-REAL_LT_DIV type thm
-REAL_LT_ANTISYM type thm
-REAL_LT_ADDR type thm
-REAL_LT_ADDNEG2 type thm
-REAL_LT_ADDNEG type thm
-REAL_LT_ADDL type thm
-REAL_LT_ADD_SUB type thm
-REAL_LT_ADD2 type thm
-REAL_LT_ADD1 type thm
-REAL_LT_ADD type thm
-REAL_LT_1 type thm
-REAL_LT_01 type thm
-REAL_LT1_POW2 type thm
-real_lt type thm
-REAL_LT type thm
-REAL_LNEG_UNIQ type thm
-REAL_LINV_UNIQ type thm
-REAL_LIN_LE_MAX type thm
-REAL_LET_TRANS type thm
-REAL_LET_TOTAL type thm
-REAL_LET_ANTISYM type thm
-REAL_LET_ADD2 type thm
-REAL_LET_ADD type thm
-REAL_LE_TRANS type thm
-REAL_LE_TOTAL type thm
-REAL_LE_SUP type thm
-REAL_LE_SUB_RADD type thm
-REAL_LE_SUB_LADD type thm
-REAL_LE_SUB_CANCEL2 type thm
-REAL_LE_SQUARE type thm
-REAL_LE_RNEG type thm
-REAL_LE_RMUL_IMP type thm
-REAL_LE_RMUL type thm
-REAL_LE_REFL type thm
-REAL_LE_RDIV_EQ type thm
-REAL_LE_RDIV type thm
-REAL_LE_RADD type thm
-REAL_LE_POW2 type thm
-REAL_LE_NEGTOTAL type thm
-REAL_LE_NEGR type thm
-REAL_LE_NEGL type thm
-REAL_LE_NEG2 type thm
-REAL_LE_NEG type thm
-REAL_LE_MUL2 type thm
-REAL_LE_MUL type thm
-REAL_LE_MIN type thm
-REAL_LE_MAX2 type thm
-REAL_LE_MAX1 type thm
-REAL_LE_MAX type thm
-REAL_LE_LT type thm
-REAL_LE_LNEG type thm
-REAL_LE_LMUL_IMP type thm
-REAL_LE_LMUL type thm
-REAL_LE_LDIV_EQ type thm
-REAL_LE_LDIV type thm
-REAL_LE_LADD_IMP type thm
-REAL_LE_LADD type thm
-REAL_LE_INV_EQ type thm
-REAL_LE_INV type thm
-REAL_LE_EPSILON type thm
-REAL_LE_DOUBLE type thm
-REAL_LE_DIV type thm
-REAL_LE_ANTISYM type thm
-REAL_LE_ADDR type thm
-REAL_LE_ADDL type thm
-REAL_LE_ADD2 type thm
-REAL_LE_ADD type thm
-REAL_LE_01 type thm
-REAL_LE1_POW2 type thm
-REAL_LE type thm
-REAL_LDISTRIB type thm
-REAL_INVINV type thm
-REAL_INV_POS type thm
-REAL_INV_NZ type thm
-REAL_INV_MUL type thm
-REAL_INV_LT_ANTIMONO type thm
-REAL_INV_LT1 type thm
-REAL_INV_INV type thm
-REAL_INV_INJ type thm
-REAL_INV_EQ_0 type thm
-REAL_INV_1OVER type thm
-REAL_INV_0 type thm
-REAL_INV1 type thm
-REAL_INJ type thm
-REAL_INF_MIN type thm
-REAL_INF_LT type thm
-REAL_INF_LE type thm
-REAL_INF_CLOSE type thm
-REAL_IMP_SUP_LE type thm
-REAL_IMP_MIN_LE2 type thm
-REAL_IMP_MAX_LE2 type thm
-REAL_IMP_LE_SUP type thm
-REAL_IMP_LE_INF type thm
-REAL_IMP_INF_LE type thm
-REAL_HALF_DOUBLE type thm
-REAL_HALF_BETWEEN type thm
-REAL_FACT_NZ type thm
-REAL_EQ_SUB_RADD type thm
-REAL_EQ_SUB_LADD type thm
-REAL_EQ_RMUL_IMP type thm
-REAL_EQ_RMUL type thm
-REAL_EQ_RDIV_EQ type thm
-REAL_EQ_RADD type thm
-REAL_EQ_NEG type thm
-REAL_EQ_MUL_LCANCEL type thm
-REAL_EQ_LMUL_IMP type thm
-REAL_EQ_LMUL2 type thm
-REAL_EQ_LMUL type thm
-REAL_EQ_LDIV_EQ type thm
-REAL_EQ_LADD type thm
-REAL_EQ_IMP_LE type thm
-REAL_ENTIRE type thm
-REAL_DOWN2 type thm
-REAL_DOWN type thm
-REAL_DOUBLE type thm
-REAL_DIV_RMUL_CANCEL type thm
-REAL_DIV_RMUL type thm
-REAL_DIV_REFL3 type thm
-REAL_DIV_REFL2 type thm
-REAL_DIV_REFL type thm
-REAL_DIV_OUTER_CANCEL3 type thm
-REAL_DIV_OUTER_CANCEL2 type thm
-REAL_DIV_OUTER_CANCEL type thm
-REAL_DIV_MUL2 type thm
-REAL_DIV_LZERO type thm
-REAL_DIV_LMUL_CANCEL type thm
-REAL_DIV_LMUL type thm
-REAL_DIV_INNER_CANCEL3 type thm
-REAL_DIV_INNER_CANCEL2 type thm
-REAL_DIV_INNER_CANCEL type thm
-REAL_DIV_DENOM_CANCEL3 type thm
-REAL_DIV_DENOM_CANCEL2 type thm
-REAL_DIV_DENOM_CANCEL type thm
-REAL_DIV_ADD type thm
-REAL_DIFFSQ type thm
-REAL_BIGNUM type thm
-REAL_ARCH_LEAST type thm
-REAL_ARCH type thm
-REAL_ADD_SYM type thm
-REAL_ADD_SUB_ALT type thm
-REAL_ADD_SUB2 type thm
-REAL_ADD_SUB type thm
-REAL_ADD_RINV type thm
-REAL_ADD_RID_UNIQ type thm
-REAL_ADD_RID type thm
-REAL_ADD_RDISTRIB type thm
-REAL_ADD_RAT type thm
-REAL_ADD_LINV type thm
-REAL_ADD_LID_UNIQ type thm
-REAL_ADD_LID type thm
-REAL_ADD_LDISTRIB type thm
-REAL_ADD_COMM type thm
-REAL_ADD_ASSOC type thm
-REAL_ADD2_SUB2 type thm
-REAL_ADD type thm
-REAL_ABS_TRIANGLE type thm
-REAL_ABS_POS type thm
-REAL_ABS_MUL type thm
-REAL_ABS_0 type thm
-REAL_10 type thm
-REAL_1 type thm
-REAL_0 type thm
-REAL type thm
-POW_ZERO_EQ type thm
-POW_ZERO type thm
-pow_rat type thm
-POW_POS_LT type thm
-POW_POS type thm
-POW_PLUS1 type thm
-POW_ONE type thm
-POW_NZ type thm
-POW_MUL type thm
-POW_MINUS1 type thm
-POW_M1 type thm
-POW_LT type thm
-POW_LE type thm
-POW_INV type thm
-POW_EQ type thm
-POW_ADD type thm
-POW_ABS type thm
-POW_2_LT type thm
-POW_2_LE1 type thm
-POW_2 type thm
-POW_1 type thm
-POW_0 type thm
-NUM_FLOOR_upper_bound type thm
-NUM_FLOOR_LOWER_BOUND type thm
-NUM_FLOOR_LET type thm
-NUM_FLOOR_LE2 type thm
-NUM_FLOOR_LE type thm
-NUM_FLOOR_EQNS type thm
-NUM_FLOOR_DIV_LOWERBOUND type thm
-NUM_FLOOR_DIV type thm
-NUM_FLOOR_BASE type thm
-NUM_CEILING_NUM_FLOOR type thm
-NUM_CEILING_LE type thm
-neg_rat type thm
-mult_ratr type thm
-mult_ratl type thm
-mult_rat type thm
-mult_ints type thm
-lt_ratr type thm
-lt_ratl type thm
-lt_rat type thm
-lt_int type thm
-le_ratr type thm
-le_ratl type thm
-le_rat type thm
-LE_NUM_CEILING type thm
-le_int type thm
-INFINITE_REAL_UNIV type thm
-eq_ratr type thm
-eq_ratl type thm
-eq_rat type thm
-eq_ints type thm
-div_ratr type thm
-div_ratl type thm
-div_rat type thm
-add_ratr type thm
-add_ratl type thm
-add_rat type thm
-add_ints type thm
-ABS_ZERO type thm
-ABS_TRIANGLE_SUB type thm
-ABS_TRIANGLE_NEG type thm
-ABS_TRIANGLE_LT type thm
-ABS_TRIANGLE type thm
-ABS_SUM type thm
-ABS_SUB_ABS type thm
-ABS_SUB type thm
-ABS_STILLNZ type thm
-ABS_SIGN2 type thm
-ABS_SIGN type thm
-ABS_REFL type thm
-ABS_POW2 type thm
-ABS_POS type thm
-ABS_NZ type thm
-ABS_NEG type thm
-ABS_N type thm
-ABS_MUL type thm
-ABS_LT_MUL2 type thm
-ABS_LE type thm
-ABS_INV type thm
-ABS_DIV type thm
-ABS_CIRCLE type thm
-ABS_CASES type thm
-ABS_BOUNDS type thm
-ABS_BOUND type thm
-ABS_BETWEEN2 type thm
-ABS_BETWEEN1 type thm
-ABS_BETWEEN type thm
-ABS_ABS type thm
-ABS_1 type thm
-ABS_0 type thm
-
-#######################################
-# HOL4 - Real number theorems : Names #
-#######################################
-#REAL_DIV set real, division
-#REAL_SUB set real, subtraction, additive inverse
-#POW_2 set power, square, two
-#REAL set real, definition, successor
-#REAL_ADD set real, addition
-#REAL_ADD_ASSOC set real, addition, associativity
-#REAL_ADD_LDISTRIB set real, addition, left, distributivity
-#REAL_ADD_RDISTRIB set real, addition, right, distributivity
-#REAL_ADD_SYM set real, addition, symmetry
-#REAL_DIV_LZERO set real, division, left, zero
-#REAL_DOUBLE set real, double
-#REAL_HALF_DOUBLE set real, half, double
-#REAL_LDISTRIB set real, left, distributivity
-#REAL_MUL set real, multiplication
-#REAL_MUL_LID set real, multiplication, left, identity
-#REAL_MUL_RID set real, multiplication, right, identity
-#REAL_MUL_RINV set real, multiplication, right, inverse
-#REAL_MUL_SYM set real, multiplication, symmetry
-#REAL_NEG_ADD set real, negation, addition
-#REAL_NEG_LMUL set real, negation, left, multiplication
-#REAL_RDISTRIB set real, right, distributivity
-#REAL_SUB_LDISTRIB set real, subtraction, left, distributivity
-#REAL_SUB_RDISTRIB set real, subtraction, right, distributivity
diff --git a/examples/lassie/sempre/interactive/lassie.grammar b/examples/lassie/sempre/interactive/lassie.grammar
deleted file mode 100644
index 1a7465467b..0000000000
--- a/examples/lassie/sempre/interactive/lassie.grammar
+++ /dev/null
@@ -1,245 +0,0 @@
- ############################################################################
- # GRAMMAR FOR NATURAL PROOF EXPRESSIONS #
- # #
- # Refer to SEMPRE's documentation for general indications on rule #
- # construction. #
- # #
- # Currently, domain knowledge comes from two sources. The lassie.lexicon #
- # file contains component names (e.g. fs) and with their types #
- # (e.g. thmlist->tactic, used for sound applications). Features of those #
- # components (e.g. their natural name, their class/type) are read from #
- # lassie.db into the TacticWorld. #
- # #
- # TacticWorld.java holds the main semantics of Lassie's operations, as #
- # we piggy back on the DALExecutor for handling the semantic part of #
- # this grammar. DALExecutor interprets semantic expression in a "world" #
- # containing "items". We superifcially follow this convention where HOL #
- # components can be considered the "items" of our "tactic-world". #
- # #
- # Generally, lowercased categories (e.g. $thm, $name) correspond to #
- # types as found in the lexicon/database. Categories which are #
- # capitalized are intermediates between lowercased categories and the #
- # $tactic category. #
- ############################################################################
-
-###########################################
-# Incorporated SML types: #
-###########################################
-# $tactic
-# $thm
-# ($thmlist)
-# $thm->tactic
-# $thmlist->tactic
-# $tactic->tactic
-# $thm->thm
-# $termquotation->tactic
-# $int->tactic->tactic
-# $termquotation->[thm->tactic]->tactic
-# $[thm->tactic]->tactic
-# $termquotation*tactic->tactic
-# $termquotationlist->tactic
-# $termquotation->[thm->tactic]->thm->tactic
-# $termquotationlist->[thm->tactic]->thm->tactic
-
- ################################################################
- # Define some abbreviations for calling into library functions #
- ################################################################
-(def @int2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.int2string)
-(def @app edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.app)
-(def @intgoal edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.goalInt)
-(def @termgoal edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.goalTerm)
-(def @infix edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.infix)
-(def @then edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then)
-(def @then1 edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then1)
-(def @cons edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.cons)
-(def @list edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.list)
-(def @quote edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.quote)
-(def @parens edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.parens)
-(def @op edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.op)
-(def @fromFeature edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.fromFeature)
-(def @intersect edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.intersect)
-(def @set2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.set2string)
-(def @choice edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.choice)
-(def @tactic edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.tactic)
-(def @mark edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.mark)
-(def @command edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.command)
-(def @thm edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.thm)
-
-(def @ChoiceFn edu.stanford.nlp.sempre.interactive.lassie.ChoiceFn)
-
-(def @appT1T2 (lambda t1 (lambda t2 (call @app (var t1) (var t2)))))
-(def @infixT1T2T3 (lambda t1 (lambda t2 (lambda t3 (call @op (var t2) (var t1) (var t3))))))
-
-###################################
-# GRAMMAR SUPPORTING LITERAL HOL4 #
-###################################
-
-(rule $ROOT ($tactic) (IdentityFn) (anchored 1))
-(rule $ROOT ($command) (IdentityFn) (anchored 1))
-
-(rule $command
- (back)
- (ConstantFn (string "back")) (anchored 1))
-
-## We can put parentheses around a tactic or a command (Missing: $ROOT $command )
-(for @cat ($tactic $thm->tactic)
- (rule @cat (\( @cat \)) (lambda t (call @parens (var t))) (anchored 1)))
-
-###############################################################################
-# literal HOL4 tactics, tacticals, ... #
-# looked up in the Lassie database #
-###############################################################################
-# tactics
-(rule $tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic"))
- (anchored 1))
-
-# tactic modifiers
-(rule $tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic->tactic")) (anchored 1))
-
-# thm tactics
-(rule $thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "thm->tactic") (anchored 1)))
-
-# thm list tactics:
-(rule $thmlist->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "thmlist->tactic") (anchored 1)))
-
-# term tactics
-(rule $termquotation->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->tactic") (anchored 1)))
-
-# first_x_assum, last_x_assum, ...
-(rule $[thm->tactic]->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "[thm->tactic]->tactic") (anchored 1)))
-
-# qspec
-(rule $termquotation->[thm->tactic]->thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->[thm->tactic]->thm->tactic") (anchored 1)))
-
-# qspecl
-(rule $termquotationlist->[thm->tactic]->thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotationlist->[thm->tactic]->thm->tactic") (anchored 1)))
-
-# qpat_x_assum, qpat_assum, ...
-(rule $termquotation->[thm->tactic]->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->[thm->tactic]->tactic")) (anchored 1))
-
-# THEN, ORELSE
-(rule $tactic->tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic->tactic->tactic") (anchored 1)))
-
-#by, suffices_by
-(rule $termquotation*tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation*tactic->tactic")) (anchored 1))
-
-(rule $thm->thm
- ($TOKEN)
- (SimpleLexiconFn (type "thm->thm")) (anchored 1))
-
-# Tactics can be produced by combining different constructs
-(for @category
- (($tactic->tactic $tactic)
- ($thm->tactic $thm)
- ($thmlist->tactic $thmlist)
- ($termquotation->tactic $termquotation)
- ($[thm->tactic]->tactic $thm->tactic))
- (rule $tactic @category @appT1T2 (anchored 1)))
-
-(rule $tactic
- ($termquotation $termquotation*tactic->tactic $tactic)
- @infixT1T2T3 (anchored 1))
-
-## Partial applications for things like qpat_x_assum or first_x_assum
-(rule $[thm->tactic]->tactic
- ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-(rule $[thm->tactic]->thm->tactic
- ($termquotation->[thm->tactic]->thm->tactic $termquotation) @appT1T2 (anchored 1))
-(rule $[thm->tactic]->thm->tactic
- ($termquotationlist->[thm->tactic]->thm->tactic $termquotationlist) @appT1T2 (anchored 1))
-(rule $thm->tactic ($[thm->tactic]->thm->tactic $thm->tactic) @appT1T2 (anchored 1))
-
-## Support for inline THEN
-(rule $tactic ($tactic $tactic->tactic->tactic $tactic) @infixT1T2T3 (anchored 1))
-
-### HOL4 Theorems
-(rule $thm ($TOKEN) (lambda t (call @thm (var t))) (anchored 1))
-(rule $thm ($thm->thm $thm) @appT1T2 (anchored 1))
-(rule $Thms ($thm) (IdentityFn) (anchored 1))
-(rule $Thms ($thm , $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-(rule $thmlist ([ $Thms ]) (lambda thms (call @list (var thms))) (anchored 1))
-(rule $thmlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-(rule $thmlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-
-##### HOL4 Terms
-(rule $termquotation (` $term ') (lambda e (call @quote (var e))) (anchored 1))
-(rule $termquotation (` $term `) (lambda e (call @quote (var e))) (anchored 1))
-(rule $term ($PHRASE) (IdentityFn) (anchored 1))
-(rule $term ($term and $term) (lambda t1 (lambda t2 (call @op (string "∧") (var t1) (var t2)))) (anchored 1))
-(rule $term ($term or $term) (lambda t1 (lambda t2 (call @op (string "∨") (var t1) (var t2)))) (anchored 1))
-
-(rule $Terms ($termquotation) (IdentityFn) (anchored 1))
-(rule $Terms ($termquotation , $Terms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-(rule $termquotationlist ([ $Terms ]) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-(rule $termquotationlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-(rule $termquotationlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-
-(rule $tactic (Goal $int) (lambda n (call @intgoal (var n))) (anchored 1))
-(rule $tactic (Goal $termquotation) (lambda t (call @termgoal (var t))) (anchored 1))
-(rule $tactic (End) (ConstantFn (string "ALLGOALS")) (anchored 1))
-
-### Other
-(rule $Number ($TOKEN) (NumberFn) (anchored 1))
-(rule $int ($Number) (lambda n (call @int2string (var n))) (anchored 1))
-
-## tactic combinators
-#(rule $tactic->tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "tactic->tactic->tactic") (anchored 1)))
-## ntac
-#(rule $int->tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "int->tactic->tactic")) (anchored 1))
-#(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-#(rule $termquotation*tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation*tactic->tactic")) (anchored 1))
-#(rule $tactic
-# ($termquotation $termquotation*tactic->tactic $tactic)
-# @infixT1T2T3 (anchored 1))
-#
-###############################################################
-## literal SML objects, looked up from the database #
-###############################################################
-#
-#
-##### HOL4 Theorems
-#(rule $thm ($thm->thm $thm) @appT1T2 (anchored 1))
-#(rule $thm ($TOKEN) (IdentityFn) (anchored 1))
-#
-### Lists
-#(rule $Thms ($thm) (IdentityFn) (anchored 1))
-#(rule $Thms ($thm , $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $thmlist ([ $Thms ]) (lambda thms (call @list (var thms))) (anchored 1))
-#(rule $thmlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-#(rule $thmlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-#
-#
-###Commands to the interactive prove interface
-#(rule $command
-# (back)
-# (ConstantFn (string "(b)")) (anchored 1))
-#
-#
diff --git a/examples/lassie/sempre/interactive/lassie.grammar_old b/examples/lassie/sempre/interactive/lassie.grammar_old
deleted file mode 100644
index 454245e0af..0000000000
--- a/examples/lassie/sempre/interactive/lassie.grammar_old
+++ /dev/null
@@ -1,334 +0,0 @@
- ############################################################################
- # GRAMMAR FOR NATURAL PROOF EXPRESSIONS #
- # #
- # Refer to SEMPRE's documentation for general indications on rule #
- # construction. #
- # #
- # Currently, domain knowledge comes from two sources. The lassie.lexicon #
- # file contains component names (e.g. fs) and with their types #
- # (e.g. thmlist->tactic, used for sound applications). Features of those #
- # components (e.g. their natural name, their class/type) are read from #
- # lassie.db into the TacticWorld. #
- # #
- # TacticWorld.java holds the main semantics of Lassie's operations, as #
- # we piggy back on the DALExecutor for handling the semantic part of #
- # this grammar. DALExecutor interprets semantic expression in a "world" #
- # containing "items". We superifcially follow this convention where HOL #
- # components can be considered the "items" of our "tactic-world". #
- # #
- # Generally, lowercased categories (e.g. $thm, $name) correspond to #
- # types as found in the lexicon/database. Categories which are #
- # capitalized are intermediates between lowercased categories and the #
- # $tactic category. #
- ############################################################################
-
-###########################################
-# Incorporated SML types: #
-###########################################
-# $tactic
-# $thm
-# ($thmlist)
-# $thm->tactic
-# $thmlist->tactic
-# $tactic->tactic
-# $thm->thm
-# $termquotation->tactic
-# $int->tactic->tactic
-# $termquotation->[thm->tactic]->tactic
-# $[thm->tactic]->tactic
-# $termquotation*tactic->tactic
-# $termquotationlist->tactic
-# $termquotation->[thm->tactic]->thm->tactic
-# $termquotationlist->[thm->tactic]->thm->tactic
-
- ################################################################
- # Define some abbreviations for calling into library functions #
- ################################################################
-(def @int2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.int2string)
-(def @app edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.app)
-(def @infix edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.infix)
-(def @then edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then)
-(def @then1 edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then1)
-(def @cons edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.cons)
-(def @list edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.list)
-(def @quote edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.quote)
-(def @parens edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.parens)
-(def @op edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.op)
-(def @fromFeature edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.fromFeature)
-(def @intersect edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.intersect)
-(def @set2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.set2string)
-(def @choice edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.choice)
-(def @tactic edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.tactic)
-(def @command edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.command)
-
-(def @ChoiceFn edu.stanford.nlp.sempre.interactive.lassie.ChoiceFn)
-
-(def @appT1T2 (lambda t1 (lambda t2 (call @app (var t1) (var t2)))))
-(def @infixT1T2T3 (lambda t1 (lambda t2 (lambda t3 (call @op (var t2) (var t1) (var t3))))))
-
-###################################
-# GRAMMAR SUPPORTING LITERAL HOL4 #
-###################################
-
-# The root is always a tactic or a command
-(rule $ROOT ($tactic) (IdentityFn) (anchored 1))
-(rule $ROOT ($command) (lambda c (call @command (var c))) (anchored 1))
-
-# Tactics can be produced by combining different constructs
-(for @category
- (($thm->tactic $thm) ($tactic->tactic $tactic) ($thmlist->tactic $thmlist)
- ($termquotation->tactic $termquotation)
- ($[thm->tactic]->tactic $thm->tactic))
- (rule $tactic @category @appT1T2 (anchored 1)))
-(rule $tactic ($termquotation $termquotation*tactic->tactic $tactic) @infixT1T2T3 (anchored 1))
-# Support for inline THEN
-(rule $tactic ($tactic $tactic->tactic->tactic $tactic) @infixT1T2T3 (anchored 1))
-
-# Partial applications for things like qpat_x_assum or first_x_assum
-(rule $[thm->tactic]->tactic
- ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-(rule $[thm->tactic]->thm->tactic
- ($termquotation->[thm->tactic]->thm->tactic $termquotation) @appT1T2 (anchored 1))
-(rule $[thm->tactic]->thm->tactic
- ($termquotationlist->[thm->tactic]->thm->tactic $termquotationlist) @appT1T2 (anchored 1))
-(rule $thm->tactic ($[thm->tactic]->thm->tactic $thm->tactic) @appT1T2 (anchored 1))
-(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-
-# We can put parentheses around a tactic or a command
-(for @cat ($ROOT $command $tactic)
- (rule @cat (\( @cat \)) (lambda t (call @parens (var t))) (anchored 1)))
-
-##############################################################
-# literal SML objects, looked up from the database #
-##############################################################
-# tactics
-(rule $tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic")) (anchored 1))
-# tactic modifiers
-(rule $tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic->tactic")) (anchored 1))
-# thm tactics
-(rule $thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "thm->tactic") (anchored 1)))
-# thm list tactics:
-(rule $thmlist->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "thmlist->tactic") (anchored 1)))
-# tactic combinators
-(rule $tactic->tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic->tactic->tactic") (anchored 1)))
-# term tactics
-(rule $termquotation->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->tactic") (anchored 1)))
-# first_x_assum, last_x_assum, ...
-(rule $[thm->tactic]->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "[thm->tactic]->tactic") (anchored 1)))
-# qspec
-(rule $termquotation->[thm->tactic]->thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->[thm->tactic]->thm->tactic") (anchored 1)))
-# qspecl
-(rule $termquotationlist->[thm->tactic]->thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotationlist->[thm->tactic]->thm->tactic") (anchored 1)))
-# qpat_x_assum, qpat_assum, ...
-(rule $termquotation->[thm->tactic]->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->[thm->tactic]->tactic")) (anchored 1))
-# ntac
-(rule $int->tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "int->tactic->tactic")) (anchored 1))
-(rule $termquotation*tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation*tactic->tactic")) (anchored 1))
-(rule $thm->thm
- ($TOKEN)
- (SimpleLexiconFn (type "thm->thm")) (anchored 1))
-
-#### HOL4 Terms
-(rule $termquotation (` $term ') (lambda e (call @quote (var e))) (anchored 1))
-(rule $termquotation (' $term ') (lambda e (call @quote (var e))) (anchored 1))
-(rule $term ($PHRASE) (IdentityFn) (anchored 1))
-(rule $term ($term and $term) (lambda t1 (lambda t2 (call @op (string "∧") (var t1) (var t2)))) (anchored 1))
-(rule $term ($term or $term) (lambda t1 (lambda t2 (call @op (string "∨") (var t1) (var t2)))) (anchored 1))
-
-(rule $Terms ($termquotation) (IdentityFn) (anchored 1))
-(rule $Terms ($termquotation , $Terms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-(rule $termquotationlist ([ $Terms ]) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-(rule $termquotationlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-(rule $termquotationlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-
-#### HOL4 Theorems
-(rule $thm ($thm->thm $thm) @appT1T2 (anchored 1))
-(rule $thm ($TOKEN) (IdentityFn) (anchored 1))
-
-## Lists
-(rule $Thms ($thm) (IdentityFn) (anchored 1))
-(rule $Thms ($thm , $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-(rule $thmlist ([ $Thms ]) (lambda thms (call @list (var thms))) (anchored 1))
-(rule $thmlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-(rule $thmlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-
-
-##Commands to the interactive prove interface
-(rule $command
- (back)
- (ConstantFn (string "(b)")) (anchored 1))
-
-## Other
-(rule $Number ($TOKEN) (NumberFn) (anchored 1))
-(rule $int ($Number) (lambda n (call @int2string (var n))) (anchored 1))
-
-################################################################
-## GRAMMAR SUPPORTING ABSTRACT DESCRIPTIONS OF HOL4 COMPONENTS #
-################################################################
-
-## Sets and their intersections, by constructing imperative sentences
-
-## Lexemes
-#(rule $type_lx ($PHRASE) (SimpleLexiconFn (type type)) (anchored 1))
-#(rule $name_lx ($PHRASE) (SimpleLexiconFn (type name)) (anchored 1))
-#(rule $AV_lx ($PHRASE) (SimpleLexiconFn (type AV)) (anchored 1))
-#(rule $VP_lx ($PHRASE) (SimpleLexiconFn (type VP)) (anchored 1))
-#(rule $OBJ_lx ($PHRASE) (SimpleLexiconFn (type OBJ)) (anchored 1))
-#(rule $CP_lx ($PHRASE) (SimpleLexiconFn (type CP)) (anchored 1))
-#(rule $PREARG_lx ($PHRASE) (SimpleLexiconFn (type PREARG)) (anchored 1))
-#
-#(rule $set_lx ($PHRASE) (SimpleLexiconFn (type set)) (anchored 1))
-#
-### Get sets
-#(def @fromFeatureX (lambda x (call @fromFeature (var x))))
-#(rule $type ($type_lx) @fromFeatureX (anchored 1))
-#(rule $name ($name_lx) @fromFeatureX (anchored 1))
-#(rule $AV ($AV_lx) @fromFeatureX (anchored 1))
-#(rule $VP ($VP_lx) @fromFeatureX (anchored 1))
-#(rule $OBJ ($OBJ_lx) @fromFeatureX (anchored 1))
-#(rule $CP ($CP_lx) @fromFeatureX (anchored 1))
-#(rule $PREARG ($PREARG_lx) @fromFeatureX (anchored 1))
-#
-#(rule $set ($set_lx) @fromFeatureX (anchored 1))
-#
-### Syntactically correct intersections
-#(def @intersectS1S2 (lambda s1 (lambda s2 (call @intersect (var s1) (var s2)))))
-#(rule $VP ($AV $VP) @intersectS1S2 (anchored 1))
-#(rule $VP ($VP $OBJ) @intersectS1S2 (anchored 1))
-#(rule $VP ($VP $CP) @intersectS1S2 (anchored 1))
-#(rule $VP ($VP $AV) @intersectS1S2 (anchored 1))
-#
-#(for @p (on with the)
-# (rule $Prep (@p) (ConstantFn null) (anchored 1)))
-#(rule $set ($set $set) @intersectS1S2 (anchored 1))
-#
-#(for @a (use apply)
-# (rule $Apply (@a) (ConstantFn null) (anchored 1)))
-#
-#(rule $VP' ($Apply $name) (SelectFn 1) (anchored 1))
-#(rule $VP' ($name) (IdentityFn) (anchored 1))
-#(rule $VP' ($VP' $type) @intersectS1S2 (anchored 1))
-#(rule $VP' ($type $VP') @intersectS1S2 (anchored 1))
-#(rule $VP' ($VP) (IdentityFn) (anchored 1))
-#(rule $VP' ($VP' $PREARG) @intersectS1S2 (anchored 1))
-#(rule $VP' ($VP' with) (SelectFn 0) (anchored 1))
-#
-### Collapsing sets to single components
-#(rule $tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.tactic")))) (anchored 1))
-#(rule $tactic ($tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $thm->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm -> tactic")))) (anchored 1))
-#(rule $thm->tactic ($thm->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $thmlist->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm list -> tactic")))) (anchored 1))
-#(rule $thmlist->tactic ($thmlist->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $tactic->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.tactic -> tactic")))) (anchored 1))
-#(rule $tactic->tactic ($tactic->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $thm->thm' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm -> thm")))) (anchored 1))
-#(rule $thm->thm ($thm->thm') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $termquotation->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.term quotation -> tactic")))) (anchored 1))
-#(rule $termquotation->tactic ($termquotation->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $int->tactic->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.int -> tactic -> tactic")))) (anchored 1))
-#(rule $int->tactic->tactic ($int->tactic->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-
-
-## Theorems
-#(rule $thm' ($set) (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm")))) (anchored 1))
-#(rule $thm ($thm') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-## Casting sets as lists
-#(rule $Thms (all $set theorems)
-# (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-# (anchored 1))
-#(rule $Thms ($set theorems)
-# (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-# (anchored 1))
-#(rule $Thms (all $set)
-# (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-# (anchored 1))
-
-## Typed wildcards
-#(rule $tactic (\( $PHRASE : tactic \)) (IdentityFn) (anchored 1))
-#(rule $thm (\( $PHRASE : thm \)) (IdentityFn) (anchored 1))
-#(rule $thm->tactic (\( $PHRASE : thm->tactic \)) (IdentityFn) (anchored 1))
-#(rule $thmlist->tactic (\( $PHRASE : thm list -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $tactic->tactic (\( $PHRASE : tactic -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $thm->thm (\( $PHRASE : thm -> thm \)) (IdentityFn) (anchored 1))
-#(rule $termquotation->tactic (\( $PHRASE : term quotation -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $int->tactic->tactic (\( $PHRASE : int -> tactic -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotation->[thm->tactic]->tactic (\( $PHRASE : term quotation -> \( thm -> tactic \) -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $[thm->tactic]->tactic (\( $PHRASE : \( thm -> tactic \) -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotation*tactic->tactic (\( $PHRASE : term quotation * tactic -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotationlist->tactic (\( $PHRASE : term quotation list -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotation->[thm->tactic]->thm->tactic (\( $PHRASE : term quotation -> \( thm -> tactic \) -> thm -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotationlist->[thm->tactic]->thm->tactic (\( $PHRASE : term quotation list -> \( thm -> tactic \) -> thm -> tactic \)) (IdentityFn) (anchored 1))
-#
-##############################
-## NATURAL LANGUAGE SYNONYMS #
-##############################
-#
-## Theorem Lists
-#(rule $Thms ($Thms and $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $thmlist (nothing) (ConstantFn []) (anchored 1))
-#(rule $thmlist (empty list) (ConstantFn []) (anchored 1))
-#
-## Tactic composition
-#(rule $tactic ($tactic then $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic then $tactic on the first goal) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-#
-##############
-## OPTIONALS #
-##############
-## App
-#(for @cat ($thm->tactic $thmlist->tactic $tactic->tactic $thm->thm $termquotation->tactic $int->tactic->tactic)
-# (rule @cat ($Apply @cat) (SelectFn 1) (anchored 1)))
-#
-## Args
-#(for @cat ($tactic $thm $thmlist $termquotation)
-# (rule @cat ($Prep @cat) (SelectFn 1) (anchored 1)))
-
-########### UNUSED ###########
-#(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->tactic ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $termquotation (` $PHRASE `) (lambda e (call @quote (var e))) (anchored 1))
-# TODO: Necessary?
-#(rule $thm
-# ($TOKEN)
-# (SimpleLexiconFn (type "thm")) (anchored 1))
-#Disabled to make learning easier... See test on "repeat" in LassieTests
-#(rule $thmlist ($Thms) (lambda thms (call @list (var thms))) (anchored 1))
-#(rule $termquotationlist ($Terms) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-## Tactic composition
-#(rule $tactic ($tactic THEN $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic THEN1 $tactic) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic \\ $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic >- $tactic) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-#
\ No newline at end of file
diff --git a/examples/lassie/sempre/interactive/lassie.grammar_v2.0 b/examples/lassie/sempre/interactive/lassie.grammar_v2.0
deleted file mode 100644
index 92c5c5a114..0000000000
--- a/examples/lassie/sempre/interactive/lassie.grammar_v2.0
+++ /dev/null
@@ -1,366 +0,0 @@
- ############################################################################
- # GRAMMAR FOR NATURAL PROOF EXPRESSIONS #
- # #
- # Refer to SEMPRE's documentation for general indications on rule #
- # construction. #
- # #
- # Currently, domain knowledge comes from two sources. The lassie.lexicon #
- # file contains component names (e.g. fs) and with their types #
- # (e.g. thmlist->tactic, used for sound applications). Features of those #
- # components (e.g. their natural name, their class/type) are read from #
- # lassie.db into the TacticWorld. #
- # #
- # TacticWorld.java holds the main semantics of Lassie's operations, as #
- # we piggy back on the DALExecutor for handling the semantic part of #
- # this grammar. DALExecutor interprets semantic expression in a "world" #
- # containing "items". We superifcially follow this convention where HOL #
- # components can be considered the "items" of our "tactic-world". #
- # #
- # Generally, lowercased categories (e.g. $thm, $name) correspond to #
- # types as found in the lexicon/database. Categories which are #
- # capitalized are intermediates between lowercased categories and the #
- # $tactic category. #
- ############################################################################
-
-###########################################
-# Incorporated SML types: #
-###########################################
-# $tactic
-# $thm
-# ($thmlist)
-# $thm->tactic
-# $thmlist->tactic
-# $tactic->tactic
-# $thm->thm
-# $termquotation->tactic
-# $int->tactic->tactic
-# $termquotation->[thm->tactic]->tactic
-# $[thm->tactic]->tactic
-# $termquotation*tactic->tactic
-# $termquotationlist->tactic
-# $termquotation->[thm->tactic]->thm->tactic
-# $termquotationlist->[thm->tactic]->thm->tactic
-
- ################################################################
- # Define some abbreviations for calling into library functions #
- ################################################################
-(def @int2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.int2string)
-(def @app edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.app)
-(def @infix edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.infix)
-(def @then edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then)
-(def @then1 edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then1)
-(def @cons edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.cons)
-(def @list edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.list)
-(def @quote edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.quote)
-(def @parens edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.parens)
-(def @op edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.op)
-(def @fromFeature edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.fromFeature)
-(def @intersect edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.intersect)
-(def @set2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.set2string)
-(def @choice edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.choice)
-(def @tactic edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.tactic)
-(def @command edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.command)
-
-(def @ChoiceFn edu.stanford.nlp.sempre.interactive.lassie.ChoiceFn)
-
-(def @appT1T2 (lambda t1 (lambda t2 (call @app (var t1) (var t2)))))
-
-(def @infixT1T2T3 (lambda t1 (lambda t2 (lambda t3 (call @infix (var t1) (var t2) (var t3))))))
-
-###################################
-# GRAMMAR SUPPORTING LITERAL HOL4 #
-###################################
-
-# The root is always a tactic or a command
-(rule $ROOT ($tactic) (lambda t (call @tactic (var t))) (anchored 1))
-(rule $ROOT ($command) (lambda c (call @command (var c))) (anchored 1))
-
-# We can put parentheses around a tactic
-(for @cat ($tactic $command)
- (rule @cat (\( @cat \)) (lambda t (call @parens (var t))) (anchored 1)))
-
-# Literal SML tactics:
-(rule $tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic")) (anchored 1))
-
-# Literal SML tactic modifiers
-(rule $tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic->tactic")) (anchored 1))
-
-# Literal SML thm tactics:
-(rule $thm->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "thm->tactic") (anchored 1)))
-
-# Literal SML thm list tactics:
-(rule $thmlist->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "thmlist->tactic") (anchored 1)))
-
-# Literal Tactic combinators
-(rule $tactic->tactic->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "tactic->tactic->tactic") (anchored 1)))
-
-# Literal Term tactics
-(rule $termquotation->tactic
- ($TOKEN)
- (SimpleLexiconFn (type "termquotation->tactic") (anchored 1)))
-
-(rule $tactic ($thm->tactic $thm) @appT1T2 (anchored 1))
-(rule $tactic ($tactic->tactic $tactic) @appT1T2 (anchored 1))
-(rule $tactic ($thmlist->tactic $thmlist) @appT1T2 (anchored 1))
-(rule $tactic ($tactic $tactic->tactic->tactic $tactic) @infixT1T2T3 (anchored 1))
-(rule $tactic ($termquotation->tactic $termquotation) @appT1T2 (anchored 1))
-
-(rule $termquotation (` $PHRASE `) (lambda e (call @quote (var e))) (anchored 1))
-
-#Thm fallback:
-(rule $thm ($TOKEN) (IdentityFn) (anchored 1))
-
-# Lists
-(rule $thmlist ([ ]) (ConstantFn []) (anchored 1))
-(rule $thmlist ([ $Thms ]) (lambda thms (call @list (var thms))) (anchored 1))
-
-(rule $Thms ($TOKEN) (IdentityFn) (anchored 1))
-(rule $Thms ($thm , $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-
-#(rule $tactic ($thmlist->tactic $thmlist) @appT1T2 (anchored 1))
-#(rule $thm ($thm->thm $thm) @appT1T2 (anchored 1))
-
-#(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->tactic ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $tactic ($[thm->tactic]->tactic $thm->tactic) @appT1T2 (anchored 1))
-#(rule $tactic ($termquotationlist->tactic $termquotationlist) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->thm->tactic ($termquotation->[thm->tactic]->thm->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->thm->tactic ($termquotationlist->[thm->tactic]->thm->tactic $termquotationlist) @appT1T2 (anchored 1))
-#(rule $thm->tactic ($[thm->tactic]->thm->tactic $thm->tactic) @appT1T2 (anchored 1))
-
-
-
-## Literal Components Import
-#(rule $tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "tactic")) (anchored 1))
-#(rule $thm
-# ($TOKEN)
-# (SimpleLexiconFn (type "thm")) (anchored 1))
-#(rule $thm->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "thm->tactic")) (anchored 1))
-#(rule $thmlist->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "thmlist->tactic")) (anchored 1))
-#(rule $tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "tactic->tactic")) (anchored 1))
-#(rule $thm->thm
-# ($TOKEN)
-# (SimpleLexiconFn (type "thm->thm")) (anchored 1))
-#(rule $termquotation->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type term "quotation->tactic")) (anchored 1))
-#(rule $int->tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "int->tactic->tactic")) (anchored 1))
-#(rule $termquotation->[thm->tactic]->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation->[thm->tactic]->tactic")) (anchored 1))
-#(rule $[thm->tactic]->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "[thm->tactic]->tactic")) (anchored 1))
-#(rule $termquotation*tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation*tactic->tactic")) (anchored 1))
-#(rule $termquotationlist->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotationlist->tactic")) (anchored 1))
-#(rule $termquotation->[thm->tactic]->thm->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation->[thm->tactic]->thm->tactic")) (anchored 1))
-#(rule $termquotationlist->[thm->tactic]->thm->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotationlist->[thm->tactic]->thm->tactic")) (anchored 1))
-##Commands to the interactive prove interface
-#(rule $command
-# ($TOKEN)
-# (SimpleLexiconFn (type "command") (anchored 1)))
-#
-#(def @appT1T2 (lambda t1 (lambda t2 (call @app (var t1) (var t2)))))
-#
-## Applications
-#(rule $tactic ($thm->tactic $thm) @appT1T2 (anchored 1))
-#(rule $tactic ($thmlist->tactic $thmlist) @appT1T2 (anchored 1))
-#(rule $tactic ($tactic->tactic $tactic) @appT1T2 (anchored 1))
-#(rule $thm ($thm->thm $thm) @appT1T2 (anchored 1))
-#(rule $tactic ($termquotation->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->tactic ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $tactic ($[thm->tactic]->tactic $thm->tactic) @appT1T2 (anchored 1))
-#(rule $tactic ($termquotationlist->tactic $termquotationlist) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->thm->tactic ($termquotation->[thm->tactic]->thm->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->thm->tactic ($termquotationlist->[thm->tactic]->thm->tactic $termquotationlist) @appT1T2 (anchored 1))
-#(rule $thm->tactic ($[thm->tactic]->thm->tactic $thm->tactic) @appT1T2 (anchored 1))
-#
-## infix
-#(rule $tactic
-# ($termquotation $termquotation*tactic->tactic $tactic)
-# (lambda q (lambda by (lambda t (call @op (var by) (var q) (var t))))) (anchored 1))
-#
-## Typed wildcards
-#(rule $tactic (\( $PHRASE : tactic \)) (IdentityFn) (anchored 1))
-#(rule $thm (\( $PHRASE : thm \)) (IdentityFn) (anchored 1))
-#(rule $thm->tactic (\( $PHRASE : thm->tactic \)) (IdentityFn) (anchored 1))
-#(rule $thmlist->tactic (\( $PHRASE : thm list -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $tactic->tactic (\( $PHRASE : tactic -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $thm->thm (\( $PHRASE : thm -> thm \)) (IdentityFn) (anchored 1))
-#(rule $termquotation->tactic (\( $PHRASE : term quotation -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $int->tactic->tactic (\( $PHRASE : int -> tactic -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotation->[thm->tactic]->tactic (\( $PHRASE : term quotation -> \( thm -> tactic \) -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $[thm->tactic]->tactic (\( $PHRASE : \( thm -> tactic \) -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotation*tactic->tactic (\( $PHRASE : term quotation * tactic -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotationlist->tactic (\( $PHRASE : term quotation list -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotation->[thm->tactic]->thm->tactic (\( $PHRASE : term quotation -> \( thm -> tactic \) -> thm -> tactic \)) (IdentityFn) (anchored 1))
-#(rule $termquotationlist->[thm->tactic]->thm->tactic (\( $PHRASE : term quotation list -> \( thm -> tactic \) -> thm -> tactic \)) (IdentityFn) (anchored 1))
-#
-## Tactic composition
-#(rule $tactic ($tactic THEN $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic THEN1 $tactic) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic \\ $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic >- $tactic) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-#
-## Lists
-#(rule $Thms ($thm) (IdentityFn) (anchored 1))
-#(rule $Thms ($thm , $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $thmlist ([ $Thms ]) (lambda thms (call @list (var thms))) (anchored 1))
-#(rule $thmlist ($Thms) (lambda thms (call @list (var thms))) (anchored 1))
-#(rule $thmlist ([ ]) (ConstantFn []) (anchored 1))
-#
-#(rule $Terms ($termquotation) (IdentityFn) (anchored 1))
-#(rule $Terms ($termquotation , $Terms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $termquotationlist ([ $Terms ]) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-#(rule $termquotationlist ($Terms) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-#(rule $termquotationlist ([ ]) (ConstantFn []) (anchored 1))
-#
-## Other
-#(rule $termquotation (` $PHRASE `) (lambda e (call @quote (var e))) (anchored 1))
-#(rule $Number ($TOKEN) (NumberFn) (anchored 1))
-#(rule $int ($Number) (lambda n (call @int2string (var n))) (anchored 1))
-#
-#
-##############################
-## NATURAL LANGUAGE SYNONYMS #
-##############################
-#
-## Theorem Lists
-#(rule $Thms ($Thms and $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $thmlist (nothing) (ConstantFn []) (anchored 1))
-#(rule $thmlist (empty list) (ConstantFn []) (anchored 1))
-#
-## Tactic composition
-#(rule $tactic ($tactic then $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-#(rule $tactic ($tactic then $tactic on the first goal) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-#
-#
-################################################################
-## GRAMMAR SUPPORTING ABSTRACT DESCRIPTIONS OF HOL4 COMPONENTS #
-################################################################
-#
-## Sets and their intersections, by constructing imperative sentences
-#
-## Lexemes
-#(rule $type_lx ($PHRASE) (SimpleLexiconFn (type type)) (anchored 1))
-#(rule $name_lx ($PHRASE) (SimpleLexiconFn (type name)) (anchored 1))
-#(rule $AV_lx ($PHRASE) (SimpleLexiconFn (type AV)) (anchored 1))
-#(rule $VP_lx ($PHRASE) (SimpleLexiconFn (type VP)) (anchored 1))
-#(rule $OBJ_lx ($PHRASE) (SimpleLexiconFn (type OBJ)) (anchored 1))
-#(rule $CP_lx ($PHRASE) (SimpleLexiconFn (type CP)) (anchored 1))
-#(rule $PREARG_lx ($PHRASE) (SimpleLexiconFn (type PREARG)) (anchored 1))
-#
-#(rule $set_lx ($PHRASE) (SimpleLexiconFn (type set)) (anchored 1))
-#
-## Get sets
-#(def @fromFeatureX (lambda x (call @fromFeature (var x))))
-#(rule $type ($type_lx) @fromFeatureX (anchored 1))
-#(rule $name ($name_lx) @fromFeatureX (anchored 1))
-#(rule $AV ($AV_lx) @fromFeatureX (anchored 1))
-#(rule $VP ($VP_lx) @fromFeatureX (anchored 1))
-#(rule $OBJ ($OBJ_lx) @fromFeatureX (anchored 1))
-#(rule $CP ($CP_lx) @fromFeatureX (anchored 1))
-#(rule $PREARG ($PREARG_lx) @fromFeatureX (anchored 1))
-#
-#(rule $set ($set_lx) @fromFeatureX (anchored 1))
-#
-## Syntactically correct intersections
-#(def @intersectS1S2 (lambda s1 (lambda s2 (call @intersect (var s1) (var s2)))))
-#(rule $VP ($AV $VP) @intersectS1S2 (anchored 1))
-#(rule $VP ($VP $OBJ) @intersectS1S2 (anchored 1))
-#(rule $VP ($VP $CP) @intersectS1S2 (anchored 1))
-#(rule $VP ($VP $AV) @intersectS1S2 (anchored 1))
-#
-#(for @p (on with the)
-# (rule $Prep (@p) (ConstantFn null) (anchored 1)))
-#(rule $set ($set $set) @intersectS1S2 (anchored 1))
-#
-#(for @a (use apply)
-# (rule $Apply (@a) (ConstantFn null) (anchored 1)))
-#
-#(rule $VP' ($Apply $name) (SelectFn 1) (anchored 1))
-#(rule $VP' ($name) (IdentityFn) (anchored 1))
-#(rule $VP' ($VP' $type) @intersectS1S2 (anchored 1))
-#(rule $VP' ($type $VP') @intersectS1S2 (anchored 1))
-#(rule $VP' ($VP) (IdentityFn) (anchored 1))
-#(rule $VP' ($VP' $PREARG) @intersectS1S2 (anchored 1))
-#(rule $VP' ($VP' with) (SelectFn 0) (anchored 1))
-#
-## Collapsing sets to single components
-#(rule $tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.tactic")))) (anchored 1))
-#(rule $tactic ($tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $thm->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm -> tactic")))) (anchored 1))
-#(rule $thm->tactic ($thm->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $thmlist->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm list -> tactic")))) (anchored 1))
-#(rule $thmlist->tactic ($thmlist->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $tactic->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.tactic -> tactic")))) (anchored 1))
-#(rule $tactic->tactic ($tactic->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $thm->thm' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm -> thm")))) (anchored 1))
-#(rule $thm->thm ($thm->thm') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $termquotation->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.term quotation -> tactic")))) (anchored 1))
-#(rule $termquotation->tactic ($termquotation->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#(rule $int->tactic->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.int -> tactic -> tactic")))) (anchored 1))
-#(rule $int->tactic->tactic ($int->tactic->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#
-## Theorems
-#(rule $thm' ($set) (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm")))) (anchored 1))
-#(rule $thm ($thm') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-## Casting sets as lists
-#(rule $Thms (all $set theorems)
-# (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-# (anchored 1))
-#(rule $Thms ($set theorems)
-# (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-# (anchored 1))
-#(rule $Thms (all $set)
-# (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-# (anchored 1))
-#
-#
-##############
-## OPTIONALS #
-##############
-## App
-#(for @cat ($thm->tactic $thmlist->tactic $tactic->tactic $thm->thm $termquotation->tactic $int->tactic->tactic)
-# (rule @cat ($Apply @cat) (SelectFn 1) (anchored 1)))
-#
-## Args
-#(for @cat ($tactic $thm $thmlist $termquotation)
-# (rule @cat ($Prep @cat) (SelectFn 1) (anchored 1)))
diff --git a/examples/lassie/sempre/interactive/lassie.grammar_v2.1 b/examples/lassie/sempre/interactive/lassie.grammar_v2.1
deleted file mode 100644
index b8f258b3b4..0000000000
--- a/examples/lassie/sempre/interactive/lassie.grammar_v2.1
+++ /dev/null
@@ -1,340 +0,0 @@
- ############################################################################
- # GRAMMAR FOR NATURAL PROOF EXPRESSIONS #
- # #
- # Refer to SEMPRE's documentation for general indications on rule #
- # construction. #
- # #
- # Currently, domain knowledge comes from two sources. The lassie.lexicon #
- # file contains component names (e.g. fs) and with their types #
- # (e.g. thmlist->tactic, used for sound applications). Features of those #
- # components (e.g. their natural name, their class/type) are read from #
- # lassie.db into the TacticWorld. #
- # #
- # TacticWorld.java holds the main semantics of Lassie's operations, as #
- # we piggy back on the DALExecutor for handling the semantic part of #
- # this grammar. DALExecutor interprets semantic expression in a "world" #
- # containing "items". We superifcially follow this convention where HOL #
- # components can be considered the "items" of our "tactic-world". #
- # #
- # Generally, lowercased categories (e.g. $thm, $name) correspond to #
- # types as found in the lexicon/database. Categories which are #
- # capitalized are intermediates between lowercased categories and the #
- # $tactic category. #
- ############################################################################
-
-###########################################
-# Incorporated SML types: #
-###########################################
-# $tactic
-# $thm
-# ($thmlist)
-# $thm->tactic
-# $thmlist->tactic
-# $tactic->tactic
-# $thm->thm
-# $termquotation->tactic
-# $int->tactic->tactic
-# $termquotation->[thm->tactic]->tactic
-# $[thm->tactic]->tactic
-# $termquotation*tactic->tactic
-# $termquotationlist->tactic
-# $termquotation->[thm->tactic]->thm->tactic
-# $termquotationlist->[thm->tactic]->thm->tactic
-
- ################################################################
- # Define some abbreviations for calling into library functions #
- ################################################################
-(def @int2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.int2string)
-(def @app edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.app)
-(def @infix edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.infix)
-(def @then edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then)
-(def @then1 edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.then1)
-(def @cons edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.cons)
-(def @list edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.list)
-(def @quote edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.quote)
-(def @parens edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.parens)
-(def @op edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.op)
-(def @fromFeature edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.fromFeature)
-(def @intersect edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.intersect)
-(def @set2string edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.set2string)
-(def @choice edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.choice)
-(def @tactic edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.tactic)
-(def @command edu.stanford.nlp.sempre.interactive.lassie.TacticWorld.command)
-
-(def @ChoiceFn edu.stanford.nlp.sempre.interactive.lassie.ChoiceFn)
-
-(def @appT1T2 (lambda t1 (lambda t2 (call @app (var t1) (var t2)))))
-(def @infixT1T2T3 (lambda t1 (lambda t2 (lambda t3 (call @op (var t2) (var t1) (var t3))))))
-
-###################################
-# GRAMMAR SUPPORTING LITERAL HOL4 #
-###################################
-
-(rule $ROOT ($tactic) (IdentityFn) (anchored 1))
-
-###############################################################
-## literal SML objects, looked up from the database #
-###############################################################
-## tactics
-(rule $tactic
- ($TOKEN)
- (call @tactic (SimpleLexiconFn (type "tactic"))) (anchored 1))
-
-# The root is always a tactic or a command
-#(rule $ROOT ($tactic) (IdentityFn) (anchored 1))
-#(rule $ROOT ($command) (lambda c (call @command (var c))) (anchored 1))
-#
-## Tactics can be produced by combining different constructs
-#(for @category
-# (($thm->tactic $thm) ($tactic->tactic $tactic) ($thmlist->tactic $thmlist)
-# ($termquotation->tactic $termquotation)
-# ($[thm->tactic]->tactic $thm->tactic))
-# (rule $tactic @category @appT1T2 (anchored 1)))
-#(rule $tactic ($termquotation $termquotation*tactic->tactic $tactic) @infixT1T2T3 (anchored 1))
-## Support for inline THEN
-#(rule $tactic ($tactic $tactic->tactic->tactic $tactic) @infixT1T2T3 (anchored 1))
-#
-## Partial applications for things like qpat_x_assum or first_x_assum
-#(rule $[thm->tactic]->tactic
-# ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->thm->tactic
-# ($termquotation->[thm->tactic]->thm->tactic $termquotation) @appT1T2 (anchored 1))
-#(rule $[thm->tactic]->thm->tactic
-# ($termquotationlist->[thm->tactic]->thm->tactic $termquotationlist) @appT1T2 (anchored 1))
-#(rule $thm->tactic ($[thm->tactic]->thm->tactic $thm->tactic) @appT1T2 (anchored 1))
-#(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-#
-## We can put parentheses around a tactic or a command
-#(for @cat ($ROOT $command $tactic)
-# (rule @cat (\( @cat \)) (lambda t (call @parens (var t))) (anchored 1)))
-#
-###############################################################
-## literal SML objects, looked up from the database #
-###############################################################
-## tactic modifiers
-#(rule $tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "tactic->tactic")) (anchored 1))
-## thm tactics
-#(rule $thm->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "thm->tactic") (anchored 1)))
-## thm list tactics:
-#(rule $thmlist->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "thmlist->tactic") (anchored 1)))
-## tactic combinators
-#(rule $tactic->tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "tactic->tactic->tactic") (anchored 1)))
-## term tactics
-#(rule $termquotation->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation->tactic") (anchored 1)))
-## first_x_assum, last_x_assum, ...
-#(rule $[thm->tactic]->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "[thm->tactic]->tactic") (anchored 1)))
-## qspec
-#(rule $termquotation->[thm->tactic]->thm->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation->[thm->tactic]->thm->tactic") (anchored 1)))
-## qspecl
-#(rule $termquotationlist->[thm->tactic]->thm->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotationlist->[thm->tactic]->thm->tactic") (anchored 1)))
-## qpat_x_assum, qpat_assum, ...
-#(rule $termquotation->[thm->tactic]->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation->[thm->tactic]->tactic")) (anchored 1))
-## ntac
-#(rule $int->tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "int->tactic->tactic")) (anchored 1))
-#(rule $termquotation*tactic->tactic
-# ($TOKEN)
-# (SimpleLexiconFn (type "termquotation*tactic->tactic")) (anchored 1))
-#(rule $thm->thm
-# ($TOKEN)
-# (SimpleLexiconFn (type "thm->thm")) (anchored 1))
-#
-##### HOL4 Terms
-#(rule $termquotation (` $term ') (lambda e (call @quote (var e))) (anchored 1))
-#(rule $termquotation (' $term ') (lambda e (call @quote (var e))) (anchored 1))
-#(rule $term ($PHRASE) (IdentityFn) (anchored 1))
-#(rule $term ($term and $term) (lambda t1 (lambda t2 (call @op (string "∧") (var t1) (var t2)))) (anchored 1))
-#(rule $term ($term or $term) (lambda t1 (lambda t2 (call @op (string "∨") (var t1) (var t2)))) (anchored 1))
-#
-#(rule $Terms ($termquotation) (IdentityFn) (anchored 1))
-#(rule $Terms ($termquotation , $Terms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $termquotationlist ([ $Terms ]) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-#(rule $termquotationlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-#(rule $termquotationlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-#
-##### HOL4 Theorems
-#(rule $thm ($thm->thm $thm) @appT1T2 (anchored 1))
-#(rule $thm ($TOKEN) (IdentityFn) (anchored 1))
-#
-### Lists
-#(rule $Thms ($thm) (IdentityFn) (anchored 1))
-#(rule $Thms ($thm , $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-#(rule $thmlist ([ $Thms ]) (lambda thms (call @list (var thms))) (anchored 1))
-#(rule $thmlist ([]) (ConstantFn (call @list (string " "))) (anchored 1))
-#(rule $thmlist ([ ]) (ConstantFn (call @list (string " "))) (anchored 1))
-#
-#
-###Commands to the interactive prove interface
-#(rule $command
-# (back)
-# (ConstantFn (string "(b)")) (anchored 1))
-#
-### Other
-#(rule $Number ($TOKEN) (NumberFn) (anchored 1))
-#(rule $int ($Number) (lambda n (call @int2string (var n))) (anchored 1))
-#
-#################################################################
-### GRAMMAR SUPPORTING ABSTRACT DESCRIPTIONS OF HOL4 COMPONENTS #
-#################################################################
-#
-### Sets and their intersections, by constructing imperative sentences
-#
-### Lexemes
-##(rule $type_lx ($PHRASE) (SimpleLexiconFn (type type)) (anchored 1))
-##(rule $name_lx ($PHRASE) (SimpleLexiconFn (type name)) (anchored 1))
-##(rule $AV_lx ($PHRASE) (SimpleLexiconFn (type AV)) (anchored 1))
-##(rule $VP_lx ($PHRASE) (SimpleLexiconFn (type VP)) (anchored 1))
-##(rule $OBJ_lx ($PHRASE) (SimpleLexiconFn (type OBJ)) (anchored 1))
-##(rule $CP_lx ($PHRASE) (SimpleLexiconFn (type CP)) (anchored 1))
-##(rule $PREARG_lx ($PHRASE) (SimpleLexiconFn (type PREARG)) (anchored 1))
-##
-##(rule $set_lx ($PHRASE) (SimpleLexiconFn (type set)) (anchored 1))
-##
-#### Get sets
-##(def @fromFeatureX (lambda x (call @fromFeature (var x))))
-##(rule $type ($type_lx) @fromFeatureX (anchored 1))
-##(rule $name ($name_lx) @fromFeatureX (anchored 1))
-##(rule $AV ($AV_lx) @fromFeatureX (anchored 1))
-##(rule $VP ($VP_lx) @fromFeatureX (anchored 1))
-##(rule $OBJ ($OBJ_lx) @fromFeatureX (anchored 1))
-##(rule $CP ($CP_lx) @fromFeatureX (anchored 1))
-##(rule $PREARG ($PREARG_lx) @fromFeatureX (anchored 1))
-##
-##(rule $set ($set_lx) @fromFeatureX (anchored 1))
-##
-#### Syntactically correct intersections
-##(def @intersectS1S2 (lambda s1 (lambda s2 (call @intersect (var s1) (var s2)))))
-##(rule $VP ($AV $VP) @intersectS1S2 (anchored 1))
-##(rule $VP ($VP $OBJ) @intersectS1S2 (anchored 1))
-##(rule $VP ($VP $CP) @intersectS1S2 (anchored 1))
-##(rule $VP ($VP $AV) @intersectS1S2 (anchored 1))
-##
-##(for @p (on with the)
-## (rule $Prep (@p) (ConstantFn null) (anchored 1)))
-##(rule $set ($set $set) @intersectS1S2 (anchored 1))
-##
-##(for @a (use apply)
-## (rule $Apply (@a) (ConstantFn null) (anchored 1)))
-##
-##(rule $VP' ($Apply $name) (SelectFn 1) (anchored 1))
-##(rule $VP' ($name) (IdentityFn) (anchored 1))
-##(rule $VP' ($VP' $type) @intersectS1S2 (anchored 1))
-##(rule $VP' ($type $VP') @intersectS1S2 (anchored 1))
-##(rule $VP' ($VP) (IdentityFn) (anchored 1))
-##(rule $VP' ($VP' $PREARG) @intersectS1S2 (anchored 1))
-##(rule $VP' ($VP' with) (SelectFn 0) (anchored 1))
-##
-#### Collapsing sets to single components
-##(rule $tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.tactic")))) (anchored 1))
-##(rule $tactic ($tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-##(rule $thm->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm -> tactic")))) (anchored 1))
-##(rule $thm->tactic ($thm->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-##(rule $thmlist->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm list -> tactic")))) (anchored 1))
-##(rule $thmlist->tactic ($thmlist->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-##(rule $tactic->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.tactic -> tactic")))) (anchored 1))
-##(rule $tactic->tactic ($tactic->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-##(rule $thm->thm' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm -> thm")))) (anchored 1))
-##(rule $thm->thm ($thm->thm') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-##(rule $termquotation->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.term quotation -> tactic")))) (anchored 1))
-##(rule $termquotation->tactic ($termquotation->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-##(rule $int->tactic->tactic' ($VP') (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.int -> tactic -> tactic")))) (anchored 1))
-##(rule $int->tactic->tactic ($int->tactic->tactic') (interactive.lassie.ChoiceFn) (anchored 1))
-#
-#
-### Theorems
-##(rule $thm' ($set) (lambda s (call @choice (call @intersect (var s) (call @fromFeature "type.thm")))) (anchored 1))
-##(rule $thm ($thm') (interactive.lassie.ChoiceFn) (anchored 1))
-##
-### Casting sets as lists
-##(rule $Thms (all $set theorems)
-## (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-## (anchored 1))
-##(rule $Thms ($set theorems)
-## (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-## (anchored 1))
-##(rule $Thms (all $set)
-## (lambda s (call @set2string (call @intersect (var s) (call @fromFeature "type.thm"))))
-## (anchored 1))
-#
-### Typed wildcards
-##(rule $tactic (\( $PHRASE : tactic \)) (IdentityFn) (anchored 1))
-##(rule $thm (\( $PHRASE : thm \)) (IdentityFn) (anchored 1))
-##(rule $thm->tactic (\( $PHRASE : thm->tactic \)) (IdentityFn) (anchored 1))
-##(rule $thmlist->tactic (\( $PHRASE : thm list -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $tactic->tactic (\( $PHRASE : tactic -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $thm->thm (\( $PHRASE : thm -> thm \)) (IdentityFn) (anchored 1))
-##(rule $termquotation->tactic (\( $PHRASE : term quotation -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $int->tactic->tactic (\( $PHRASE : int -> tactic -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $termquotation->[thm->tactic]->tactic (\( $PHRASE : term quotation -> \( thm -> tactic \) -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $[thm->tactic]->tactic (\( $PHRASE : \( thm -> tactic \) -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $termquotation*tactic->tactic (\( $PHRASE : term quotation * tactic -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $termquotationlist->tactic (\( $PHRASE : term quotation list -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $termquotation->[thm->tactic]->thm->tactic (\( $PHRASE : term quotation -> \( thm -> tactic \) -> thm -> tactic \)) (IdentityFn) (anchored 1))
-##(rule $termquotationlist->[thm->tactic]->thm->tactic (\( $PHRASE : term quotation list -> \( thm -> tactic \) -> thm -> tactic \)) (IdentityFn) (anchored 1))
-##
-###############################
-### NATURAL LANGUAGE SYNONYMS #
-###############################
-##
-### Theorem Lists
-##(rule $Thms ($Thms and $Thms) (lambda t1 (lambda t2 (call @cons (var t1) (var t2)))) (anchored 1))
-##(rule $thmlist (nothing) (ConstantFn []) (anchored 1))
-##(rule $thmlist (empty list) (ConstantFn []) (anchored 1))
-##
-### Tactic composition
-##(rule $tactic ($tactic then $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-##(rule $tactic ($tactic then $tactic on the first goal) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-##
-###############
-### OPTIONALS #
-###############
-### App
-##(for @cat ($thm->tactic $thmlist->tactic $tactic->tactic $thm->thm $termquotation->tactic $int->tactic->tactic)
-## (rule @cat ($Apply @cat) (SelectFn 1) (anchored 1)))
-##
-### Args
-##(for @cat ($tactic $thm $thmlist $termquotation)
-## (rule @cat ($Prep @cat) (SelectFn 1) (anchored 1)))
-#
-############ UNUSED ###########
-##(rule $tactic->tactic ($int->tactic->tactic $int) @appT1T2 (anchored 1))
-##(rule $[thm->tactic]->tactic ($termquotation->[thm->tactic]->tactic $termquotation) @appT1T2 (anchored 1))
-##(rule $termquotation (` $PHRASE `) (lambda e (call @quote (var e))) (anchored 1))
-## TODO: Necessary?
-##(rule $thm
-## ($TOKEN)
-## (SimpleLexiconFn (type "thm")) (anchored 1))
-##Disabled to make learning easier... See test on "repeat" in LassieTests
-##(rule $thmlist ($Thms) (lambda thms (call @list (var thms))) (anchored 1))
-##(rule $termquotationlist ($Terms) (lambda termquotations (call @list (var termquotations))) (anchored 1))
-### Tactic composition
-##(rule $tactic ($tactic THEN $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-##(rule $tactic ($tactic THEN1 $tactic) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-##(rule $tactic ($tactic \\ $tactic) (lambda t1 (lambda t2 (call @then (var t1) (var t2)))) (anchored 1))
-##(rule $tactic ($tactic >- $tactic) (lambda t1 (lambda t2 (call @then1 (var t1) (var t2)))) (anchored 1))
-##
diff --git a/examples/lassie/sempre/interactive/lassie.synonyms b/examples/lassie/sempre/interactive/lassie.synonyms
deleted file mode 100644
index 4cbe426ad0..0000000000
--- a/examples/lassie/sempre/interactive/lassie.synonyms
+++ /dev/null
@@ -1,2 +0,0 @@
-{"lexeme":"theorem","formula":"type.thm","type":"type"}
-{"lexeme":"add","formula":"name.addition","type":"name"}
\ No newline at end of file
diff --git a/examples/lassie/sempre/interactive/run b/examples/lassie/sempre/interactive/run
deleted file mode 100755
index 6be2ac07bc..0000000000
--- a/examples/lassie/sempre/interactive/run
+++ /dev/null
@@ -1,314 +0,0 @@
-#!/usr/bin/env ruby
-
-# This is the main entry point for running SHRDLURN. See
-# fig/lib/execrunner.rb for more documentation for how commands are generated.
-# There are a bunch of modes that this script can be invoked with, which
-# loosely correspond to the modules.
-
-$: << 'fig/lib'
-require 'execrunner'
-$optPrefix = '-'
-$path = 'interactive'
-$output = 'interactive/output'
-$modes = []
-def addMode(name, description, func)
- $modes << [name, description, func]
-end
-
-def codalab(dependencies=nil)
- # Set @cl=1 to run job on CodaLab
- dependencies ||= l(':fig', ':lib', ':module-classes.txt', ':libsempre')
- l(
- letDefault(:cl, 0),
- sel(:cl,
- l(),
- l('cl', 'run', dependencies, '---', 'LC_ALL=C.UTF-8'),
- nil),
- nil)
-end
-
-def header(modules='core', codalabDependencies=nil)
- l(
- codalab(codalabDependencies),
- # Queuing system
- letDefault(:q, 0), sel(:q, l(), l('fig/bin/q', '-shareWorkingPath', o('mem', '5g'), o('memGrace', 10), '-add', '---')),
- # Create execution directory
- letDefault(:pooldir, 1),
- sel(:pooldir, l(), 'fig/bin/qcreate'),
- # Run the Java command...
- 'java',
- '-ea',
- '-Dmodules='+modules,
- # Memory size; set to low to work with HOL regression server
- letDefault(:memsize, 'low'),
- sel(:memsize, {
- 'tiny' => l('-Xms2G', '-Xmx4G'),
- 'low' => l('-Xms5G', '-Xmx7G'),
- 'default' => l('-Xms8G', '-Xmx10G'),
- 'medium' => l('-Xms12G', '-Xmx14G'),
- 'high' => l('-Xms20G', '-Xmx24G'),
- 'higher' => l('-Xms40G', '-Xmx50G'),
- 'impressive' => l('-Xms75G', '-Xmx90G'),
- }),
- # Classpath
- '-cp', 'libsempre/*:lib/*',
- # Profiling
- letDefault(:prof, 0), sel(:prof, l(), '-Xrunhprof:cpu=samples,depth=100,file=_OUTPATH_/java.hprof.txt'),
- # Debugging
- letDefault(:debug, 0), sel(:debug, l(), l('-Xdebug', '-Xrunjdwp:server=y,transport=dt_socket,suspend=y,address=8898')),
- nil)
-end
-
-def figOpts; l(selo(:pooldir, 'execDir', 'exec', '_OUTPATH_'), o('overwriteExecDir'), o('addToView', 0), o('monitor', 'false')) end
-
-############################################################
-# Unit tests
-
-addMode('backup', 'small commands like run community server, backup, or simulator', lambda { |e| l(
- lambda { |e| system 'echo "backing up with mv"'},
- lambda { |e| system 'mkdir -p ./int-backup/'},
- letDefault(:msg, 'backing up, no message'),
- lambda { |e| l('echo ', :msg, '> ./int-backup/message')},
- lambda { |e| l('echo ', '`date +%Y-%m-%d.%H:%M:%S`', '>> ./int-backup/message')},
- lambda { |e| system 'mv int-output int-backup/`date +%Y-%m-%d.%H:%M:%S`'},
- lambda { |e| system 'mkdir -p ./int-output'},
-nil)})
-
-addMode('backup-data', 'put community-server into trash with time stamp', lambda { |e| l(
- lambda { |e| system 'echo "backing up data with mv"'},
- lambda { |e| system 'mkdir -p ./community-server/data-backup'},
- lambda { |e| system 'mv ./community-server/data ./community-server/data-backup/`date +%Y-%m-%d.%H:%M:%S`'},
-nil)})
-
-addMode('trash', 'put int-output into trash with time stamp', lambda { |e| l(
- lambda { |e| system 'echo "trashing int-output with time stamp"'},
- lambda { |e| system 'mv int-output int-output-trash-`date +%Y-%m-%d.%H:%M:%S`'},
- lambda { |e| system 'rm -rf int-output-trash-*'},
- lambda { |e| system 'mkdir -p ./int-output'},
-nil)})
-
-addMode('test', 'Run unit tests for interactive stuff', lambda { |e|
- l(
- 'java', '-ea', '-Xmx12g', '-cp', 'libsempre/*:lib/*',
- letDefault(:debug, 0), sel(:debug, l(), l('-Xdebug', '-Xrunjdwp:server=y,transport=dt_socket,suspend=y,address=8898')),
- 'org.testng.TestNG',
- lambda { |e|
- if e[:class]
- l('-testclass', 'edu.stanford.nlp.sempre.interactive.test.' + e[:class])
- else
- "./#{$path}/testng.xml"
- end
- },
- nil)
-})
-
-addMode('simulator', 'run the simulator', lambda { |e| l(
- # rlwrap,
- header('core,interactive'),
- 'edu.stanford.nlp.sempre.interactive.Simulator',
- figOpts,
- letDefault(:server, 'local'),
- sel(:server, {
- 'local' => o('serverURL', 'http://localhost:8410'),
- 'remote' => o('serverURL', 'http://jonsson.stanford.edu:8410')
- }),
- # set to 0 to enable logging
- o('numThreads', 1),
- letDefault(:sandbox, 'full'),
- sel(:sandbox, {
- 'all' => o('reqParams', 'grammar=0\&cite=0\&learn=0\&logging=0'),
- 'nolog' => o('reqParams', 'grammar=0\&cite=0\&learn=1\&logging=0'),
- 'nolearn' => o('reqParams', 'grammar=1\&cite=1\&learn=0\&logging=0'),
- 'none' => o('reqParams', 'grammar=1\&cite=1\&learn=1\&logging=0'),
- 'nocite' => o('reqParams', 'grammar=1\&cite=0\&learn=1\&logging=0'),
- }),
- letDefault(:task, 'sidaw'),
- sel(:task, {
- 'freebuild' => o('logFiles', "./#{$path}/queries/freebuild.json.gz"),
- 'freebuilddef' => o('logFiles', "./#{$path}/queries/freebuild.def.json.gz"),
-
- 'qual1' => o('logFiles', "./#{$path}/queries/rawqueries/qualifier1-0118.json.gz"),
- 'qual2' => o('logFiles', "./#{$path}/queries/rawqueries/qualifier2-0129.json.gz"),
- 'qual3' => o('logFiles', "./#{$path}/queries/rawqueries/qualifier3-0201.json.gz"), # both 2 and 3
- 'free1' => o('logFiles', "./#{$path}/queries/rawqueries/freebuild1-0121.json.gz"),
- 'free2' => o('logFiles', "./#{$path}/queries/rawqueries/freebuild2-0127.json.gz"),
- }),
-nil)})
-
-############################################################
-# {2016-07-02} [sidaw]: interactive semantic parsing
-addMode('voxelurn', 'interactive semantic parsing in a VoxelWorld', lambda { |e| l(
- #rlwrap,
- header('core,interactive'),
- 'edu.stanford.nlp.sempre.Main',
- #figOpts,
- o('server'),
- o('masterType', 'edu.stanford.nlp.sempre.interactive.InteractiveMaster'),
- o('Executor', 'interactive.DALExecutor'),
- o('LanguageAnalyzer', 'interactive.DALAnalyzer'),
- o('DALExecutor.convertNumberValues', true),
- o('DALExecutor.printStackTrace', true),
- o('VoxelWorld.maxBlocks', 100000),
- selo(0, 'DALExecutor.worldType', 'VoxelWorld', 'CalendarWorld', 'Otherworld'),
- selo(0, 'Grammar.inPaths', "./#{$path}/voxelurn.grammar"),
-
- o('Params.initWeightsRandomly', false),
- o('Grammar.binarizeRules', false),
- o('Grammar.useApplyFn', 'interactive.ApplyFn'),
-
- o('LanguageAnalyzer.lowerCaseTokens', true),
-
- o('Parser.pruneErrorValues', true),
- o('Parser', 'interactive.InteractiveBeamParser'),
- o('Parser.callSetEvaluation', false),
- o('Parser.coarsePrune', true),
-
- o('Parser.beamSize', 50),
- o('InteractiveBeamParser.maxNewTreesPerSpan', 5001),
- o('ParserState.customExpectedCounts', 'None'),
-
- selo(0, 'InteractiveBeamParser.floatStrategy', 'Never', 'NoParse', 'Always'),
- o('InteractiveBeamParser.trackedCats', 'Number', 'Numbers', 'Color', 'Direction', 'Set', 'Sets', 'Action', 'Actions'),
-
- o('Derivation.derivComparator', 'AnchorPriorityScoreComparator'),
- o('Params.l1Reg', 'nonlazy'),
- o('Params.l1RegCoeff', 0.0001),
-
- o('Params.initStepSize', 0.1),
- o('Params.adaptiveStepSize', true),
- #o('Params.stepSizeReduction', 0.25),
-
- o('FeatureExtractor.featureComputers', 'interactive.DALFeatureComputer'),
- o('FeatureExtractor.featureDomains', ':rule', ':span', ':stats', ':scope', ':social', ':window'),
- # o('FeatureExtractor.featureDomains', ':rule'),
-
- o('InteractiveMaster.intOutputPath', './int-output/'),
- o('InteractiveMaster.onlyInteractive', true),
- o('InteractiveUtils.citationPath', './int-output/citation/'),
-
- o('InteractiveMaster.useAligner', false),
- o('InteractiveMaster.maxSequence', 20),
- o('InteractiveMaster.maxChars', 200),
-
- o('DefinitionAligner.strategies', 'ExactExclusion'),
-
- o('InteractiveServer.numThreads', 16),
- o('InteractiveServer.maxCandidates', 50),
- o('InteractiveServer.queryLogPath', './int-output/query.log'),
- o('InteractiveServer.responseLogPath', './int-output/response.log'),
- o('InteractiveServer.port', 8410),
-
- o('GrammarInducer.useBestPacking', true),
- o('GrammarInducer.useSimplePacking', true),
- o('GrammarInducer.maxNonterminals', 3),
-
- o('Derivation.showTypes', false),
- o('Derivation.showValues', false),
- o('Derivation.showRules', false),
- o('Derivation.anchoredBonus', 1.0),
-
- o('NumberFn.allowedRange', 0, 100),
- o('SimpleLexicon.inPaths', "./#{$path}/csscolors.lexicon"),
-
- lambda { |e| system 'mkdir -p ./int-output/'; nil},
- lambda { |e| system 'mkdir -p ./int-output/log/'; nil},
- lambda { |e| system 'mkdir -p ./int-output/citation/'; nil},
-nil) })
-
-############################################################
-# {2019-06-12} [nbos]: Natural Language Parsing for HOL4
-addMode('lassie', 'interactive semantic parsing for proving theorems in HOL4', lambda { |e| l(
- #rlwrap,
- header('core,interactive'),
- 'edu.stanford.nlp.sempre.Main',
- figOpts,
- o('interactive'),
- o('masterType', 'edu.stanford.nlp.sempre.interactive.InteractiveMaster'),
-
- o('Executor', 'JavaExecutor'), # Change executor for different semantics
- o('JavaExecutor.convertNameValues', true),
-
- o('LanguageAnalyzer', 'interactive.DALAnalyzer'),
- o('Grammar.inPaths', "./#{$path}/lassie.grammar"),
-
- o('InteractiveMaster.allowRegularCommands', true),
- o('HOLOntology.dbPath', "./#{$path}/lassie.db"),
- o('HOLOntology.lexPath', "./#{$path}/lassie.lexicon"),
- # o('HOLOntology.seedGrammarPath', "./#{$path}/lassie.seed.grammar"),
- # o('HOLOntology.genGrammarPath', "./#{$path}/lassie.generated.grammar"),
-
- o('Params.initWeightsRandomly', false),
- o('Grammar.binarizeRules', false),
- o('Grammar.useApplyFn', 'interactive.ApplyFn'),
-
- o('LanguageAnalyzer.lowerCaseTokens', false),
- o('SimpleLexicon.lowerCaseTokens', false),
-
- o('Parser.pruneErrorValues', true),
- o('Parser', 'interactive.InteractiveBeamParser'),
- o('Parser.callSetEvaluation', false),
- o('Parser.coarsePrune', true),
-
- o('Parser.beamSize', 100),
- o('InteractiveBeamParser.maxNewTreesPerSpan', 5001),
- o('ParserState.customExpectedCounts', 'None'),
-
- selo(0, 'InteractiveBeamParser.floatStrategy', 'Never', 'NoParse', 'Always'),
- o('InteractiveBeamParser.trackedCats', 'Number', 'Numbers', 'Color', 'Direction', 'Set', 'Sets', 'Action', 'Actions'),
-
- o('Derivation.derivComparator', 'AnchorPriorityScoreComparator'),
- o('Params.l1Reg', 'nonlazy'),
- o('Params.l1RegCoeff', 0.0001),
-
- o('Params.initStepSize', 0.1),
- o('Params.adaptiveStepSize', true),
- #o('Params.stepSizeReduction', 0.25),
-
- # o('FeatureExtractor.featureComputers', 'interactive.DALFeatureComputer'),
- # o('FeatureExtractor.featureDomains', ':rule', ':span', ':stats', ':scope', ':social', ':window'),
- # o('FeatureExtractor.featureDomains', ':rule'),
-
- o('InteractiveMaster.intOutputPath', './int-output/'),
- o('InteractiveMaster.onlyInteractive', true),
- o('InteractiveUtils.citationPath', './int-output/citation/'),
-
- o('InteractiveMaster.useAligner', false),
- o('InteractiveMaster.maxSequence', 20),
- o('InteractiveMaster.maxChars', 200),
-
- o('DefinitionAligner.strategies', 'ExactExclusion'),
-
- o('GrammarInducer.useBestPacking', true),
- o('GrammarInducer.useSimplePacking', false),
- o('GrammarInducer.maxNonterminals', 5), # default 3
- o('GrammarInducer.minTerminals', 0), # default 1
-
- o('Derivation.showTypes', false),
- o('Derivation.showValues', false),
- o('Derivation.showRules', false),
- o('Derivation.anchoredBonus', 1.0),
-
- o('NumberFn.allowedRange', 0, 100),
- o('SimpleLexicon.inPaths', "./#{$path}/lassie.lexicon", "./#{$path}/lassie.synonyms"),
-
- lambda { |e| system 'mkdir -p ./int-output/'; nil},
- lambda { |e| system 'mkdir -p ./int-output/log/'; nil},
- lambda { |e| system 'mkdir -p ./int-output/citation/'; nil},
-nil) })
-############################################################
-
-if ARGV.size == 0
- puts "#{$0} @mode= [options]"
- puts
- puts 'This is the main entry point for all interactive related modes.'
- puts "Modes:"
- $modes.each { |name,description,func|
- puts " #{name}: #{description}"
- }
-end
-
-modesMap = {}
-$modes.each { |name,description,func|
- modesMap[name] = func
-}
-run!(sel(:mode, modesMap))
diff --git a/examples/lassie/sempre/pull-dependencies b/examples/lassie/sempre/pull-dependencies
deleted file mode 100755
index 0757939aec..0000000000
--- a/examples/lassie/sempre/pull-dependencies
+++ /dev/null
@@ -1,332 +0,0 @@
-#!/usr/bin/env ruby
-
-# SEMPRE depends on several library/data files into |lib|. Run this script to
-# copy those dependencies to your local directory. This allows you to run
-# SEMPRE from anywhere. This file consists of a set of modules (which loosely
-# correspond to the code modules).
-#
-# The master copy of these dependencies are stored on the Stanford NLP machines.
-#
-# Usage:
-# ./pull-dependencies ...
-#
-# For developers with ssh access to NLP machines, there are two more local commands:
-# - Copy or link |sourcePath| into lib/|dir|.
-# ./pull-dependencies -l ...
-# - Deploy the dependencies to the NLP machines's public www.
-# ./pull-dependencies -l -r ...
-
-# Specify the version of the dependencies
-# (To developer: Update this before releasing a new version!)
-$version = '2.0'
-
-$isLocal = ARGV.index('-l')
-$isRelease = ARGV.index('-r')
-if $isRelease and not $isLocal
- puts "ERROR: To release, must use both -l and -r"
- exit 1
-end
-ARGV.delete_if { |x| x == '-l' or x == '-r' }
-
-def isZip(name)
- # Directories are zipped
- name.end_with?('.exec') or name !~ /\./
-end
-
-def pull(sourcePath, dir=nil, opts={})
- puts sourcePath
- destDir = 'lib' + (dir ? '/' + dir : '')
- system "mkdir -p #{destDir}"
-
- name = File.basename(sourcePath)
- ext = isZip(name) ? '.zip' : ''
-
- if not $isLocal and not $isRelease
- # Download url => localPath
- if sourcePath.start_with?('http://') || sourcePath.start_with?('https://')
- url = sourcePath
- else
- url = 'http://nlp.stanford.edu/software/sempre/dependencies-' + $version + sourcePath + ext
- end
- localPath = destDir + '/' + name + ext
- system "mkdir -p #{File.dirname(localPath)}" or exit 1
- system "wget -c '#{url}' -O #{localPath}" or exit 1
- # Unzip localPath to destDir if it's a zip file
- if isZip(name)
- system "cd #{File.dirname(localPath)} && unzip #{File.basename(localPath)}" or exit 1
- system "rm #{localPath}" or exit 1
- end
- else
- rsyncOpts = '-rlptDzi' # Preserve everything except groups and permissions
- if $isRelease
- # Copy sourcePath to cluster
- baseDeployPath = '/u/apache/htdocs/static/software/sempre/dependencies-' + $version
- deployPath = baseDeployPath + sourcePath + ext
- system "mkdir -p #{File.dirname(deployPath)}" or exit 1
- if File.exists?(sourcePath)
- if isZip(name)
- system "cd #{File.dirname(sourcePath)} && zip -r #{deployPath} #{File.basename(sourcePath)}" or exit 1
- else
- if opts[:symlink]
- system "ln -sf #{File.expand_path(sourcePath)} #{deployPath}" or exit 1
- else
- system "rsync #{rsyncOpts} #{sourcePath} #{deployPath}" or exit 1
- end
- end
- else
- system "rsync #{rsyncOpts} jamie.stanford.edu:#{sourcePath} #{deployPath}" or exit 1
- end
- system "chmod -R og=u #{baseDeployPath}" #or exit 1
- else
- # Download sourcePath from cluster to destDir
- if File.exists?(sourcePath)
- if opts[:symlink]
- system "ln -sf #{File.expand_path(sourcePath)} #{destDir}" or exit 1
- else
- system "rsync #{rsyncOpts} #{sourcePath} #{destDir}" or exit 1
- end
- else
- system "rsync #{rsyncOpts} jamie.stanford.edu:#{sourcePath} #{destDir}" or exit 1
- end
- end
- end
-end
-
-# source: path to master git repository
-def updateGit(source)
- dir = File.basename(source.sub(/\.git$/, ''))
- if File.exists?(dir)
- system 'cd '+dir+' && git pull' or exit 1
- else
- system 'git clone ' + source or exit 1
- end
-end
-
-def downloadExec(path)
- ['options.map', 'params', 'grammar'].each { |file|
- if File.exists?(path+'/'+file)
- pull(path+'/'+file, 'models/'+File.basename(path))
- end
- }
-end
-
-$modules = []
-def addModule(name, description, func)
- $modules << [name, description, func]
-end
-
-############################################################
-
-addModule('core', 'Core utilities (need to compile)', lambda {
- # fig: options parsing, experiment management, utils
- updateGit('https://github.com/percyliang/fig')
- system 'make -C fig' or exit 1
- system 'mkdir -p lib && cd lib && ln -sf ../fig/fig.jar' or exit 1
-
- # Google libraries
- pull('/u/nlp/data/semparse/resources/guava-14.0.1.jar')
-
- # TestNG -- testing framework
- pull('/u/nlp/data/semparse/resources/testng-6.8.5.jar')
- pull('/u/nlp/data/semparse/resources/jcommander-1.30.jar')
-
- # Checkstyle: make sure code looks fine
- pull('/u/nlp/data/semparse/resources/checkstyle')
-
- # JSON
- pull('/u/nlp/data/semparse/resources/jackson-core-2.2.0.jar')
- pull('/u/nlp/data/semparse/resources/jackson-annotations-2.2.0.jar')
- pull('/u/nlp/data/semparse/resources/jackson-databind-2.2.0.jar')
-
- # jLine from maven central
- pull('https://repo1.maven.org/maven2/jline/jline/2.14.2/jline-2.14.2.jar')
-})
-
-addModule('corenlp', 'Stanford CoreNLP 3.6.0', lambda {
- pull('/u/nlp/data/semparse/resources/stanford-corenlp-full-2015-12-09.zip', '', {:symlink => true})
- if not File.exists?('lib/stanford-corenlp-full-2015-12-09')
- system "cd lib && unzip stanford-corenlp-full-2015-12-09.zip" or exit 1
- end
- pull('/u/nlp/data/semparse/resources/stanford-corenlp-caseless-2015-04-20-models.jar',
- 'stanford-corenlp-full-2015-12-09', {:symlink => true})
- # Remove old file (for backward compatibility)
- if Dir.glob('lib/stanford-corenlp*.jar').any?
- system 'rm -v lib/stanford-corenlp*.jar' or exit 1
- end
- {'stanford-corenlp-3.6.0.jar' => 'stanford-corenlp.jar',
- 'stanford-corenlp-3.6.0-models.jar' => 'stanford-corenlp-models.jar',
- 'stanford-corenlp-caseless-2015-04-20-models.jar' => 'stanford-corenlp-caseless-models.jar',
- 'joda-time.jar' => 'joda-time.jar',
- 'jollyday.jar' => 'jollyday.jar',
- 'ejml-0.23.jar' => 'ejml.jar',
- 'slf4j-api.jar' => 'slf4j-api.jar',
- 'slf4j-simple.jar' => 'slf4j-simple.jar',
- }.each { |key, value|
- system "ln -sfv stanford-corenlp-full-2015-12-09/#{key} lib/#{value}" or exit 1
- }
-})
-
-addModule('corenlp-3.2.0', 'Stanford CoreNLP 3.2.0 (for backward reproducibility)', lambda {
- pull('/u/nlp/data/semparse/resources/stanford-corenlp-full-2013-06-20.zip', '', {:symlink => true})
- if not File.exists?('lib/stanford-corenlp-full-2013-06-20')
- system "cd lib && unzip stanford-corenlp-full-2013-06-20.zip" or exit 1
- end
- pull('/u/nlp/data/semparse/resources/stanford-corenlp-caseless-2013-06-07-models.jar',
- 'stanford-corenlp-full-2013-06-20', {:symlink => true})
- # Remove old file (for backward compatibility)
- if Dir.glob('lib/stanford-corenlp*.jar').any?
- system 'rm -v lib/stanford-corenlp*.jar' or exit 1
- end
- {'stanford-corenlp-3.2.0.jar' => 'stanford-corenlp.jar',
- 'stanford-corenlp-3.2.0-models.jar' => 'stanford-corenlp-models.jar',
- 'stanford-corenlp-caseless-2013-06-07-models.jar' => 'stanford-corenlp-caseless-models.jar',
- 'joda-time.jar' => 'joda-time.jar',
- 'jollyday.jar' => 'jollyday.jar'
- }.each { |key, value|
- system "ln -sfv stanford-corenlp-full-2013-06-20/#{key} lib/#{value}" or exit 1
- }
-})
-
-addModule('freebase', 'Freebase: need to construct Freebase schemas', lambda {
- # Freebase schema
- pull('/u/nlp/data/semparse/scr/freebase/state/execs/93.exec/schema2.ttl', 'fb_data/93.exec')
-
- # Lucene libraries
- pull('/u/nlp/data/semparse/resources/lucene-core-4.4.0.jar')
- pull('/u/nlp/data/semparse/resources/lucene-analyzers-common-4.4.0.jar')
- pull('/u/nlp/data/semparse/resources/lucene-queryparser-4.4.0.jar')
-
- # Freebase data (for lexicon)
- pull('/u/nlp/data/semparse/scr/fb_data/7', 'fb_data')
-
- # WebQuestions dataset
- pull('/u/nlp/data/semparse/webquestions/dataset_11/webquestions.examples.train.json', 'data/webquestions/dataset_11')
- pull('/u/nlp/data/semparse/webquestions/dataset_11/webquestions.examples.test.json', 'data/webquestions/dataset_11')
-})
-
-
-
-addModule('virtuoso', 'Virtuoso: if want to run own SPARQL server locally', lambda {
- updateGit('https://github.com/openlink/virtuoso-opensource')
- # Run this command to compile:
- #system "cd virtuoso-opensource && ./autogen.sh && ./configure --prefix=$PWD/install && make && make install" or exit 1
-})
-
-addModule('fullfreebase-ttl', 'Freebase (ttl file)', lambda {
- # This is just for your reference. It is not directly used by SEMPRE.
- pull('/u/nlp/data/semparse/scr/freebase/state/execs/93.exec/0.ttl.bz2', 'fb_data/93.exec', {:symlink => true})
-})
-
-addModule('fullfreebase-vdb', 'Freebase (Virtuoso database)', lambda {
- # Virtuoso index of 0.ttl above. This is read (and written) by Virtuoso.
- pull('/u/nlp/data/semparse/scr/freebase/state/execs/93.exec/vdb.tar.bz2', 'fb_data/93.exec', {:symlink => true})
- # You need to unzip this yourself and move these files to the right place.
-})
-
-addModule('fullfreebase-types', 'Freebase types', lambda {
- # Map from mid (e.g., fb:m.02mjmr) to id (e.g., fb:en.barack_obama) (used to link external things like Freebase API search with our internal Freebase)
- pull('/u/nlp/data/semparse/scr/freebase/freebase-rdf-2013-06-09-00-00.canonical-id-map.gz', 'fb_data', {:symlink => true})
- # Map from id to types (used to do type inference on internal entities)
- pull('/u/nlp/data/semparse/scr/freebase/freebase-rdf-2013-06-09-00-00.canonicalized.en-types.gz', 'fb_data', {:symlink => true})
- # You need to unzip these yourself and move these files to the right place.
-})
-
-addModule('tables', 'Semantic parsing with execution on tables', lambda {
- # CSV reader
- pull('/u/nlp/data/semparse/resources/opencsv-3.0.jar')
-})
-
-addModule('tables-data', 'WikiTableQuestions dataset v1.0.2', lambda {
- # Compact version of the dataset
- pull('https://github.com/ppasupat/WikiTableQuestions/releases/download/v1.0.2/WikiTableQuestions-1.0.2-compact.zip', 'data')
- # Remove old file (for backward compatibility)
- if File.directory?('lib/data/WikiTableQuestions')
- system 'rm -rv lib/data/WikiTableQuestions' or exit 1
- end
- system "cd lib/data && unzip WikiTableQuestions-1.0.2-compact.zip" or exit 1
-})
-
-addModule('tables-data-0.5', 'WikiTableQuestions dataset v0.5 (for backward reproducibility)', lambda {
- # Compact version of the dataset
- pull('https://github.com/ppasupat/WikiTableQuestions/releases/download/v0.5/WikiTableQuestions-0.5-compact.zip', 'data')
- # Remove old file (for backward compatibility)
- if File.directory?('lib/data/WikiTableQuestions')
- system 'rm -rv lib/data/WikiTableQuestions' or exit 1
- end
- system "cd lib/data && unzip WikiTableQuestions-0.5-compact.zip" or exit 1
-})
-
-addModule('tables-cprune', 'Neighbor information for applying macro grammar on tables', lambda {
- pull('/u/nlp/data/semparse/cprune/nn_0.zip', 'data/nn_0', {:symlink => true})
- system "cd lib/data/nn_0 && unzip nn_0.zip" or exit 1
-})
-
-addModule('overnight', 'Creating a parser for multiple domains', lambda {
- # Geo evaluation
- pull('/u/nlp/data/semparse/overnight/geo880.db', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/geo880/geo880-train.examples', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/geo880/geo880-test.examples', 'data/overnight/', {:symlink => true})
-
-
- # Cache for turking
- pull('/u/nlp/data/semparse/overnight/cache/', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/layouts/', 'data/overnight/', {:symlink => true})
-
- # Pull testing code
- pull('/u/nlp/data/semparse/overnight/test/', 'data/overnight/', {:symlink => true})
-
- # Pull geo880
- pull('/u/nlp/data/semparse/overnight/geo880/geo880.paraphrases.train.superlatives.examples', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/geo880/geo880.paraphrases.train.superlatives2.examples', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/geo880/geo880.lexicon', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/geo880/geo880.predicate.dict', 'data/overnight/', {:symlink => true})
-
- # Pull dependencies for everything else
- domains = ['geo880', 'regex', 'publications', 'socialnetwork', 'restaurants', 'blocks', 'calendar', 'housing', 'basketball', 'recipes', 'calendarplus']
- domains.each do |domain|
- pull('/u/nlp/data/semparse/overnight/' + domain + '/' + domain + '.paraphrases.train.examples', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/' + domain + '/' + domain + '.paraphrases.test.examples', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/' + domain + '/' + domain + '.paraphrases.groups', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/' + domain + '/' + domain + '.word_alignments.berkeley', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/' + domain + '/' + domain + '.phrase_alignments', 'data/overnight/', {:symlink => true})
- pull('/u/nlp/data/semparse/overnight/' + domain + '/' + domain + '-ppdb.txt', 'data/overnight/', {:symlink => true})
- end
-
- # Pull the independent sets for calendar
- pull('/u/nlp/data/semparse/overnight/calendar/eval/calendar.test.turk.examples', 'data/overnight/', {:symlink => true})
-})
-
-addModule('esslli_2016', 'Data for ESSLLI 2016 semantic parsing class', lambda {
- pull('/u/nlp/data/semparse/esslli_2016', 'data/esslli_2016/', {:symlink => true})
-})
-
-addModule('geo880', 'Data, lexicon, grammars and KB for geo880', lambda {
- pull('/u/nlp/data/semparse/geo880/geo880-test.examples', 'data/geo880', {:symlink => true})
- pull('/u/nlp/data/semparse/geo880/geo880-test.preprocessed.examples', 'data/geo880', {:symlink => true})
- pull('/u/nlp/data/semparse/geo880/geo880-train.preprocessed.examples', 'data/geo880', {:symlink => true})
- pull('/u/nlp/data/semparse/geo880/geo880.grammar', 'data/geo880', {:symlink => true})
- pull('/u/nlp/data/semparse/geo880/geo880.lexicon', 'data/geo880', {:symlink => true})
- pull('/u/nlp/data/semparse/geo880/geo880.kg', 'data/geo880', {:symlink => true})
- pull('/u/nlp/data/semparse/geo880/geo880.type_hierarchy', 'data/geo880', {:symlink => true})
-})
-############################################################
-
-if ARGV.size == 0
- puts "#{$0} ... "
- puts
- puts "Modules:"
- $modules.each { |name,description,func|
- puts " #{name}: #{description}"
- }
- puts
- puts "Internal use (Stanford NLP only):"
- puts " #{$0} -l ...: Get the files from the local Stanford NLP server instead"
- puts " #{$0} -l -r ...: Release to the public www directory on the server"
-end
-
-$modules.each { |name,description,func|
- if ARGV.index(name)
- puts "===== Downloading #{name}: #{description}"
- func.call
- end
-}
diff --git a/examples/lassie/sempre/run b/examples/lassie/sempre/run
deleted file mode 100755
index 7f5bc89141..0000000000
--- a/examples/lassie/sempre/run
+++ /dev/null
@@ -1,1115 +0,0 @@
-#!/usr/bin/env ruby
-
-# This is the main entry point for running all SEMPRE programs. See
-# fig/lib/execrunner.rb for more documentation for how commands are generated.
-# There are a bunch of modes that this script can be invoked with, which
-# loosely correspond to the modules.
-
-$: << 'fig/lib'
-require 'execrunner'
-$optPrefix = '-'
-
-$modes = []
-def addMode(name, description, func)
- $modes << [name, description, func]
-end
-
-def codalab(dependencies=nil)
- # Set @cl=1 to run job on CodaLab
- dependencies ||= l(':fig', ':lib', ':module-classes.txt', ':libsempre')
- l(
- letDefault(:cl, 0),
- sel(:cl,
- l(),
- l('cl', 'run', dependencies, '---', 'LC_ALL=C.UTF-8'),
- nil),
- nil)
-end
-
-def header(modules='core', codalabDependencies=nil)
- l(
- codalab(codalabDependencies),
- # Queuing system
- letDefault(:q, 0), sel(:q, l(), l('fig/bin/q', '-shareWorkingPath', o('mem', '5g'), o('memGrace', 10), '-add', '---')),
- # Create execution directory
- letDefault(:pooldir, 1),
- sel(:pooldir, l(), 'fig/bin/qcreate'),
- # Run the Java command...
- 'java',
- '-ea',
- '-Dmodules='+modules,
- # Memory size
- letDefault(:memsize, 'default'),
- sel(:memsize, {
- 'tiny' => l('-Xms2G', '-Xmx4G'),
- 'low' => l('-Xms5G', '-Xmx7G'),
- 'default' => l('-Xms8G', '-Xmx10G'),
- 'medium' => l('-Xms12G', '-Xmx14G'),
- 'high' => l('-Xms20G', '-Xmx24G'),
- 'higher' => l('-Xms40G', '-Xmx50G'),
- 'impressive' => l('-Xms75G', '-Xmx90G'),
- }),
- # Classpath
- '-cp', 'libsempre/*:lib/*',
- # Profiling
- letDefault(:prof, 0), sel(:prof, l(), '-Xrunhprof:cpu=samples,depth=100,file=_OUTPATH_/java.hprof.txt'),
- nil)
-end
-
-def unbalancedTrainDevSplit
- l(o('Dataset.trainFrac', 0.8), o('Dataset.devFrac', 0.2))
-end
-def balancedTrainDevSplit
- l(o('Dataset.trainFrac', 0.5), o('Dataset.devFrac', 0.5))
-end
-
-def figOpts; l(selo(:pooldir, 'execDir', 'exec', '_OUTPATH_'), o('overwriteExecDir'), o('addToView', 0)) end
-
-############################################################
-# Unit tests
-
-addMode('test', 'Run unit tests', lambda { |e|
- l(
- 'java', '-ea', '-Xmx12g', '-cp', 'libsempre/*:lib/*',
- lambda { |e|
- e.key?(:sparqlserver) ? "-Dsparqlserver=http://#{e[:sparqlserver]}/sparql" : l()
- },
- 'org.testng.TestNG',
- lambda { |e|
- if e[:class]
- l('-testclass', 'edu.stanford.nlp.sempre.' + e[:class])
- else
- 'testng.xml'
- end
- },
- lambda { |e|
- if e[:fast]
- o('excludegroups', 'sparql,corenlp')
- else
- nil
- end
- },
- nil)
-})
-
-############################################################
-# Freebase
-
-def freebaseHeader; header('core,freebase') end
-
-def freebaseFeatureDomains
- [
- 'basicStats',
- 'alignmentScores',
- 'entityFeatures',
- 'context',
- 'skipPos',
- 'joinPos',
- 'wordSim',
- 'lexAlign',
- 'tokenMatch',
- 'rule',
- 'opCount',
- 'constant',
- 'denotation',
- 'whType',
- 'span',
- 'derivRank',
- 'lemmaAndBinaries',
- nil].compact
-end
-
-def sparqlOpts
- l(
- required(:sparqlserver, 'host:port of the Sparql server'), # Example: jonsson:3093, etc.
- o('SparqlExecutor.endpointUrl', lambda{|e| 'http://'+e[:sparqlserver]+'/sparql'}),
- nil)
-end
-
-def freebaseOpts
- l(
- figOpts,
- sparqlOpts,
-
- # Features
- o('FeatureExtractor.featureDomains', *freebaseFeatureDomains),
- o('Builder.executor', 'freebase.SparqlExecutor'),
- o('Builder.valueEvaluator', 'freebase.FreebaseValueEvaluator'),
- o('LanguageAnalyzer.languageAnalyzer', 'corenlp.CoreNLPAnalyzer'),
-
- # Lexicon
- o('LexiconFn.lexiconClassName', 'edu.stanford.nlp.sempre.fbalignment.lexicons.Lexicon'),
- l( # binary
- o('BinaryLexicon.binaryLexiconFilesPath', 'lib/fb_data/7/binaryInfoStringAndAlignment.txt'),
- o('BinaryLexicon.keyToSortBy', 'Intersection_size_typed'),
- nil),
- o('UnaryLexicon.unaryLexiconFilePath','lib/fb_data/7/unaryInfoStringAndAlignment.txt'), # unary
- o('EntityLexicon.entityPopularityPath','lib/fb_data/7/entityPopularity.txt'), # entity
- #Jonathan - added this 3/5/2015
- o('TypeInference.typeLookup','freebase.FreebaseTypeLookup'),
- o('FreebaseSearch.cachePath', '/u/nlp/data/semparse/scr/cache/fbsearch/1.cache'),
- nil)
-end
-
-def cachePaths(lexiconFnCachePath, sparqlExecutorCachePath)
- l(
- required(:cacheserver, 'none (don\'t cache to disk), local (write to local file), or : (hit the cacheserver)'),
- lambda { |e|
- cacheserver = e[:cacheserver]
- cacheserver = 'jonsson:4000' if cacheserver == 'remote' # Default
- case cacheserver
- when 'none' then l()
- when 'local' then l( # Use files directly - don't run more than one job that does this!
- o('Lexicon.cachePath', 'LexiconFn.cache'),
- o('SparqlExecutor.cachePath', 'SparqlExecutor.cache'),
- o('FreebaseSearch.cachePath', 'FreebaseSearch.cache'),
- nil)
- else l(
- o('Lexicon.cachePath', cacheserver+':/u/nlp/data/semparse/cache/'+lexiconFnCachePath),
- o('SparqlExecutor.cachePath', cacheserver+':/u/nlp/data/semparse/cache/'+sparqlExecutorCachePath),
- o('FreebaseSearch.cachePath', cacheserver+':/u/nlp/data/semparse/cache/fbsearch/1.cache'),
- # Read-only
- o('EntityLexicon.mid2idPath', cacheserver+':/u/nlp/data/semparse/scr/freebase/freebase-rdf-2013-06-09-00-00.canonical-id-map'),
- o('FreebaseTypeLookup.entityTypesPath', cacheserver+':/u/nlp/data/semparse/scr/freebase/freebase-rdf-2013-06-09-00-00.canonicalized.en-types'),
- nil)
- end
- },
- nil)
-end
-
-# tag is either "free917" or "webquestions"
-def emnlp2013AblationExperiments(tag)
- l(
- letDefault(:ablation, 0),
- # Ablation experiments (EMNLP)
- sel(:ablation,
- l(), # (0) Just run things normally
- selo(nil, 'Parser.beamSize', 200, 50, 10), # (1) Vary beam size
- selo(nil, 'Dataset.trainFrac', 0.1, 0.2, 0.4, 0.6), # (2) Vary training set size
- sel(nil, # (3) Structural: only do join or only do bridge
- o('Grammar.tags', l(tag, 'join')),
- o('Grammar.tags', l(tag, 'bridge')),
- o('Grammar.tags', l(tag, 'inject')),
- nil),
- sel(nil, # (4) Features
- o('FeatureExtractor.featureDomains', *(freebaseFeatureDomains+['lexAlign'])), # +lexAlign
- o('FeatureExtractor.featureDomains', *(freebaseFeatureDomains+['lexAlign']-['alignmentScores'])), # +lexAlign -alignmentScores
- o('FeatureExtractor.featureDomains', *(freebaseFeatureDomains-['denotation'])), # -denotation
- o('FeatureExtractor.featureDomains', *(freebaseFeatureDomains-['skipPos', 'joinPos'])), # -syntax features (skipPos, joinPos)
- nil),
- #o('Builder.executor', 'FormulaMatchExecutor'), # (6) train on logical forms (doesn't really work well)
- nil),
-
- letDefault(:split, 0), selo(:split, 'Dataset.splitRandom', 1, 2, 3),
- nil)
-end
-
-def free917
- l( # Data
- letDefault(:data, 0),
- sel(:data,
- l(o('Dataset.inPaths', 'train,data/free917.train.examples.canonicalized.json'), unbalancedTrainDevSplit), # (0) train 0.8, dev 0.2
- l(o('Dataset.inPaths', 'train,data/free917.train.examples.canonicalized.json', 'test,data/free917.test.examples.canonicalized.json')), # (1) Don't run on test yet!
- nil),
-
- # Grammar
- o('Grammar.inPaths', 'freebase/data/emnlp2013.grammar'),
- o('Parser.beamSize', 500),
-
- emnlp2013AblationExperiments('free917'),
-
- # lexicon index
- letDefault(:lucene, 0),
- sel(:lucene,
- l(
- o('EntityLexicon.exactMatchIndex','lib/lucene/4.4/free917/'),
- cachePaths('10/LexiconFn.cache', '10/SparqlExecutor.cache'),
- o('Grammar.tags', 'free917', 'bridge', 'join', 'inject', 'exact'),
- nil),
- l( # With entity disambiguation - currently too crappy
- o('EntityLexicon.inexactMatchIndex','lib/lucene/4.4/inexact/'),
- cachePaths('4/LexiconFn.cache', '4/SparqlExecutor.cache'),
- o('Grammar.tags', 'free917', 'bridge', 'join', 'inject', 'inexact'),
- nil),
- nil),
- # Use binary predicate features (overfits on free917)
- o('BridgeFn.filterBadDomain',false),
- # Learning
- o('Learner.maxTrainIters', 6),
- nil)
-end
-
-def webquestions
- l(
- # Data
- letDefault(:data, 0),
- sel(:data,
- l( # Webquestions (dev) [EMNLP final JSON]
- o('Dataset.inPaths',
- 'train,lib/data/webquestions/dataset_11/webquestions.examples.train.json'),
- unbalancedTrainDevSplit,
- nil),
- l( # Webquestions (test) [EMNLP final JSON]
- o('Dataset.inPaths',
- 'train,lib/data/webquestions/dataset_11/webquestions.examples.train.json',
- 'test,lib/data/webquestions/dataset_11/webquestions.examples.test.json'),
- nil),
- nil),
-
- # Grammar
- letDefault(:grammar, 1),
- sel(:grammar, l(), l(o('Grammar.inPaths', 'freebase/data/emnlp2013.grammar'))),
-
- o('Parser.beamSize', 200), # {07/03/13}: WebQuestions is too slow to run with default 500, so set to 200 for now...
-
- # Caching
- letDefault(:entitysearch, 0),
- sel(:entitysearch, # Used for EMNLP 2013
- l(
- cachePaths('lucene/0.cache', 'sparql/3.cache'),
- o('EntityLexicon.inexactMatchIndex','lib/lucene/4.4/inexact/'),
- o('LexiconFn.maxEntityEntries',10),
- o('Grammar.tags', 'webquestions', 'bridge', 'join', 'inject','inexact'), # specify also strategy
- nil),
- nil),
-
- # Learning
- o('Learner.maxTrainIters', 3),
-
- # Use binary predicate features (overfits on free917)
- o('BridgeFn.useBinaryPredicateFeatures', true),
- o('BridgeFn.filterBadDomain',true),
- letDefault(:split, 0), selo(:split, 'Dataset.splitRandom', 1,2,3),
- nil)
-end
-
-
-addMode('freebase', 'Freebase (for EMNLP 2013, ACL 2014, TACL 2014)', lambda { |e| l(
- letDefault(:train, 0),
- letDefault(:interact, 0),
-
- # nlpsub: for running commands on PBS
- letDefault(:nlpsub, 0),
- sel(:nlpsub,
- l(),
- l('nlpsub', '-d/scr/yonatan/sandbox/blackhole', '-nyonatan', '-c3'),
- l('nlpsub', '-d/scr/yonatan/sandbox/blackhole', '-nyonatan', '-qjag', '-c3'),
- l('nlpsub', '-d/scr/yonatan/sandbox/blackhole', '-nyonatan', '-qjohn', '-c3'),
- nil),
- sel(:interact, l()),
- freebaseHeader,
- 'edu.stanford.nlp.sempre.Main',
- freebaseOpts,
-
- # Dataset
- sel(:domain, {
- 'webquestions' => webquestions,
- 'free917' => free917,
- }),
-
-
- sel(:interact, l(), l(
- # After training, run interact, which loads up a set of parameters and
- # puts you in a prompt.
- o('Dataset.inPaths'),
- o('Learner.maxTrainIters', 0),
- required(:load, 'none or exec number (e.g., 15) to load'),
- lambda { |e|
- if e[:load] == 'none' then
- l()
- else
- execPath = "lib/models/#{e[:load]}.exec"
- l(
- o('Builder.inParamsPath', execPath+'/params'),
- o('Grammar.inPaths', execPath+'/grammar'),
- o('Master.logPath', lambda{|e| 'state/' + e[:domain] + '.log'}),
- o('Master.newExamplesPath', lambda{|e| 'state/' + e[:domain] + '.examples'}),
- o('Master.onlineLearnExamples', true),
- # Make sure features are set properly!
- nil)
- end
- },
- o('Main.interactive'),
- nil))
-) })
-
-addMode('cacheserver', 'Start the general-purpose cache server that serves files with key-value maps', lambda { |e|
- l(
- 'java', '-Xmx36g', '-ea', '-cp', 'libsempre/*:lib/fig.jar',
- 'edu.stanford.nlp.sempre.cache.StringCacheServer',
- letDefault(:port, 4000),
- lambda { |e| o('port', e[:port]) },
-
- letDefault(:cachetype, 0),
- sel(:cachetype,
- l(
- o('FileStringCache.appendMode'),
- o('FileStringCache.capacity', 35 * 1024),
- o('FileStringCache.flushFrequency', 2147483647),
- nil),
- l(
- o('FileStringCache.appendMode',false),
- o('FileStringCache.capacity', 1 * 1024),
- o('FileStringCache.flushFrequency', 100000),
- nil),
- nil),
- nil)
-})
-
-############################################################
-# Freebase RDF database (for building SPARQL database)
-
-# Scratch directory
-def scrOptions
- letDefault(:scr, '/u/nlp/data/semparse/rdf/scr/' + `hostname | cut -f 1 -d .`.chomp)
-end
-
-addMode('filterfreebase', '(1) Filter RDF Freebase dump (do this once) [takes about 1 hour]', lambda { |e| l(
- scrOptions,
- l(
- 'fig/bin/qcreate', o('statePath', lambda{|e| e[:scr] + '/state'}),
- 'java', '-ea', '-Xmx20g', '-cp', 'libsempre/*:lib/*',
- 'edu.stanford.nlp.sempre.freebase.FilterFreebase',
- o('inPath', '/u/nlp/data/semparse/scr/freebase/freebase-rdf-2013-06-09-00-00.canonicalized'),
- sel(:keep, {
- 'all' => o('keepAllProperties'),
- 'geo' => l(
- o('keepTypesPaths', 'data/geo.types'),
- o('keepPropertiesPath', 'data/geo.properties'),
- o('keepGeneralPropertiesOnlyForSeenEntities', true),
- nil),
- }),
- o('execDir', '_OUTPATH_'), o('overwriteExecDir'),
- nil),
-nil) })
-
-addMode('sparqlserver', '(2) Start the SPARQL server [do this every time]', lambda { |e| l(
- scrOptions,
- required(:exec),
- sel(nil,
- l(
- 'freebase/scripts/virtuoso', 'start',
- lambda{|e| e[:scr]+'/state/execs/'+e[:exec].to_s+'.exec/vdb'}, # DB directory
- lambda{|e| 3000+e[:exec]}, # port
- nil),
- # Give everyone permissions so that anyone can kill the server if needed.
- l(
- 'chmod', '-R', 'og=u',
- lambda{|e| e[:scr]+'/state/execs/'+e[:exec].to_s+'.exec/vdb'}, # DB directory
- nil),
- # To stop the server: freebase/scripts/virtuoso stop 3093
- nil),
-nil) })
-
-# (3) Index the filtered RDF dump [takes 48 hours]
-addMode('indexfreebase', '(3) Index the filtered RDF dump [takes 48 hours for Freebase]', lambda { |e| l(
- letDefault(:stage, nil),
- scrOptions,
- required(:exec),
- sel(:stage,
- l(
- 'scripts/virtuoso', 'add',
- lambda{|e| e[:scr]+'/state/execs/'+e[:exec].to_s+'.exec/0.ttl'}, # ttl file
- lambda{|e| 3000+e[:exec]}, # port
- lambda{|e| e[:offset] || 0}, # offset
- nil),
- l(
- 'scripts/extract-freebase-schema.rb',
- lambda{|e| 'http://localhost:'+(3000+e[:exec]).to_s+'/sparql'}, # port
- lambda{|e| e[:scr]+'/state/execs/'+e[:exec].to_s+'.exec/schema.ttl'},
- nil),
- nil),
-nil) })
-
-addMode('convertfree917', 'Convert the Free917 dataset', lambda { |e| l(
- 'java', '-ea', '-Xmx15g',
- '-cp', 'libsempre/*:lib/*',
- 'edu.stanford.nlp.sempre.freebase.Free917Converter',
- o('inDir','/u/nlp/data/semparse/yates/final-dataset-acl-2013-all/'),
- o('outDir','data/free917_convert/'),
- o('entityInfoFile','/user/joberant/scr/fb_data/3/entityInfo.txt'),
- o('cvtFile','lib/fb_data/2/Cvts.txt'),
- o('midToIdFile','/u/nlp/data/semparse/scr/freebase/freebase-rdf-2013-06-09-00-00.canonical-id-map'),
-nil) })
-
-addMode('query', 'Query a single logical form or SPARQL', lambda { |e| l(
- codalab,
- 'java', '-ea',
- '-cp', 'libsempre/*:lib/*',
- 'edu.stanford.nlp.sempre.freebase.SparqlExecutor',
- sparqlOpts,
-nil) })
-
-############################################################
-
-
-# Just start a simple interactive shell to try out SEMPRE commands
-addMode('simple', 'Simple shell', lambda { |e| l(
- codalab, 'java', '-cp', 'libsempre/*:lib/*', '-ea', 'edu.stanford.nlp.sempre.Main',
- o('Main.interactive'),
-nil) })
-
-addMode('simple-sparql', 'Simple shell for querying SPARQL', lambda { |e| l(
- codalab, 'java', '-Dmodules=core,freebase', '-cp', 'libsempre/*:lib/*', '-ea', 'edu.stanford.nlp.sempre.Main',
- o('executor', 'freebase.SparqlExecutor'),
- sparqlOpts,
- o('Main.interactive'),
-nil) })
-
-addMode('simple-lambdadcs', 'Simple shell for querying with the LambdaDCSExecutor', lambda { |e| l(
- codalab, 'java', '-Dmodules=core,tables,corenlp', '-cp', 'libsempre/*:lib/*', '-ea', 'edu.stanford.nlp.sempre.Main',
- o('executor', 'tables.lambdadcs.LambdaDCSExecutor'),
- o('FeatureExtractor.featureDomains', 'denotation lexAlign joinPos skipPos'.split),
- o('LanguageAnalyzer.languageAnalyzer', 'corenlp.CoreNLPAnalyzer'),
- o('Main.interactive'),
-nil) })
-
-addMode('simple-freebase', 'Simple shell for using Freebase', lambda { |e| l(
- 'java', '-Dmodules=core,freebase', '-cp', 'libsempre/*:lib/*', '-ea', 'edu.stanford.nlp.sempre.Main',
- o('executor', 'freebase.SparqlExecutor'),
- letDefault(:sparqlserver, 'freebase.cloudapp.net:3093'),
- letDefault(:cacheserver, 'freebase.cloudapp.net:4000'),
- sparqlOpts,
- # Set up Freebase search for entities
- # Assume run following on the server (read-only and capacity are important!)
- # ./run @mode=cacheserver -readOnly -capacity MAX -basePath lib/fb_data
- o('FreebaseSearch.cachePath', 'FreebaseSearch.cache'),
- o('EntityLexicon.mid2idPath', lambda { |e| e[:cacheserver] + ':freebase-rdf-2013-06-09-00-00.canonical-id-map.gz' }),
- o('TypeInference.typeLookup', 'freebase.FreebaseTypeLookup'),
- o('FreebaseTypeLookup.entityTypesPath', lambda { |e| e[:cacheserver] + ':freebase-rdf-2013-06-09-00-00.canonicalized.en-types.gz' }),
- o('EntityLexicon.maxEntries', 2),
- o('FeatureExtractor.featureDomains', 'rule'),
- o('Parser.coarsePrune'),
- o('JoinFn.typeInference'),
- o('UnaryLexicon.unaryLexiconFilePath', '/dev/null'),
- o('BinaryLexicon.binaryLexiconFilesPath', '/dev/null'),
- #o('JoinFn.showTypeCheckFailures'), # Use this to debug
- o('Grammar.inPaths', 'freebase/data/demo1.grammar'), # Override with your own custom grammar
- o('SparqlExecutor.returnTable'),
- #o('SparqlExecutor.includeSupportingInfo'), # Show full information
- o('Main.interactive'),
-nil) })
-
-addMode('simple-freebase-nocache', 'Simple shell for using Freebase (without a cache server)', lambda { |e| l(
- 'java', '-Dmodules=core,freebase', '-cp', 'libsempre/*:lib/*', '-ea', 'edu.stanford.nlp.sempre.Main',
- o('executor', 'freebase.SparqlExecutor'),
- letDefault(:sparqlserver, 'freebase.cloudapp.net:3093'),
- sparqlOpts,
- o('FeatureExtractor.featureDomains', 'rule'),
- o('Parser.coarsePrune'),
- o('JoinFn.typeInference'),
- o('UnaryLexicon.unaryLexiconFilePath', '/dev/null'),
- o('BinaryLexicon.binaryLexiconFilesPath', '/dev/null'),
- #o('JoinFn.showTypeCheckFailures'), # Use this to debug
- o('Grammar.inPaths', 'freebase/data/demo1.grammar'), # Override with your own custom grammar
- #o('SparqlExecutor.includeSupportingInfo'), # Show full information
- o('Main.interactive'),
-nil) })
-
-
-############################################################
-# {2014-12-27} [Percy]: Overnight semantic parsing
-def overnightFeatureDomains
- [
- 'match',
- 'ppdb',
- 'skip-bigram',
- 'root',
- 'alignment',
- 'lexical',
- 'root_lexical',
- 'lf',
- 'simpleworld',
- nil].compact
-end
-
-addMode('overnight', 'Overnight semantic parsing', l(
- header('core,freebase,overnight'),
- 'edu.stanford.nlp.sempre.Main',
- figOpts,
- o('JavaExecutor.convertNumberValues', false),
- o('useAnchorsOnce', true),
- o('trackLocalChoices'),
- o('JoinFn.typeInference', true),
- o('Builder.parser', 'FloatingParser'),
- o('FloatingParser.executeAllDerivations', 'true'),
- o('LanguageAnalyzer', 'corenlp.CoreNLPAnalyzer'),
- o('Learner.maxTrainIters', 1),
- #o('printAllPredictions'),
- o('Derivation.showUtterance'),
- letDefault(:debug, 0),
-
- selo(1, 'maxExamples', 'train:10', 'train:MAX'),
-
- # Exact matching is needed on most simple domains
- # o('executor', 'FormulaMatchExecutor'),
- # o('Builder.valueEvaluator', 'ExactValueEvaluator'),
-
- # Features
- o('FeatureExtractor.featureDomains', 'denotation'), # denotation features from general feature extractor
- o('FeatureExtractor.featureComputers', 'overnight.OvernightFeatureComputer'), #
- o('OvernightFeatureComputer.featureDomains', *overnightFeatureDomains),
- #o('initialization', 'paraphrase :: match,1', 'paraphrase :: size,-0.1', 'paraphrase :: ppdb,0.3',
- # 'paraphrase :: skip-bigram,0.8', 'paraphrase :: skip-ppdb,0.2','denotation :: error,-1000'),
- o('coarsePrune'),
- sel(2,
- l(), # no reg
- l(o('Params.l1Reg','lazy'),o('Params.l1RegCoeff',0)),
- l(o('Params.l1Reg','lazy'),o('Params.l1RegCoeff',0.001)),
- nil),
- # Set up the domain
- required(:domain),
- o('Grammar.inPaths', lambda { |e| 'overnight/' + e[:domain] + '.grammar' }),
- o('SimpleWorld.domain', lambda { |e| e[:domain] }),
- o('PPDBModel.ppdbModelPath', lambda { |e| 'lib/data/overnight/' + e[:domain] + '-ppdb.txt' }),
- o('Dataset.trainFrac', 0.8), o('Dataset.devFrac', 0.2),
- o('FloatingParser.maxDepth', 11),
- o('Parser.beamSize', 20),
- letDefault(:alignment, 1),
- sel(:alignment,
- o('wordAlignmentPath', lambda { |e| 'lib/data/overnight/' + e[:domain] + '.word_alignments.heuristic' }),
- o('wordAlignmentPath', lambda { |e| 'lib/data/overnight/' + e[:domain] + '.word_alignments.berkeley' }),
- nil),
- o('phraseAlignmentPath', lambda { |e| 'lib/data/overnight/' + e[:domain] + '.phrase_alignments' }),
- o('PPDBModel.ppdbModelPath', lambda { |e| 'lib/data/overnight/' + e[:domain] + '-ppdb.txt' }),
- o('DerivationPruner.pruningComputers', ['overnight.OvernightDerivationPruningComputer']),
- o('DerivationPruner.pruningStrategies', ['violateHardConstraints']),
- o('Dataset.inPaths',
- lambda { |e| 'train:lib/data/overnight/' + e[:domain] + '.paraphrases.train.examples' },
- lambda { |e| 'test:lib/data/overnight/' + e[:domain] + '.paraphrases.test.examples' }),
- sel(:domain, {
- 'geo880' => l(
- letDefault(:data,0),
- sel(:data,
- l(o('Dataset.inPaths', 'train:lib/data/overnight/geo880.paraphrases.train.superlatives.examples')),
- l(o('Dataset.inPaths', 'train:lib/data/overnight/geo880.paraphrases.train.superlatives.examples', 'test:lib/data/overnight/geo880-train.examples')),
- l(o('Dataset.inPaths', 'train:lib/data/overnight/geo880.paraphrases.train.superlatives2.examples', 'test:lib/data/overnight/geo880-train.examples')),
- l(o('Dataset.inPaths', 'train:lib/data/overnight/geo880.paraphrases.train.superlatives.examples', 'test:lib/data/overnight/geo880-test.examples')),
- l(o('Dataset.inPaths', 'train:lib/data/overnight/geo880.paraphrases.train.superlatives2.examples', 'test:lib/data/overnight/geo880-test.examples')),
- nil),
- o('Parser.beamSize', 20),
- o('initialization', 'paraphrase :: match,1', 'paraphrase :: size,-0.1', 'paraphrase :: ppdb,0.3',
- 'lf :: edu.stanford.nlp.sempre.SimpleWorld.superlative& superlative,10',
- 'root :: pos0=WRB&returnType=class edu.stanford.nlp.sempre.NumberValue,10'),
- o('FloatingParser.maxDepth', 11),
- o('Grammar.tags','generate','general', 'geo880'),
- o('SimpleLexicon.inPaths', 'lib/data/overnight/geo880.lexicon'),
- nil),
- 'calendar' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'calendarplus' => l(
- o('Grammar.tags','generate','general','geo440'),
- o('Grammar.inPaths','overnight/calendar.grammar'),
- o('SimpleWorld.domain', 'calendar'),
- nil),
- 'blocks' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'restaurants' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'housing' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'socialnetwork' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'publications' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'basketball' => l(
- o('Grammar.tags','generate','general'),
- nil),
- 'recipes' => l(
- o('Grammar.tags','generate','general'),
- nil),
- }),
-nil))
-
-############################################################
-# {5/27/15} [Ice]
-addMode('tables', 'QA on HTML tables', lambda { |e| l(
- # Add @cldir=1 to use CodaLab's directory paths
- letDefault(:cldir, 0),
- # Usual header
- header('core,tables,corenlp,cprune'),
- # Select class
- letDefault(:class, 'main'),
- sel(:class, {
- 'main' => 'edu.stanford.nlp.sempre.Main',
- 'check' => 'edu.stanford.nlp.sempre.tables.test.DPDParserChecker',
- 'dump' => 'edu.stanford.nlp.sempre.tables.serialize.SerializedDumper',
- 'load' => l('edu.stanford.nlp.sempre.tables.serialize.SerializedLoader', let(:parser, 'serialized')),
- 'stats' => 'edu.stanford.nlp.sempre.tables.test.TableStatsComputer',
- 'tag-data' => 'edu.stanford.nlp.sempre.tables.serialize.TaggedDatasetGenerator',
- 'tag-table' => 'edu.stanford.nlp.sempre.tables.serialize.TaggedTableGenerator',
- 'tag-fuzzy' => 'edu.stanford.nlp.sempre.tables.serialize.TaggedFuzzyGenerator',
- 'alter' => l('edu.stanford.nlp.sempre.tables.alter.BatchTableAlterer', let(:parser, 'serialized')),
- 'alter-ex' => l('edu.stanford.nlp.sempre.tables.alter.AlteredTablesExecutor', let(:parser, 'serialized')),
- 'filter' => 'edu.stanford.nlp.sempre.tables.serialize.DumpFilterer',
- 'column' => 'edu.stanford.nlp.sempre.tables.test.TableColumnAnalyzer',
- 'execute' => 'edu.stanford.nlp.sempre.tables.test.BatchTableExecutor',
- }),
- # Fig parameters
- selo(:cldir, 'execDir', '_OUTPATH_', '.'),
- o('overwriteExecDir'), o('addToView', 15), o('jarFiles', 'libsempre/*'),
- sel(:cldir, l(), '>/dev/null'),
- # Set environment for table execution
- o('executor', 'tables.lambdadcs.LambdaDCSExecutor'),
- o('targetValuePreprocessor', 'tables.TableValuePreprocessor'),
- o('NumberFn.unitless'), o('NumberFn.alsoTestByConversion'),
- o('TypeInference.typeLookup', 'tables.TableTypeLookup'),
- o('JoinFn.specializedTypeCheck', false), o('JoinFn.typeInference', true),
- o('Learner.outputPredValues'),
- # Value Evaluator
- letDefault(:eval, 'value'),
- sel(:eval, {
- 'value' => o('Builder.valueEvaluator', 'tables.TableValueEvaluator'),
- 'denotation' => o('Builder.valueEvaluator', 'tables.TableValueEvaluator'), # alias of 'value'
- 'formula' => l(
- o('Builder.valueEvaluator', 'tables.TableFormulaEvaluator'),
- o('fallBackToValueEvaluator', false),
- nil),
- }),
- # Parser
- letDefault(:parser, 'floatsize'),
- o('beamSize', 50),
- o('useSizeInsteadOfDepth'),
- sel(:parser, {
- 'floatsize' => l(
- o('Builder.parser', 'FloatingParser'),
- o('FloatingParser.maxDepth', 15),
- nil),
- 'baseline' => o('Builder.parser', 'tables.baseline.TableBaselineParser'),
- 'serialized' => o('Builder.parser', 'tables.serialize.SerializedParser'),
- # ACL 2016
- 'grow-dpd' => l(
- o('Builder.parser', 'tables.dpd.DPDParser'),
- o('FloatingParser.maxDepth', 8),
- nil),
- 'grow-float' => l(
- o('Builder.parser', 'FloatingParser'),
- o('FloatingParser.maxDepth', 8),
- o('FloatingParser.betaReduce'), o('initialFloatingHasZeroDepth'),
- nil),
- 'grow-mix' => l(
- o('Builder.parser', 'MixParser'),
- o('MixParser.parsers', 'FloatingParser', 'tables.serialize.SerializedParser:train-0xc'),
- o('FloatingParser.maxDepth', 8),
- o('FloatingParser.betaReduce'), o('initialFloatingHasZeroDepth'),
- nil),
- # EMNLP 2017
- 'cprune' => l(
- o('Builder.parser', 'cprune.CPruneFloatingParser'),
- o('FloatingParser.maxDepth', 15),
- o('maxNumNeighbors', 40),
- o('maxPredictedPatterns', 1000),
- nil),
- }),
- o('Parser.verbose', 0),
- letDefault(:pruning, 1),
- sel(:pruning,
- l(),
- l(
- o('DerivationPruner.pruningStrategies', *tablesPruningStrategies),
- o('DerivationPruner.pruningComputers', 'tables.TableDerivationPruningComputer'),
- nil),
- nil),
- # Grammar
- tablesGrammarPaths,
- letDefault(:fuzzy, 'original'),
- sel(:fuzzy, {
- 'original' => o('FuzzyMatcher.fuzzyMatcher', 'tables.match.OriginalMatcher'),
- 'editdist-exact' => l(
- o('FuzzyMatcher.fuzzyMatcher', 'tables.match.EditDistanceFuzzyMatcher'),
- o('fuzzyMatchMaxEditDistanceRatio', 0.0),
- nil),
- 'editdist-fuzzy' => l(
- o('FuzzyMatcher.fuzzyMatcher', 'tables.match.EditDistanceFuzzyMatcher'),
- o('fuzzyMatchSubstring'), o('fuzzyMatchMaxEditDistanceRatio', 0.15),
- o('alsoMatchPart'),
- nil),
- }),
- letDefault(:normalize, 1),
- sel(:normalize,
- l(),
- l(o('genericDateValue'), o('numberCanStartAnywhere'), o('num2CanStartAnywhere')),
- nil),
- letDefault(:anchor, 1),
- sel(:anchor, {
- 1 => o('FloatingParser.useAnchorsOnce', true),
- 2 => l(o('FloatingParser.useAnchorsOnce', false), o('FloatingParser.useMaxAnchors', 2)),
- }),
- # Dataset
- letDefault(:data, 'none'),
- tablesDataPaths,
- # Verbosity
- o('FeatureVector.ignoreZeroWeight'),
- o('logFeaturesLimit', 10),
- o('LambdaDCSException.noErrorMessage'),
- letDefault(:verbose, 0),
- sel(:verbose,
- l(
- o('maxPrintedPredictions', 1), o('maxPrintedTrue', 1),
- nil),
- l(
- o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10),
- o('putCellNameInCanonicalUtterance'), o('showUtterance'),
- nil),
- l(
- o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10),
- o('putCellNameInCanonicalUtterance'), o('showUtterance'),
- o('summarizeRuleTime'), o('summarizeDenotations'),
- nil),
- l(
- o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10),
- o('putCellNameInCanonicalUtterance'), o('showUtterance'),
- o('summarizeRuleTime'), o('summarizeDenotations'),
- o('showRules'),
- o('Parser.verbose', 2),
- o('JoinFn.verbose', 3),
- o('JoinFn.showTypeCheckFailures'),
- nil),
- nil),
- # Language Analyzer
- letDefault(:lang, 'corenlp'),
- sel(:lang, {
- 'simple' => o('LanguageAnalyzer', 'SimpleAnalyzer'),
- 'corenlp' => l(o('LanguageAnalyzer', 'corenlp.CoreNLPAnalyzer'), o('annotators', *'tokenize ssplit pos lemma ner'.split)),
- 'fullcorenlp' => l(o('LanguageAnalyzer', 'corenlp.CoreNLPAnalyzer'), o('annotators', *'tokenize ssplit pos lemma ner parse'.split)),
- }),
- # Training
- letDefault(:train, 0),
- sel(:train,
- l(
- let(:l1, 0),
- nil),
- l(
- o('combineFromFloatingParser'),
- o('maxTrainIters', 3),
- o('showValues', false), o('showFirstValue'),
- o('customExpectedCounts', 'TOP'),
- nil),
- l(
- # for dumping derivations (@class=dump)
- # force unbalancedTrainDevSplit + combine from floating parser
- o('combineFromFloatingParser'), o('DPDParser.cheat'),
- nil),
- nil),
- # Regularization
- letDefault(:l1, 1),
- sel(:l1,
- l(),
- l(o('Params.l1Reg','lazy'), o('Params.l1RegCoeff', '3e-5')), # Default
- l(o('Params.l1Reg','lazy'), selo(nil, 'Params.l1RegCoeff', 0, 0.00001, 0.0001, 0.001, 0.01)),
- l(o('Params.l1Reg','lazy'), selo(nil, 'Params.l1RegCoeff', 0.00001, 0.00003, 0.0001, 0.0003)),
- l(o('Params.l1Reg','lazy'), selo(nil, 'Params.l1RegCoeff', 0.00001, 0.00003, 0.0005)),
- nil),
- # Features
- letDefault(:feat, 'none'),
- sel(:feat, {
- 'none' => l(), # No features (random)
- 'some' => l( # Add your own features! (only set up the feature computers)
- o('FeatureExtractor.featureComputers', 'tables.features.PhrasePredicateFeatureComputer tables.features.PhraseDenotationFeatureComputer'.split),
- nil),
- 'all' => l( # All ACL 2015 features
- o('FeatureExtractor.featureDomains', 'custom-denotation phrase-predicate phrase-denotation headword-denotation missing-predicate'.split),
- o('FeatureExtractor.featureComputers', 'tables.features.PhrasePredicateFeatureComputer tables.features.PhraseDenotationFeatureComputer'.split),
- nil),
- 'more' => l( # All ACL 2015 features + more experimental features
- o('FeatureExtractor.featureDomains', 'custom-denotation phrase-predicate phrase-denotation headword-denotation missing-predicate anchored-entity'.split),
- o('FeatureExtractor.featureComputers', 'tables.features.PhrasePredicateFeatureComputer tables.features.PhraseDenotationFeatureComputer tables.features.AnchorFeatureComputer'.split),
- nil),
- 'baseline' => l( # For the baseline classifier
- o('FeatureExtractor.featureDomains', 'custom-denotation phrase-denotation headword-denotation table-baseline'.split),
- o('FeatureExtractor.featureComputers', 'tables.baseline.TableBaselineFeatureComputer tables.features.PhraseDenotationFeatureComputer'.split),
- nil),
- 'ablate' => l(
- o('FeatureExtractor.featureComputers', 'tables.features.PhrasePredicateFeatureComputer tables.features.PhraseDenotationFeatureComputer'.split),
- selo(nil,
- 'FeatureExtractor.featureDomains',
- 'phrase-predicate phrase-denotation headword-denotation missing-predicate'.split,
- 'custom-denotation phrase-denotation headword-denotation missing-predicate'.split,
- 'custom-denotation phrase-predicate headword-denotation missing-predicate'.split,
- 'custom-denotation phrase-predicate phrase-denotation missing-predicate'.split,
- 'custom-denotation phrase-predicate phrase-denotation headword-denotation'.split,
- nil),
- nil),
- }),
- letDefault(:featOp, 'careful'),
- sel(:featOp, {
- 'none' => l(),
- 'careful' => l(
- o('maxNforLexicalizeAllPairs', 2),
- o('computeFuzzyMatchPredicates'),
- nil),
- }),
-nil) })
-
-def tablesGrammarPaths
- lambda { |e|
- baseDir = ['tables/grammars/', 'grammars/'][e[:cldir]]
- l(
- letDefault(:grammar, 'combined-all'),
- sel(:grammar, {
- 'custom' => l(),
- 'restrict' => o('Grammar.inPaths', "#{baseDir}restrict.grammar"),
- 'simple' => o('Grammar.inPaths', "#{baseDir}simple.grammar"),
- 'combined' => o('Grammar.inPaths', "#{baseDir}combined.grammar"),
- 'combined-jnc' => l( # WQ baseline
- o('Grammar.inPaths', "#{baseDir}combined.grammar"),
- o('Grammar.tags', *'movement count'.split),
- nil),
- 'combined-cut' => l( # No intersection / union
- o('Grammar.inPaths', "#{baseDir}combined.grammar"),
- o('Grammar.tags', *'movement comparison count aggregate superlative arithmetic'.split),
- nil),
- 'combined-all' => l( # Default
- o('Grammar.inPaths', "#{baseDir}combined.grammar"),
- o('Grammar.tags', *'alternative movement comparison count aggregate superlative arithmetic merge'.split),
- nil),
- 'combined-more' => l(
- o('Grammar.inPaths', "#{baseDir}combined.grammar"),
- o('Grammar.tags', *'alternative movement comparison count aggregate superlative arithmetic merge v-superlative'.split),
- nil),
- 'combined-trigger' => l( # Use trigger words for operations
- o('Grammar.inPaths', "#{baseDir}combined.grammar"),
- o('Grammar.tags', *'t-alternative t-movement t-comparison t-count t-aggregate t-superlative t-arithmetic merge'.split),
- nil),
- # ACL 2016
- 'grow-custom' => l(
- o('Grammar.inPaths', "#{baseDir}grow.grammar"),
- o('Grammar.binarizeRules', false),
- nil),
- 'grow-default' => l(
- o('Grammar.inPaths', "#{baseDir}grow.grammar"),
- o('Grammar.binarizeRules', false),
- o('Grammar.tags', *'scoped merge-and arithmetic comparison alternative neq yearrange part closedclass scoped-2args-merge-and'.split),
- let(:anchor, 2),
- nil),
- 'grow-strict' => l(
- o('Grammar.inPaths', "#{baseDir}grow.grammar"),
- o('Grammar.binarizeRules', false),
- o('Grammar.tags', *'scoped merge-and arithmetic comparison alternative neq yearrange part closedclass-generic scoped-2args-merge-and'.split),
- let(:anchor, 2),
- nil),
- # EMNLP 2017
- 'extended' => l(
- o('Grammar.inPaths', "#{baseDir}extended.grammar"),
- o('Grammar.tags', *'alternative movement comparison count aggregate superlative arithmetic merge v-superlative'.split),
- nil),
- }),
- nil)
- }
-end
-
-def tablesDataPaths
- lambda { |e|
- baseDir = ['lib/data/WikiTableQuestions/data/', 'WikiTableQuestions/data/'][e[:cldir]]
- csvDir = ['lib/data/WikiTableQuestions/', 'WikiTableQuestions/'][e[:cldir]]
- nnDir = ['lib/data/nn_0/', 'nn_0/'][e[:cldir]]
- datasets = {
- 'none' => l(),
- 'train' => o('Dataset.inPaths', "train,#{baseDir}training.examples"),
- # Pristine test test
- 'test' => l(
- o('Dataset.inPaths',
- "train,#{baseDir}training.examples",
- "test,#{baseDir}pristine-unseen-tables.examples"),
- o('neighborFilePath', "#{nnDir}/exact_nearest_neighbors.all"),
- nil),
- # @data=annotated can be used with @class=check only
- 'annotated' => o('Dataset.inPaths', "train,#{baseDir}annotated-all.examples"),
- 'before300' => o('Dataset.inPaths', "train,#{baseDir}training-before300.examples"),
- }
- # Development sets: 80:20 random split of training data
- ['1', '2', '3', '4', '5'].each do |x|
- datasets['u-' + x] = l(
- o('Dataset.inPaths',
- "train,#{baseDir}random-split-#{x}-train.examples",
- "dev,#{baseDir}random-split-#{x}-dev.examples",
- nil),
- o('neighborFilePath', "#{nnDir}/exact_nearest_neighbors.seed-#{x}.train"),
- nil)
- end
- # That's it!
- l(
- o('TableKnowledgeGraph.baseCSVDir', csvDir),
- # To use the normalized values from the tagged file, which were checked by hand,
- # add @useTaggedFile=1
- letDefault(:useTaggedFile, 0),
- selo(:useTaggedFile, 'TableValuePreprocessor.taggedFiles', '', "#{csvDir}/tagged/data/"),
- sel(:data, datasets),
- nil)
- }
-end
-
-def tablesPruningStrategies
- [
- ### Critical strategies
- "emptyDenotation",
- "nonLambdaError",
- ### Strategies that do not depend on the children's actual formulas
- "atomic",
- "tooManyValues",
- "badSummarizerHead",
- "mistypedMerge",
- ### Strategies that depend on the children's formulas
- "doubleNext",
- "multipleSuperlatives",
- "sameMerge",
- "forwardBackward",
- "unsortedMerge",
- "typeRowMerge",
- nil].compact
-end
-
-
-############################################################
-# {2015-01-18} Generate utterances [Percy]
-addMode('genovernight', 'Generate utterances for overnight semantic parsing', lambda { |e| l(
- header('core,overnight'),
- 'edu.stanford.nlp.sempre.overnight.GenerationMain',
- figOpts,
- o('JoinFn.typeInference', true),
- o('JoinFn.specializedTypeCheck', false),
-
- o('JavaExecutor.convertNumberValues', false),
- o('JavaExecutor.printStackTrace', false),
-
- # These domains are all based on SimpleWorld
- required(:domain),
- o('Grammar.inPaths', lambda { |e| 'overnight/' + e[:domain] + '.grammar' }),
- o('SimpleWorld.domain', lambda { |e| e[:domain] }),
- o('initialization', 'denotation :: error,-1000', 'denotation :: empty,-100', 'paraphrase :: size,+0.01', 'denotation :: value_in_formula,-100'),
- o('FeatureExtractor.featureComputers','overnight.OvernightFeatureComputer'),
- o('OvernightFeatureComputer.featureDomains', ''),
- o('OvernightFeatureComputer.itemAnalysis',false),
- letDefault(:gen, 1),
- sel(:gen,
- l( # For debugging the grammar
- o('FeatureExtractor.featureDomains', 'denotation'),
- o('Dataset.inPaths', lambda { |e| 'train:overnight/' + e[:domain] + '-unittest.examples'}),
- selo(:parse, 'Grammar.tags', 'generate', 'parse'),
- o('interactive'),
- nil),
- l( # For generating utterances
- o('parser', 'FloatingParser'),
- o('maxDepth', 30), o('beamSize', 10000),
- o('derivationScoreNoise', 1),
- o('Dataset.inPaths', 'train:overnight/null.examples'),
- o('Derivation.showUtterance'),
- o('FeatureExtractor.featureDomains', 'denotation'),
- o('printAllPredictions'),
- o('printPredictedUtterances'),
- o('executeAllDerivations'),
- o('Parser.pruneErrorValues', true),
- o('Grammar.tags', 'generate'),
- nil),
- nil),
- a('Grammar.tags', 'general'),
-nil) })
-
-# Generate for all the domains
-addMode('genovernight-wrapper', 'Generate utterances for overnight semantic parsing', lambda { |e| l(
- './run', '@mode=genovernight', '@gen=1',
- sel(nil, {
- 'calendar' => let(:domain, 'calendar'),
- 'blocks' => let(:domain, 'blocks'),
- 'housing' => let(:domain, 'housing'),
- 'restaurants' => let(:domain, 'restaurants'),
- 'publications' => let(:domain, 'publications'),
- 'socialnetwork' => let(:domain, 'socialnetwork'),
- 'basketball' => let(:domain, 'basketball'),
- 'geo880' => let(:domain, 'geo880'),
- 'recipes' => let(:domain, 'recipes'),
- }),
- lambda { |e| '@domain=' + e[:domain] },
- lambda { |e| system 'mkdir -p genovernight.out'; o('execDir', 'genovernight.out/' + e[:domain]) },
-nil) })
-
-addMode('geo880', 'Semantic parsing on the geo880 dataset', lambda { |e| l(
- # Usual header
- header('core,tables,corenlp,geo880'),
- 'edu.stanford.nlp.sempre.Main',
- # Fig parameters
- figOpts,
- o('executor', 'tables.lambdadcs.LambdaDCSExecutor'),
- o('JoinFn.specializedTypeCheck', false), o('JoinFn.typeInference', false),
- # Parser
- o('Builder.parser', 'BeamParser'),
- o('Parser.coarsePrune'),
-
- # Evaluation
- o('Builder.valueEvaluator', 'geo880.Geo880ValueEvaluator'),
-
- # Grammar
- o('Grammar.inPaths','lib/data/geo880/geo880.grammar'),
-
- # Type hierarchy
- o('Geo880TypeLookup.typeHierarchyPath', 'lib/data/geo880/geo880.type_hierarchy'),
- o('TypeInference.typeLookup','geo880.Geo880TypeLookup'),
-
- # Yrkvpba
- o('SimpleLexicon.inPaths', 'lib/data/geo880/geo880.lexicon'),
-
- # Learner
- o('Learner.maxTrainIters', 3),
-
- # Dataset
- letDefault(:data, 0),
- sel(:data,
- l(o('Dataset.inPaths', 'train,lib/data/geo880/geo880-train.preprocessed.examples'), unbalancedTrainDevSplit), # (0) train 0.8, dev 0.2
- l(o('Dataset.inPaths', 'train,lib/data/geo880/geo880-train.examples', 'test,lib/data/geo880/geo880-test.preprocessed/examples')), # (1) Don't run on test yet!
- nil),
- # Load the graph
- o('Dataset.globalGraphPath', 'lib/data/geo880/geo880.kg'),
- # Verbosity
- letDefault(:verbose, 0),
- sel(:verbose,
- l(),
- l(
- o('showRules'),
- o('Parser.verbose', 2),
- o('JoinFn.verbose', 3),
- o('JoinFn.showTypeCheckFailures'),
- nil),
- nil),
- # Language Analyzer
- l(o('LanguageAnalyzer', 'corenlp.CoreNLPAnalyzer'), o('annotators', *'tokenize ssplit pos lemma ner'.split)),
- # Regularization
- letDefault(:l1, 0),
- sel(:l1,
- l(),
- l(o('Params.l1Reg','lazy'), o('Params.l1RegCoeff', '3e-5')),
- l(o('Params.l1Reg','lazy'), selo(nil, 'Params.l1RegCoeff', 0, 0.00001, 0.0001, 0.001, 0.01)),
- nil),
- # Features
- letDefault(:feat, 'freebase'),
- sel(:feat, {
- 'none' => l(), # No features (random)
- 'freebase' => l(
- o('FeatureExtractor.featureDomains', 'rule opCount constant whType span lemmaAndBinaries denotation lexAlign joinPos skipPos'.split),
-# o('FeatureExtractor.featureDomains', 'rule opCount constant whType lemmaAndBinaries denotation lexAlign joinPos skipPos'.split),
- nil),
- }),
-nil) })
-
-############################################################
-
-if ARGV.size == 0
- puts "#{$0} @mode= [options]"
- puts
- puts 'This is the main entry point for all SEMPRE-related runs.'
- puts "Modes:"
- $modes.each { |name,description,func|
- puts " #{name}: #{description}"
- }
-end
-
-modesMap = {}
-$modes.each { |name,description,func|
- modesMap[name] = func
-}
-run!(sel(:mode, modesMap))
diff --git a/examples/lassie/sempre/scripts/agenda-stats b/examples/lassie/sempre/scripts/agenda-stats
deleted file mode 100755
index 43bd9b52f4..0000000000
--- a/examples/lassie/sempre/scripts/agenda-stats
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-ARGV.each { |e|
- e = e.sub(/\.exec$/, '')
- puts "===== #{e}"
- system "./fig/bin/tab -s -H -i e/#{e}.exec/learner.events -a iter group .sort utterance / ^parseTime$ ^numOfFeaturizedDerivs$ ^firstCorrectItem$ ^totalDerivs$ ^partCorrect$ ^partOracle$"
-}
diff --git a/examples/lassie/sempre/scripts/checkstyle.sh b/examples/lassie/sempre/scripts/checkstyle.sh
deleted file mode 100755
index bd68d0a712..0000000000
--- a/examples/lassie/sempre/scripts/checkstyle.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-# Check style of the code
-
-if [ -z "$1" ]; then
- files=`find src -name "*.java"`
-else
- files="$@"
-fi
-
-d=`dirname $0`
-prog="$d/../lib/checkstyle/checkstyle-6.6-all.jar"
-java -cp $prog com.puppycrawl.tools.checkstyle.Main -c `dirname $0`/checkstyle.xml $files
diff --git a/examples/lassie/sempre/scripts/checkstyle.xml b/examples/lassie/sempre/scripts/checkstyle.xml
deleted file mode 100644
index 06eda0a3d9..0000000000
--- a/examples/lassie/sempre/scripts/checkstyle.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/examples/lassie/sempre/scripts/create-geo-simple-lexicon.py b/examples/lassie/sempre/scripts/create-geo-simple-lexicon.py
deleted file mode 100755
index ce2f8171fc..0000000000
--- a/examples/lassie/sempre/scripts/create-geo-simple-lexicon.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/python
-
-import sys
-import json
-
-class LexicalEntry:
- def __init__(self, l, f, t):
- self.lexeme=l.strip()
- self.formula=f.strip()
- self.type=t.strip()
-
-out = open(sys.argv[2],'w')
-
-with open(sys.argv[1]) as f:
- for line in f:
- tokens = line.split("\t")
- if len(tokens) > 2:
- continue
- if(tokens[0] == "loc_city"):
- index = tokens[1].rfind('.')
- citystate = tokens[1][index+1:]
- city = citystate[0:citystate.rfind('_')]
- city = city.replace('_',' ').strip()
- entry = LexicalEntry(city, tokens[1], "fb:en.city")
- out.write(json.dumps(entry.__dict__)+'\n')
- elif (tokens[0] == "loc_state"):
- index = tokens[1].rfind('.')
- state = tokens[1][index+1:].strip()
- state = state.replace('_',' ').strip()
- entry = LexicalEntry(state, tokens[1], "fb:en.state")
- out.write(json.dumps(entry.__dict__)+'\n')
- elif tokens[0] == "loc_river":
- index = tokens[1].rfind('.')
- river = tokens[1][index+1:].strip()
- river = river.replace('_',' ').strip()
- entry = LexicalEntry(river+" river", tokens[1], "fb:en.river")
- out.write(json.dumps(entry.__dict__)+'\n')
- elif (tokens[0] == "loc_place"):
- index = tokens[1].rfind('.')
- place = tokens[1][index+1:].strip()
- place = place.replace('_',' ').strip()
- entry = LexicalEntry(place, tokens[1], "fb:en.place")
- out.write(json.dumps(entry.__dict__)+'\n')
- elif (tokens[0] == "loc_lake"):
- index = tokens[1].rfind('.')
- lake = tokens[1][index+1:].strip()
- lake = lake.replace('_',' ').strip()
- if not 'lake' in lake:
- lake = lake + " lake"
- entry = LexicalEntry(lake, tokens[1], "fb:en.lake")
- out.write(json.dumps(entry.__dict__)+'\n')
- elif (tokens[0] == "loc_mountain"):
- index = tokens[1].rfind('.')
- mountain = tokens[1][index+1:].strip()
- mountain = mountain.replace('_',' ').strip()
- entry = LexicalEntry("mount " + mountain, tokens[1], "fb:en.mountain")
- out.write(json.dumps(entry.__dict__)+'\n')
- elif (tokens[0] == "loc_country"):
- index = tokens[1].rfind('.')
- country = tokens[1][index+1:].strip()
- country = country.replace('_',' ').strip()
- entry = LexicalEntry(country, tokens[1], "fb:en.country")
- out.write(json.dumps(entry.__dict__)+'\n')
-
-
-out.close()
-
-
diff --git a/examples/lassie/sempre/scripts/evaluation.py b/examples/lassie/sempre/scripts/evaluation.py
deleted file mode 100755
index b7f298af23..0000000000
--- a/examples/lassie/sempre/scripts/evaluation.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/python
-
-import sys
-import json
-
-# Official evaluation script used to evaluate Freebase question answering
-# systems. Used for EMNLP 2013, ACL 2014 papers, etc.
-
-if len(sys.argv) != 2:
- sys.exit("Usage: %s " % sys.argv[0])
-
-"""return a tuple with recall, precision, and f1 for one example"""
-def computeF1(goldList,predictedList):
-
- """Assume all questions have at least one answer"""
- if len(goldList)==0:
- raise Exception("gold list may not be empty")
- """If we return an empty list recall is zero and precision is one"""
- if len(predictedList)==0:
- return (0,1,0)
- """It is guaranteed now that both lists are not empty"""
-
- precision = 0
- for entity in predictedList:
- if entity in goldList:
- precision+=1
- precision = float(precision) / len(predictedList)
-
- recall=0
- for entity in goldList:
- if entity in predictedList:
- recall+=1
- recall = float(recall) / len(goldList)
-
- f1 = 0
- if precision+recall>0:
- f1 = 2*recall*precision / (precision + recall)
- return (recall,precision,f1)
-
-averageRecall=0
-averagePrecision=0
-averageF1=0
-count=0
-
-"""Go over all lines and compute recall, precision and F1"""
-with open(sys.argv[1]) as f:
- for line in f:
- tokens = line.split("\t")
- gold = json.loads(tokens[1])
- predicted = json.loads(tokens[2])
- recall, precision, f1 = computeF1(gold,predicted)
- averageRecall += recall
- averagePrecision += precision
- averageF1 += f1
- count+=1
-
-"""Print final results"""
-averageRecall = float(averageRecall) / count
-averagePrecision = float(averagePrecision) / count
-averageF1 = float(averageF1) / count
-print "Number of questions: " + str(count)
-print "Average recall over questions: " + str(averageRecall)
-print "Average precision over questions: " + str(averagePrecision)
-print "Average f1 over questions: " + str(averageF1)
-averageNewF1 = 2 * averageRecall * averagePrecision / (averagePrecision + averageRecall)
-print "F1 of average recall and average precision: " + str(averageNewF1)
-
diff --git a/examples/lassie/sempre/scripts/extract-module-classes.rb b/examples/lassie/sempre/scripts/extract-module-classes.rb
deleted file mode 100755
index 3f3b3daaf5..0000000000
--- a/examples/lassie/sempre/scripts/extract-module-classes.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env ruby
-
-# Input: src
-# Output: module-classes.txt
-
-# For each module (e.g., core, freebase), we compute the list of classes
-# associated with that class.
-
-out_path = 'module-classes.txt'
-out = open(out_path, 'w')
-items = []
-core_packages = ['test'] # Packages in core which are not their own modules
-modules = {}
-Dir['src/**/*.java'].each { |path|
- class_name = path.sub(/^src\//, '').gsub(/\//, '.').gsub(/\.java$/, '')
- module_name = path.sub(/^.*sempre\//, '').split(/\//)[0]
- module_name = 'core' if module_name =~ /\.java$/ || core_packages.index(module_name)
- modules[module_name] = true
- items << (module_name + " " + class_name)
-}
-items.sort!
-out.puts items
-out.close
-puts "Wrote modules with #{items.size} files to #{out_path}: #{modules.keys.sort.join(' ')}"
diff --git a/examples/lassie/sempre/scripts/filterGeneratedNegations.py b/examples/lassie/sempre/scripts/filterGeneratedNegations.py
deleted file mode 100755
index a7da009ea8..0000000000
--- a/examples/lassie/sempre/scripts/filterGeneratedNegations.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/python
-
-import sys
-import json
-
-# Official evaluation script used to evaluate Freebase question answering
-# systems. Used for EMNLP 2013, ACL 2014 papers, etc.
-
-if len(sys.argv) != 3:
- sys.exit("Usage: %s " % sys.argv[0])
-
-generated = set()
-with open(sys.argv[1]) as f:
- for line in f:
- generated.add(line)
-
-out = open(sys.argv[2],'w')
-
-
-with open(sys.argv[1]) as f:
- for line in f:
- index = line.find(" not")
- if index != -1:
- newStr = line[0:index] + line[index+4:len(line)]
- if newStr in generated:
- out.write(line)
- else:
- out.write(line)
-out.close()
diff --git a/examples/lassie/sempre/scripts/find-first-pred-diff.sh b/examples/lassie/sempre/scripts/find-first-pred-diff.sh
deleted file mode 100755
index cec807cbf9..0000000000
--- a/examples/lassie/sempre/scripts/find-first-pred-diff.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# Takes two log files and outputs the first line where they differ in terms
-# of the example or the predictions
-
-egrep "Example: |Pred@| Item " ../state/execs/$1.exec/log > temp.1
-egrep "Example: |Pred@| Item " ../state/execs/$2.exec/log > temp.2
-cmp temp.1 temp.2
-#rm temp.1
-#rm temp.2
-
diff --git a/examples/lassie/sempre/scripts/find-hard-coded-paths.rb b/examples/lassie/sempre/scripts/find-hard-coded-paths.rb
deleted file mode 100755
index 32b5a89f3a..0000000000
--- a/examples/lassie/sempre/scripts/find-hard-coded-paths.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env ruby
-
-# Heuristically find all hard-coded paths in the source code.
-# There should be no absolute paths.
-Dir["src/**/*.java"].each { |sourcePath|
- IO.foreach(sourcePath) { |line|
- next unless line =~ /"([\w_\/\.]+)"/
- file = $1
- next unless file =~ /^\/[uU]\w+\/\w+/ || file =~ /^lib\//
- if file =~ /^\//
- message = " [BAD: absolute path]"
- elsif not File.exists?(file)
- message = " [BAD: does not exist]"
- else
- message = ""
- end
- puts sourcePath + ": " + file + message
- }
-}
diff --git a/examples/lassie/sempre/scripts/fix-checkstyle.rb b/examples/lassie/sempre/scripts/fix-checkstyle.rb
deleted file mode 100755
index 36fa0f62f6..0000000000
--- a/examples/lassie/sempre/scripts/fix-checkstyle.rb
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/usr/bin/env ruby
-
-# Hacky script for automatically fixing style errors. This script is far from
-# perfect and you should manually inspect all changes before making changes.
-
-# Usage:
-# scripts/fix-checkstyle.rb # Inspect changes
-# scripts/fix-checkstyle.rb mutate # Apply
-# scripts/fix-checkstyle.rb # Do to particular files
-
-mutate = ARGV.index('mutate'); ARGV = ARGV.select { |a| a != 'mutate' }
-
-files = ARGV.size > 0 ? ARGV : Dir['src/**/*.java']
-
-files.each { |path|
- in_multi_comment = false
- line_num = 0
- lines = IO.readlines(path).map { |line|
- line_num += 1
- line = line.chomp
- new_line = line + ''
-
- # Remove trailing whitespace
- new_line.gsub!(/\s+$/, '')
-
- # Add space after comment
- new_line.gsub!(/ \/\/(\w)/, '// \1')
-
- # Put space after certain operators
- new_line.gsub!(/ (if|for|while|catch)\(/, ' \1 (')
-
- # Put space
- new_line.gsub!(/( for \(\w+ \w+): /, '\1 : ')
-
- # Put space after casts
- new_line.gsub!(/\((\w+)\)([a-z])/, '(\1) \2')
-
- # Reverse modifier order
- new_line.gsub!(/ final static /, ' static final ')
-
- in_single_quote = false
- in_double_quote = false
- in_comment = false
- tokens = new_line.split(//)
- (0...tokens.size).each { |i|
- # Previous, current, next characters
- p = i-1 >= 0 ? tokens[i-1] : ''
- c = tokens[i]
- n = i+1 < tokens.size ? tokens[i+1] : ''
-
- if c == '\'' && p != '\\' # Quote
- in_single_quote = !in_single_quote
- end
- if c == '"' && p != '\\' # Quote
- in_double_quote = !in_double_quote
- end
- if c == '/' && n == '/' # Comment
- in_comment = true
- end
- if c == '/' && n == '*' # Begin multi-comment
- in_multi_comment = true
- end
-
- if !(in_single_quote || in_double_quote || in_comment || in_multi_comment || c == '')
- # Replace if not in quote or comment
- if c == ',' # One space after
- c += ' ' if n != ' '
- elsif ['++', '--'].index(c+n) # Double character operators
- c = c+n
- n = ''
- elsif ['==', '!=', '<=', '>=', '+=', '-=', '*=', '/=', '&=', '|=', '&&', '||'].index(c+n) # Double character operators
- c = c+n
- n = ''
- c = ' ' + c if p != ' '
- c = c + ' ' if tokens[i+2] != ' '
- elsif '*/=%'.index(c) # Single character operators
- # Don't do <, > because of generics
- # Don't do , + because of unaries
- c = ' ' + c if p != ' '
- c = c + ' ' if n != ' '
- end
-
- # Write back
- tokens[i] = c
- tokens[i+1] = n if i+1 < tokens.size
- end
-
- if p == '*' && c == '/' # End multi-comment
- in_multi_comment = false
- end
- }
- new_line = tokens.join('')
- #p new_line
-
- new_line.gsub!(/\. \* ;/, '.*;')
- new_line.gsub!(/\s+$/, '')
-
- if line != new_line
- puts "======= #{path} #{line_num}"
- puts "OLD: [#{line}]"
- puts "NEW: [#{new_line}]"
- end
-
- new_line
- }
-
- # Write it out
- if mutate
- out = open(path, 'w')
- out.puts lines
- out.close
- end
-}
diff --git a/examples/lassie/sempre/scripts/generate-prediction-file.sh b/examples/lassie/sempre/scripts/generate-prediction-file.sh
deleted file mode 100755
index b176c5ae8f..0000000000
--- a/examples/lassie/sempre/scripts/generate-prediction-file.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-#Generate predictions file for evaluation script
-#arguments: (1) execution numebr (2) iteration number (3) final output file
-
-fig/bin/tab e/$1.exec/learner.events iter group utterance targetValue predValue | grep -P "$2\ttest" | cut -f3,4,5 > pred_temp
-java -cp "libsempre/*:lib/*" edu.stanford.nlp.sempre.freebase.utils.FileUtils pred_temp $3
-rm pred_temp
diff --git a/examples/lassie/sempre/scripts/tunnel b/examples/lassie/sempre/scripts/tunnel
deleted file mode 100755
index 12dcc698f4..0000000000
--- a/examples/lassie/sempre/scripts/tunnel
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/bash
-
-# Allows running things locally that need to connect to cache servers or sparql
-# servers on NLP, which are behind a firewall.
-# After starting this script, connect to localhost: to connect to :.
-
-# Cache server
-host=jonsson
-port=4000
-echo "Tunnel localhost:$port => $host:$port"
-pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
-if [ -n "$pid" ]; then kill $pid; fi
-ssh -N -n -L $port:$host:$port jacob.stanford.edu &
-
-# Sparql server for Freebase
-host=jonsson
-port=3093
-echo "Tunnel localhost:$port => $host:$port"
-pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
-if [ -n "$pid" ]; then kill $pid; fi
-ssh -N -n -L $port:$host:$port jacob.stanford.edu &
-
-# Sparql server for geo
-host=jonsson
-port=3094
-echo "Tunnel localhost:$port => $host:$port"
-pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
-if [ -n "$pid" ]; then kill $pid; fi
-ssh -N -n -L $port:$host:$port jacob.stanford.edu &
-
-# Sparql server for Paleo
-host=jonsson
-port=3021
-echo "Tunnel localhost:$port => $host:$port"
-pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
-if [ -n "$pid" ]; then kill $pid; fi
-ssh -N -n -L $port:$host:$port jacob.stanford.edu &
-
-# Cache server (immutable)
-host=john5
-port=4001
-echo "Tunnel localhost:$port => $host:$port"
-pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
-if [ -n "$pid" ]; then kill $pid; fi
-ssh -N -n -L $port:$host:$port jacob.stanford.edu &
-
diff --git a/examples/lassie/sempre/scripts/verify-code-loop.rb b/examples/lassie/sempre/scripts/verify-code-loop.rb
deleted file mode 100755
index 6b353e9d2b..0000000000
--- a/examples/lassie/sempre/scripts/verify-code-loop.rb
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/usr/bin/env ruby
-
-# Verifies that the codebase is sane (compiles, doesn't crash, gets reasonable
-# accuracy) every once in a while. If something fails, an email is sent out
-
-$mode = ARGV[0]
-if $mode != 'now' && $mode != 'loop'
- puts "Usage: #{$0} (now|loop)"
- puts " now: check immediately and exit (don't email)"
- puts " loop: check only when stuff changes and loop (email if something breaks)"
- exit 1
-end
-
-# Who should be notified if the code breaks.
-$recipient = 'stanford-sempre@googlegroups.com'
-$logPath = "verify-code-loop.log"
-
-# Send out the log file to all the recipients.
-def emailLog(subject)
- return unless $mode == 'loop'
-
- maxLines = 100 # Maximum number of lines to send via email.
- numLines = IO.readlines($logPath).size
- if numLines <= maxLines
- command = "cat #{$logPath}"
- else
- # Take first few lines and last few lines to keep under maxLines.
- command = "(head -#{maxLines/2} #{$logPath}; echo '... (#{numLines - maxLines} lines omitted) ...'; tail -#{maxLines/2} #{$logPath})"
- end
- command = "#{command} | mail -s '#{subject}' #{$recipient}"
- puts "Emailing log file: #{command}"
- system command or exit 1
-end
-
-def emailBroken
- emailLog('sempre code is broken!')
-end
-
-# Print to stdout and log file.
-def log(line, newline=true)
- line = "[#{`date`.chomp}] #{line}"
- if newline
- puts line
- else
- print line
- end
- out = open($logPath, 'a')
- out.puts line
- out.close
-end
-
-# Run and command; if fail, send email.
-def run(command, verbose)
- log("======== Running: #{command}", false) if verbose
- ok = system "#{command} >> #{$logPath} 2>&1"
- puts " [#{ok ? 'ok' : 'failed'}]" if verbose
- emailBroken if not ok
- ok
-end
-
-def restart
- exit 1 if $mode == 'now'
-
- system "cat #{$logPath}"
-
- # In case there are updates
- log("Restarting #{$0}...")
- exec($0 + ' loop')
-end
-
-log("Started verify-code loop version 2")
-log("Writing to #{$logPath}...")
-firstTime = true
-while true
- break if $mode == 'now' && (not firstTime)
-
- # Whenever there's a change to the repository, run a test
- system "rm -f #{$logPath}"
- if not run('git pull', false)
- log("git pull failed - this is bad, let's just quit.")
- break
- end
-
- if $mode == 'loop' && system("grep -q 'Already up-to-date' #{$logPath}")
- # No changes, just wait
- sleep 60
- next
- end
- firstTime = false
-
- # Check everything
- log("Testing...")
- run('git log -3', true) or restart # Print out last commit messages
- run('./pull-dependencies', true) or restart
- run('ant clean', true) or restart
- run('ant', true) or restart
-
- run('scripts/find-hard-coded-paths.rb', true) or restart
-
- # Run tests
- run("./run @mode=test", true) or restart
-
- emailLog('sempre code passes tests!')
-
- break if $mode == 'now'
- restart
-end
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AbstractReinforcementParserState.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AbstractReinforcementParserState.java
deleted file mode 100644
index cf79b83481..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AbstractReinforcementParserState.java
+++ /dev/null
@@ -1,201 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.collect.Sets;
-import fig.basic.LogInfo;
-import fig.basic.MapUtils;
-import fig.basic.StopWatchSet;
-
-import java.util.*;
-
-/**
- * Contains methods for putting derivations on the chart and combining them
- * to add new derivations to the agenda
- * @author joberant
- */
-abstract class AbstractReinforcementParserState extends ChartParserState {
-
- protected final ReinforcementParser parser;
- protected final CoarseParser coarseParser;
- protected CoarseParser.CoarseParserState coarseParserState;
- protected static final double EPSILON = 10e-20; // used to break ties between agenda items
-
- public AbstractReinforcementParserState(ReinforcementParser parser, Params params, Example ex, boolean computeExpectedCounts) {
- super(parser, params, ex, computeExpectedCounts);
- this.parser = parser;
- coarseParser = parser.coarseParser;
- }
-
- protected abstract void addToAgenda(DerivationStream derivationStream);
-
- protected boolean coarseAllows(String cat, int start, int end) {
- return coarseParserState == null || coarseParserState.coarseAllows(cat, start, end);
- }
-
- //don't add to a cell in the chart that is fill
- protected boolean addToBoundedChart(Derivation deriv) {
-
- List derivations = chart[deriv.start][deriv.end].get(deriv.cat);
- totalGeneratedDerivs++;
- if (Parser.opts.visualizeChartFilling) {
- chartFillingList.add(new CatSpan(deriv.start, deriv.end, deriv.cat));
- }
- if (derivations == null) {
- chart[deriv.start][deriv.end].put(deriv.cat,
- derivations = new ArrayList<>());
- }
- if (derivations.size() < getBeamSize()) {
- derivations.add(deriv);
- Collections.sort(derivations, Derivation.derivScoreComparator); // todo - perhaps can be removed
- return true;
- } else return false;
- }
-
- // for [start, end) we try to create [start, end + i) or [start - i, end) and add unary rules
- protected void combineWithChartDerivations(Derivation deriv) {
- expandDerivRightwards(deriv);
- expandDerivLeftwards(deriv);
- applyCatUnaryRules(deriv);
- }
-
- private void expandDerivRightwards(Derivation leftChild) {
- if (parser.verbose(6))
- LogInfo.begin_track("Expanding rightward");
- Map> rhsCategoriesToRules = parser.leftToRightSiblingMap.get(leftChild.cat);
- if (rhsCategoriesToRules != null) {
- for (int i = 1; leftChild.end + i <= numTokens; ++i) {
- Set intersection = Sets.intersection(rhsCategoriesToRules.keySet(), chart[leftChild.end][leftChild.end + i].keySet());
-
- for (String rhsCategory : intersection) {
- List compatibleRules = rhsCategoriesToRules.get(rhsCategory);
- List rightChildren = chart[leftChild.end][leftChild.end + i].get(rhsCategory);
- generateParentDerivations(leftChild, rightChildren, true, compatibleRules);
- }
- }
- // handle terminals
- if (leftChild.end < numTokens)
- handleTerminalExpansion(leftChild, false, rhsCategoriesToRules);
- }
- if (parser.verbose(6))
- LogInfo.end_track();
- }
-
- private void expandDerivLeftwards(Derivation rightChild) {
- if (parser.verbose(5))
- LogInfo.begin_track("Expanding leftward");
- Map> lhsCategorisToRules = parser.rightToLeftSiblingMap.get(rightChild.cat);
- if (lhsCategorisToRules != null) {
- for (int i = 1; rightChild.start - i >= 0; ++i) {
- Set intersection = Sets.intersection(lhsCategorisToRules.keySet(), chart[rightChild.start - i][rightChild.start].keySet());
-
- for (String lhsCategory : intersection) {
- List compatibleRules = lhsCategorisToRules.get(lhsCategory);
- List leftChildren = chart[rightChild.start - i][rightChild.start].get(lhsCategory);
- generateParentDerivations(rightChild, leftChildren, false, compatibleRules);
- }
- }
- // handle terminals
- if (rightChild.start > 0)
- handleTerminalExpansion(rightChild, true, lhsCategorisToRules);
- }
- if (parser.verbose(5))
- LogInfo.end_track();
- }
-
- private void generateParentDerivations(Derivation expandedDeriv, List otherDerivs,
- boolean expandedLeftChild, List compatibleRules) {
-
- for (Derivation otherDeriv : otherDerivs) {
- Derivation leftChild, rightChild;
- if (expandedLeftChild) {
- leftChild = expandedDeriv;
- rightChild = otherDeriv;
- } else {
- leftChild = otherDeriv;
- rightChild = expandedDeriv;
- }
- List children = new ArrayList<>();
- children.add(leftChild);
- children.add(rightChild);
- for (Rule rule : compatibleRules) {
- if (coarseAllows(rule.lhs, leftChild.start, rightChild.end)) {
- DerivationStream resDerivations = applyRule(leftChild.start, rightChild.end, rule, children);
-
- if (!resDerivations.hasNext())
- continue;
- addToAgenda(resDerivations);
- }
- }
- }
- }
-
- // returns the score of derivation computed
- private DerivationStream applyRule(int start, int end, Rule rule, List children) {
- try {
- if (Parser.opts.verbose >= 5)
- LogInfo.logs("applyRule %s %s %s %s", start, end, rule, children);
- StopWatchSet.begin(rule.getSemRepn()); // measuring time
- StopWatchSet.begin(rule.toString());
- DerivationStream results = rule.sem.call(ex,
- new SemanticFn.CallInfo(rule.lhs, start, end, rule, com.google.common.collect.ImmutableList.copyOf(children)));
- StopWatchSet.end();
- StopWatchSet.end();
- return results;
- } catch (Exception e) {
- LogInfo.errors("Composition failed: rule = %s, children = %s", rule, children);
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- private void applyCatUnaryRules(Derivation deriv) {
- if (parser.verbose(4))
- LogInfo.begin_track("Category unary rules");
- for (Rule rule : parser.catUnaryRules) {
- if (!coarseAllows(rule.lhs, deriv.start, deriv.end))
- continue;
- if (deriv.cat.equals(rule.rhs.get(0))) {
- DerivationStream resDerivations = applyRule(deriv.start, deriv.end, rule, Collections.singletonList(deriv));
- addToAgenda(resDerivations);
- }
- }
- if (parser.verbose(4))
- LogInfo.end_track();
- }
-
- public List gatherRhsTerminalsDerivations() {
- List derivs = new ArrayList<>();
- final List empty = Collections.emptyList();
-
- for (int i = 0; i < numTokens; i++) {
- for (int j = i + 1; j <= numTokens; j++) {
- for (Rule rule : MapUtils.get(parser.terminalsToRulesList, phrases[i][j], Collections.emptyList())) {
- if (!coarseAllows(rule.lhs, i, j))
- continue;
- derivs.add(applyRule(i, j, rule, empty));
- }
- }
- }
- return derivs;
- }
-
- // rules where one word is a terminal and the other is a non-terminal
- private void handleTerminalExpansion(Derivation child, boolean before, Map> categoriesToRules) {
-
- String phrase = before ? phrases[child.start - 1][child.start] : phrases[child.end][child.end + 1];
- int start = before ? child.start - 1 : child.start;
- int end = before ? child.end : child.end + 1;
-
- if (categoriesToRules.containsKey(phrase)) {
- List children = new ArrayList<>();
- children.add(child);
- for (Rule rule : categoriesToRules.get(phrase)) {
- if (coarseAllows(rule.lhs, start, end)) {
- DerivationStream resDerivations = applyRule(start, end, rule, children);
- if (!resDerivations.hasNext())
- continue;
- addToAgenda(resDerivations);
- }
- }
- }
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ActionFormula.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ActionFormula.java
deleted file mode 100644
index 120493318a..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ActionFormula.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.List;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-
-import fig.basic.LispTree;
-
-/**
- * An ActionFormula represent a compositional action used in the interactive
- * package : is used as a prefix to denote an ActionFormula primitive (:
- * actioname args) sequential (:s ActionFormula ActionFormula ...) repeat (:loop
- * Number ActionFormula) conditional (:if Set ActionFormula) block scoping (:blk
- * ActionFormula)
- *
- * @author sidaw
- */
-public class ActionFormula extends Formula {
- public enum Mode {
- primitive(":"), // (: remove *)
- sequential(":s"), // (:s (: add red top) (: remove this))
- repeat(":loop"), // (:loop (count (has color green)) (: add red top))
- conditional(":if"), // (:if (count (has color green)) (: add red top))
- whileloop(":while"), // (:while (count (has color green)) (: add red top))
- forset(":for"), // (:for (and this (color red)) (:s (: add red top) (: add
- // yellow top) (: remove)))
- foreach(":foreach"), // (:foreach * (add ((reverse color) this) top))
-
- // primitives for declaring variables
- // let(":let"), // (:let X *),
- // set(":set"), // (:set X *)
-
- block(":blk"), // start a block of code (like {}) with a new scope
- blockr(":blkr"), // also return a result after finishing the block
- isolate(":isolate"), other(":?");
-
- private final String value;
-
- Mode(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return this.value;
- }
- };
-
- public final Mode mode;
- public final List args;
-
- public ActionFormula(Mode mode, List args) {
- this.mode = mode;
- this.args = args;
- }
-
- public static Mode parseMode(String mode) {
- if (mode == null)
- return null;
- for (Mode m : Mode.values()) {
- // LogInfo.logs("mode string %s \t== %s \t!= %s", m.toString(), mode,
- // m.name());
- if (m.toString().equals(mode))
- return m;
- }
- if (mode.startsWith(":"))
- throw new RuntimeException("Unsupported ActionFormula mode");
- return null;
- }
-
- @Override
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild(this.mode.toString());
- for (Formula arg : args)
- tree.addChild(arg.toLispTree());
- return tree;
- }
-
- @Override
- public void forEach(Function func) {
- if (!func.apply(this)) {
- for (Formula arg : args)
- arg.forEach(func);
- }
- }
-
- @Override
- public Formula map(Function transform) {
- Formula result = transform.apply(this);
- if (result != null)
- return result;
- List newArgs = Lists.newArrayList();
- for (Formula arg : args)
- newArgs.add(arg.map(transform));
- return new ActionFormula(this.mode, newArgs);
- }
-
- @Override
- public List mapToList(Function> transform, boolean alwaysRecurse) {
- List res = transform.apply(this);
- if (res.isEmpty() || alwaysRecurse) {
- for (Formula arg : args)
- res.addAll(arg.mapToList(transform, alwaysRecurse));
- }
- return res;
- }
-
- @SuppressWarnings({ "equalshashcode" })
- @Override
- public boolean equals(Object thatObj) {
- if (!(thatObj instanceof ActionFormula))
- return false;
- ActionFormula that = (ActionFormula) thatObj;
- if (!this.mode.equals(that.mode))
- return false;
- if (!this.args.equals(that.args))
- return false;
- return true;
- }
-
- @Override
- public int computeHashCode() {
- int hash = 0x7ed55d16;
- hash = hash * 0xd3a2646c + mode.hashCode();
- hash = hash * 0xd3a2646c + args.hashCode();
- return hash;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AggregateFormula.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AggregateFormula.java
deleted file mode 100644
index c5ce22c7ac..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AggregateFormula.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.base.Function;
-import fig.basic.LispTree;
-
-import java.util.List;
-
-/**
- * 'Aggregate' takes a set and computes some number on that set.
- *
- * @author Percy Liang
- */
-public class AggregateFormula extends Formula {
- public enum Mode { count, sum, avg, min, max };
- public final Mode mode;
- public final Formula child;
-
- public AggregateFormula(Mode mode, Formula child) {
- this.mode = mode;
- this.child = child;
- }
-
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild(mode.toString());
- tree.addChild(child.toLispTree());
- return tree;
- }
-
- public static Mode parseMode(String mode) {
- if ("count".equals(mode)) return Mode.count;
- if ("sum".equals(mode)) return Mode.sum;
- if ("avg".equals(mode)) return Mode.avg;
- if ("min".equals(mode)) return Mode.min;
- if ("max".equals(mode)) return Mode.max;
- return null;
- }
-
- @Override
- public void forEach(Function func) {
- if (!func.apply(this)) child.forEach(func);
- }
-
- @Override
- public Formula map(Function func) {
- Formula result = func.apply(this);
- return result == null ? new AggregateFormula(mode, child.map(func)) : result;
- }
-
- @Override
- public List mapToList(Function> func, boolean alwaysRecurse) {
- List res = func.apply(this);
- if (res.isEmpty() || alwaysRecurse)
- res.addAll(child.mapToList(func, alwaysRecurse));
- return res;
- }
-
- @SuppressWarnings({"equalshashcode"})
- @Override
- public boolean equals(Object thatObj) {
- if (!(thatObj instanceof AggregateFormula)) return false;
- AggregateFormula that = (AggregateFormula) thatObj;
- if (!this.mode.equals(that.mode)) return false;
- if (!this.child.equals(that.child)) return false;
- return true;
- }
-
- public int computeHashCode() {
- int hash = 0x7ed55d16;
- hash = hash * 0xd3a2646c + mode.toString().hashCode();
- hash = hash * 0xd3a2646c + child.hashCode();
- return hash;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ArithmeticFormula.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ArithmeticFormula.java
deleted file mode 100644
index 524e158614..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ArithmeticFormula.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.base.Function;
-import fig.basic.LispTree;
-
-import java.util.List;
-
-/**
- * Performs arithmetic operations (+, -, *, /).
- * Note that these are non-binary relations, which means we can't model them
- * using a join.
- *
- * @author Percy Liang
- */
-public class ArithmeticFormula extends Formula {
- public enum Mode { add, sub, mul, div };
- public final Mode mode;
- public final Formula child1;
- public final Formula child2;
-
- public ArithmeticFormula(Mode mode, Formula child1, Formula child2) {
- this.mode = mode;
- this.child1 = child1;
- this.child2 = child2;
- }
-
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild(modeToString(mode));
- tree.addChild(child1.toLispTree());
- tree.addChild(child2.toLispTree());
- return tree;
- }
-
- @Override
- public void forEach(Function func) {
- if (!func.apply(this)) { child1.forEach(func); child2.forEach(func); }
- }
-
- @Override
- public Formula map(Function func) {
- Formula result = func.apply(this);
- return result == null ? new ArithmeticFormula(mode, child1.map(func), child2.map(func)) : result;
- }
-
- @Override
- public List mapToList(Function> func, boolean alwaysRecurse) {
- List res = func.apply(this);
- if (res.isEmpty() || alwaysRecurse) {
- res.addAll(child1.mapToList(func, alwaysRecurse));
- res.addAll(child2.mapToList(func, alwaysRecurse));
- }
- return res;
- }
-
- public static Mode parseMode(String mode) {
- if ("+".equals(mode)) return Mode.add;
- if ("-".equals(mode)) return Mode.sub;
- if ("*".equals(mode)) return Mode.mul;
- if ("/".equals(mode)) return Mode.div;
- return null;
- }
-
- public static String modeToString(Mode mode) {
- switch (mode) {
- case add: return "+";
- case sub: return "-";
- case mul: return "*";
- case div: return "/";
- default: throw new RuntimeException("Invalid mode: " + mode);
- }
- }
-
- @SuppressWarnings({"equalshashcode"})
- @Override
- public boolean equals(Object thatObj) {
- if (!(thatObj instanceof ArithmeticFormula)) return false;
- ArithmeticFormula that = (ArithmeticFormula) thatObj;
- if (this.mode != that.mode) return false;
- if (!this.child1.equals(that.child1)) return false;
- if (!this.child2.equals(that.child2)) return false;
- return true;
- }
-
- public int computeHashCode() {
- int hash = 0x7ed55d16;
- hash = hash * 0xd3a2646c + mode.toString().hashCode(); // Note: don't call hashCode() on mode directly.
- hash = hash * 0xd3a2646c + child1.hashCode();
- hash = hash * 0xd3a2646c + child2.hashCode();
- return hash;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AtomicSemType.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AtomicSemType.java
deleted file mode 100644
index 962b0d66e4..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/AtomicSemType.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import fig.basic.LispTree;
-
-// Represents an atomic type (strings, entities, numbers, dates, etc.).
-public class AtomicSemType extends SemType {
- public final String name;
- public AtomicSemType(String name) {
- if (name == null) throw new RuntimeException("Null name");
- this.name = name;
- }
- public boolean isValid() { return true; }
- public SemType meet(SemType that) {
- if (that instanceof TopSemType) return this;
- if (that instanceof UnionSemType) return that.meet(this);
- if (that instanceof AtomicSemType) {
- String name1 = this.name;
- String name2 = ((AtomicSemType) that).name;
- if (name1.equals(name2)) return this; // Shortcut: the same
- if (SemTypeHierarchy.singleton.getSupertypes(name1).contains(name2)) return this;
- if (SemTypeHierarchy.singleton.getSupertypes(name2).contains(name1)) return that;
- return SemType.bottomType;
- }
- return SemType.bottomType;
- }
-
- public SemType apply(SemType that) { return SemType.bottomType; }
- public SemType reverse() { return SemType.bottomType; }
- public LispTree toLispTree() { return LispTree.proto.newLeaf(name); }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BadFormulaException.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BadFormulaException.java
deleted file mode 100644
index cb4f6c8c4c..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BadFormulaException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-public class BadFormulaException extends RuntimeException {
- public static final long serialVersionUID = 86586128316354597L;
-
- String message;
-
- public BadFormulaException(String message) { this.message = message; }
-
- // Combine multiple exceptions
- public BadFormulaException(BadFormulaException... exceptions) {
- StringBuilder builder = new StringBuilder();
- for (BadFormulaException exception : exceptions)
- builder.append(" | ").append(exception.message);
- //builder.append(exception).append("\n");
- this.message = builder.toString().substring(3);
- }
-
- @Override
- public String toString() { return message; }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BeamParser.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BeamParser.java
deleted file mode 100644
index 7f9bb16231..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BeamParser.java
+++ /dev/null
@@ -1,315 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-
-import fig.basic.*;
-import fig.exec.Execution;
-
-import java.util.*;
-
-/**
- * A simple bottom-up chart-based parser that keeps the |beamSize| top
- * derivations for each chart cell (cat, start, end). Also supports fast
- * indexing of lexicalized rules using a trie.
- *
- * Note that this code does not rely on the Grammar being binarized,
- * which makes it more complex.
- *
- * @author Percy Liang
- */
-public class BeamParser extends Parser {
- public static class Options {
- @Option public int maxNewTreesPerSpan = Integer.MAX_VALUE;
- }
- public static Options opts = new Options();
-
- Trie trie; // For non-cat-unary rules
-
- public BeamParser(Spec spec) {
- super(spec);
-
- // Index the non-cat-unary rules
- trie = new Trie();
- for (Rule rule : grammar.rules)
- addRule(rule);
- if (Parser.opts.visualizeChartFilling)
- this.chartFillOut = IOUtils.openOutAppendEasy(Execution.getFile("chartfill"));
- }
-
- public synchronized void addRule(Rule rule) {
- if (!rule.isCatUnary())
- trie.add(rule);
- }
-
- public ParserState newParserState(Params params, Example ex, boolean computeExpectedCounts) {
- BeamParserState coarseState = null;
- if (Parser.opts.coarsePrune) {
- LogInfo.begin_track("Parser.coarsePrune");
- coarseState = new BeamParserState(this, params, ex, computeExpectedCounts, BeamParserState.Mode.bool, null);
- coarseState.infer();
- coarseState.keepTopDownReachable();
- LogInfo.end_track();
- }
- return new BeamParserState(this, params, ex, computeExpectedCounts, BeamParserState.Mode.full, coarseState);
- }
-}
-
-/**
- * Stores BeamParser information about parsing a particular example. The actual
- * parsing code lives here.
- *
- * @author Percy Liang
- * @author Roy Frostig
- */
-class BeamParserState extends ChartParserState {
- public final Mode mode;
- // Modes:
- // 1) Bool: just check if cells (cat, start, end) are reachable (to prune chart)
- // 2) Full: compute everything
- public enum Mode { bool, full }
-
- private final BeamParser parser;
- private final BeamParserState coarseState; // Used to prune
-
- public BeamParserState(BeamParser parser, Params params, Example ex, boolean computeExpectedCounts,
- Mode mode, BeamParserState coarseState) {
- super(parser, params, ex, computeExpectedCounts);
- this.parser = parser;
- this.mode = mode;
- this.coarseState = coarseState;
- }
-
- public void infer() {
- if (numTokens == 0)
- return;
-
- if (parser.verbose(2)) LogInfo.begin_track("ParserState.infer");
-
- // Base case
- for (Derivation deriv : gatherTokenAndPhraseDerivations()) {
- featurizeAndScoreDerivation(deriv);
- addToChart(deriv);
- }
-
- // Recursive case
- for (int len = 1; len <= numTokens; len++)
- for (int i = 0; i + len <= numTokens; i++)
- build(i, i + len);
-
- if (parser.verbose(2)) LogInfo.end_track();
-
- // Visualize
- if (parser.chartFillOut != null && Parser.opts.visualizeChartFilling && this.mode != Mode.bool) {
- parser.chartFillOut.println(Json.writeValueAsStringHard(new ChartFillingData(ex.id, chartFillingList,
- ex.utterance, ex.numTokens())));
- parser.chartFillOut.flush();
- }
-
- setPredDerivations();
-
- if (mode == Mode.full) {
- // Compute gradient with respect to the predicted derivations
- ensureExecuted();
- if (computeExpectedCounts) {
- expectedCounts = new HashMap<>();
- ParserState.computeExpectedCounts(predDerivations, expectedCounts);
- }
- }
- }
-
- // Create all the derivations for the span [start, end).
- protected void build(int start, int end) {
- applyNonCatUnaryRules(start, end, start, parser.trie, new ArrayList(), new IntRef(0));
-
- Set cellsPruned = new HashSet<>();
- applyCatUnaryRules(start, end, cellsPruned);
-
- for (Map.Entry> entry : chart[start][end].entrySet())
- pruneCell(cellsPruned, entry.getKey(), start, end, entry.getValue());
- }
-
- private static String cellString(String cat, int start, int end) {
- return cat + ":" + start + ":" + end;
- }
-
- // Return number of new derivations added
- private int applyRule(int start, int end, Rule rule, List children) {
- if (Parser.opts.verbose >= 5) LogInfo.logs("applyRule %s %s %s %s", start, end, rule, children);
- try {
- if (mode == Mode.full) {
- StopWatchSet.begin(rule.getSemRepn());
- DerivationStream results = rule.sem.call(ex,
- new SemanticFn.CallInfo(rule.lhs, start, end, rule, ImmutableList.copyOf(children)));
- StopWatchSet.end();
- while (results.hasNext()) {
- Derivation newDeriv = results.next();
- featurizeAndScoreDerivation(newDeriv);
- addToChart(newDeriv);
- }
- return results.estimatedSize();
- } else if (mode == Mode.bool) {
- Derivation deriv = new Derivation.Builder()
- .cat(rule.lhs).start(start).end(end).rule(rule)
- .children(ImmutableList.copyOf(children))
- .formula(Formula.nullFormula)
- .createDerivation();
- addToChart(deriv);
- return 1;
- } else {
- throw new RuntimeException("Invalid mode");
- }
- } catch (Exception e) {
- LogInfo.errors("Composition failed: rule = %s, children = %s", rule, children);
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- // Don't prune the same cell more than once.
- protected void pruneCell(Set cellsPruned, String cat, int start, int end, List derivations) {
- String cell = cellString(cat, start, end);
- if (cellsPruned.contains(cell)) return;
- cellsPruned.add(cell);
- pruneCell(cell, derivations);
- }
-
- // Apply all unary rules with RHS category.
- // Before applying each unary rule (rule.lhs -> rhsCat), we can prune the cell of rhsCat
- // because we assume acyclicity, so rhsCat's cell will never grow.
- private void applyCatUnaryRules(int start, int end, Set cellsPruned) {
- for (Rule rule : parser.catUnaryRules) {
- if (!coarseAllows(rule.lhs, start, end))
- continue;
- String rhsCat = rule.rhs.get(0);
- List derivations = chart[start][end].get(rhsCat);
- if (Parser.opts.verbose >= 5)
- LogInfo.logs("applyCatUnaryRules %s %s %s %s", start, end, rule, derivations);
- if (derivations == null) continue;
-
- pruneCell(cellsPruned, rhsCat, start, end, derivations); // Prune before applying rules to eliminate cruft!
-
- for (Derivation deriv : derivations)
- applyRule(start, end, rule, Collections.singletonList(deriv));
- }
- }
-
- // Strategy: walk along the input on span (start:end) and traverse the trie
- // to get the list of the rules that could apply by matching the RHS.
- // start:end: span we're dealing with.
- // i: current token position
- // node: contains a link to the RHS that could apply.
- // children: the derivations that't we're building up.
- // numNew: Keep track of number of new derivations created
- private void applyNonCatUnaryRules(int start,
- int end,
- int i,
- Trie node,
- ArrayList children,
- IntRef numNew) {
- if (node == null) return;
- if (!coarseAllows(node, start, end)) return;
-
- if (Parser.opts.verbose >= 5) {
- LogInfo.logs(
- "applyNonCatUnaryRules(start=%d, end=%d, i=%d, children=[%s], %s rules)",
- start, end, i, Joiner.on(", ").join(children), node.rules.size());
- }
-
- // Base case: our fencepost has walked to the end of the span, so
- // apply the rule on all the children gathered during the walk.
- if (i == end) {
- for (Rule rule : node.rules) {
- if (coarseAllows(rule.lhs, start, end)) {
- numNew.value += applyRule(start, end, rule, children);
- }
- }
- return;
- }
-
- // Advance terminal token
- applyNonCatUnaryRules(
- start, end, i + 1,
- node.next(ex.token(i)),
- children,
- numNew);
-
- // Advance non-terminal category
- for (int j = i + 1; j <= end; j++) {
- for (Map.Entry> entry : chart[i][j].entrySet()) {
- Trie nextNode = node.next(entry.getKey());
- for (Derivation arg : entry.getValue()) {
- children.add(arg);
- applyNonCatUnaryRules(start, end, j, nextNode, children, numNew);
- children.remove(children.size() - 1);
- if (mode != Mode.full) break; // Only need one hypothesis
- if (numNew.value >= BeamParser.opts.maxNewTreesPerSpan) return;
- }
- }
- }
- }
-
- // -- Coarse state pruning --
-
- // Remove any (cat, start, end) which isn't reachable from the
- // (Rule.rootCat, 0, numTokens)
- public void keepTopDownReachable() {
- if (numTokens == 0) return;
-
- Set reachable = new HashSet<>();
- collectReachable(reachable, Rule.rootCat, 0, numTokens);
-
- // Remove all derivations associated with (cat, start, end) that aren't reachable.
- for (int start = 0; start < numTokens; start++) {
- for (int end = start + 1; end <= numTokens; end++) {
- List toRemoveCats = new LinkedList<>();
- for (String cat : chart[start][end].keySet()) {
- String key = catStartEndKey(cat, start, end);
- if (!reachable.contains(key)) {
- toRemoveCats.add(cat);
- }
- }
- Collections.sort(toRemoveCats);
- for (String cat : toRemoveCats) {
- if (parser.verbose(4)) {
- LogInfo.logs("Pruning chart %s(%s,%s)", cat, start, end);
- }
- chart[start][end].remove(cat);
- }
- }
- }
- }
-
- private void collectReachable(Set reachable, String cat, int start, int end) {
- String key = catStartEndKey(cat, start, end);
- if (reachable.contains(key)) return;
-
- if (!chart[start][end].containsKey(cat)) {
- // This should only happen for the root when there are no parses.
- return;
- }
-
- reachable.add(key);
- for (Derivation deriv : chart[start][end].get(cat)) {
- for (Derivation subderiv : deriv.children) {
- collectReachable(reachable, subderiv.cat, subderiv.start, subderiv.end);
- }
- }
- }
-
- private String catStartEndKey(String cat, int start, int end) {
- return cat + ":" + start + ":" + end;
- }
-
- // For pruning with the coarse state
- protected boolean coarseAllows(Trie node, int start, int end) {
- if (coarseState == null) return true;
- return SetUtils.intersects(
- node.cats,
- coarseState.chart[start][end].keySet());
- }
- protected boolean coarseAllows(String cat, int start, int end) {
- if (coarseState == null) return true;
- return coarseState.chart[start][end].containsKey(cat);
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BooleanValue.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BooleanValue.java
deleted file mode 100644
index 497683daf5..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BooleanValue.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import fig.basic.LispTree;
-
-/**
- * Represents a boolean.
- * @author Percy Liang
- **/
-public class BooleanValue extends Value {
- public final boolean value;
-
- public BooleanValue(boolean value) { this.value = value; }
- public BooleanValue(LispTree tree) { this.value = Boolean.parseBoolean(tree.child(1).value); }
-
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild("boolean");
- tree.addChild(value + "");
- return tree;
- }
-
- @Override public String sortString() { return "" + value; }
- @Override public String pureString() { return "" + value; }
-
- @Override public int hashCode() { return Boolean.valueOf(value).hashCode(); }
- @Override public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- BooleanValue that = (BooleanValue) o;
- return this.value == that.value;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BoundedPriorityQueue.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BoundedPriorityQueue.java
deleted file mode 100644
index e2775c9ba8..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/BoundedPriorityQueue.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.*;
-
-/**
- * Created by joberant on 3/27/14.
- * A priority queue that holds no more than N elements
- */
-public class BoundedPriorityQueue extends TreeSet {
- private static final long serialVersionUID = 5724671156522771658L;
- private int elementsLeft;
-
- public BoundedPriorityQueue(int maxSize, Comparator comparator) {
- super(comparator);
- this.elementsLeft = maxSize;
- }
-
- /**
- * @return true if element was added, false otherwise
- * */
- @Override
- public boolean add(E e) {
- if (elementsLeft == 0 && size() == 0) {
- // max size was initiated to zero => just return false
- return false;
- } else if (elementsLeft > 0) {
- // queue isn't full => add element and decrement elementsLeft
- boolean added = super.add(e);
- if (added) {
- elementsLeft--;
- }
- return added;
- } else {
- // there is already 1 or more elements => compare to the least
- int compared = super.comparator().compare(e, this.last());
- if (compared == -1) {
- // new element is larger than the least in queue => pull the least and add new one to queue
- pollLast();
- super.add(e);
- return true;
- } else {
- // new element is less than the least in queue => return false
- return false;
- }
- }
- }
-
- public List toList() {
- List res = new ArrayList<>();
- for (E e : this)
- res.add(e);
- return res;
- }
-
- public static void main(String[] args) {
-
- BoundedPriorityQueue queue =
- new BoundedPriorityQueue<>(5,
- new Comparator() {
- @Override
- public int compare(Integer o1, Integer o2) {
- return o1.compareTo(o2);
- }
- });
-
- queue.add(10);
- queue.add(8);
- queue.add(4);
- queue.add(12);
- queue.add(3);
- queue.add(7);
- queue.add(9);
- for (Integer num : queue) {
- System.out.println(num);
- }
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Builder.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Builder.java
deleted file mode 100644
index edfd89899e..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Builder.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.base.Strings;
-
-import fig.basic.Option;
-import fig.basic.Utils;
-
-/**
- * Contains all the components (grammar, feature extractor, parser, parameters)
- * needed for semantic parsing.
- *
- * @author Percy Liang
- */
-public class Builder {
- public static class Options {
- @Option public String inParamsPath;
- @Option public String executor = "JavaExecutor";
- @Option public String valueEvaluator = "ExactValueEvaluator";
- @Option public String parser = "BeamParser";
- }
-
- public static Options opts = new Options();
-
- public Grammar grammar;
- public Executor executor;
- public ValueEvaluator valueEvaluator;
- public FeatureExtractor extractor;
- public Parser parser;
- public Params params;
-
- public void build() {
- grammar = null;
- executor = null;
- valueEvaluator = null;
- extractor = null;
- parser = null;
- params = null;
- buildUnspecified();
- }
-
- public void buildUnspecified() {
- // Grammar
- if (grammar == null) {
- grammar = new Grammar();
- grammar.read();
- grammar.write();
- }
-
- // Executor
- if (executor == null)
- executor = (Executor) Utils.newInstanceHard(SempreUtils.resolveClassName(opts.executor));
-
- // Value evaluator
- if (valueEvaluator == null)
- valueEvaluator = (ValueEvaluator) Utils.newInstanceHard(SempreUtils.resolveClassName(opts.valueEvaluator));
-
- // Feature extractor
- if (extractor == null)
- extractor = new FeatureExtractor(executor);
-
- // Parser
- if (parser == null)
- parser = buildParser(new Parser.Spec(grammar, extractor, executor, valueEvaluator));
-
- // Parameters
- if (params == null) {
- params = new Params();
- if (!Strings.isNullOrEmpty(opts.inParamsPath))
- params.read(opts.inParamsPath);
- }
- }
-
- public static Parser buildParser(Parser.Spec spec) {
- switch (opts.parser) {
- case "BeamParser":
- return new BeamParser(spec);
- case "ReinforcementParser":
- return new ReinforcementParser(spec);
- case "FloatingParser":
- return new FloatingParser(spec);
- default:
- // Try instantiating by name
- try {
- Class> parserClass = Class.forName(SempreUtils.resolveClassName(opts.parser));
- return (Parser) parserClass.getConstructor(spec.getClass()).newInstance(spec);
- } catch (ClassNotFoundException e1) {
- throw new RuntimeException("Illegal parser: " + opts.parser);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("Error while instantiating parser: " + opts.parser + "\n" + e);
- }
- }
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CallFormula.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CallFormula.java
deleted file mode 100644
index 98a9b14571..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CallFormula.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import fig.basic.LispTree;
-
-import java.util.List;
-
-/**
- * A CallFormula represents a function call.
- * See JavaExecutor for the semantics of this formula.
- * (call func arg_1 ... arg_k)
- *
- * @author Percy Liang
- */
-public class CallFormula extends Formula {
- public final Formula func;
- public final List args;
-
- public CallFormula(String func, List args) {
- this(Formulas.newNameFormula(func), args);
- }
-
- public CallFormula(Formula func, List args) {
- this.func = func;
- this.args = args;
- }
-
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild("call");
- tree.addChild(func.toLispTree());
- for (Formula arg : args)
- tree.addChild(arg.toLispTree());
- return tree;
- }
-
- @Override
- public void forEach(Function func) {
- if (!func.apply(this)) {
- this.func.forEach(func);
- for (Formula arg: args)
- arg.forEach(func);
- }
- }
-
- @Override
- public Formula map(Function transform) {
- Formula result = transform.apply(this);
- if (result != null) return result;
- Formula newFunc = func.map(transform);
- List newArgs = Lists.newArrayList();
- for (Formula arg : args)
- newArgs.add(arg.map(transform));
- return new CallFormula(newFunc, newArgs);
- }
-
- @Override
- public List mapToList(Function> transform, boolean alwaysRecurse) {
- List res = transform.apply(this);
- if (res.isEmpty() || alwaysRecurse) {
- res.addAll(func.mapToList(transform, alwaysRecurse));
- for (Formula arg : args)
- res.addAll(arg.mapToList(transform, alwaysRecurse));
- }
- return res;
- }
-
- @SuppressWarnings({"equalshashcode"})
- @Override
- public boolean equals(Object thatObj) {
- if (!(thatObj instanceof CallFormula)) return false;
- CallFormula that = (CallFormula) thatObj;
- if (!this.func.equals(that.func)) return false;
- if (!this.args.equals(that.args)) return false;
- return true;
- }
-
- public int computeHashCode() {
- int hash = 0x7ed55d16;
- hash = hash * 0xd3a2646c + func.hashCode();
- hash = hash * 0xd3a2646c + args.hashCode();
- return hash;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CallTypeInfo.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CallTypeInfo.java
deleted file mode 100644
index 841278cf0c..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CallTypeInfo.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.List;
-
-// Type information for each function in CallFormula.
-public class CallTypeInfo {
- public final String func;
- public final List argTypes;
- public final SemType retType;
-
- public CallTypeInfo(String func, List argTypes, SemType retType) {
- this.func = func;
- this.argTypes = argTypes;
- this.retType = retType;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CanonicalNames.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CanonicalNames.java
deleted file mode 100644
index 2521f67c17..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CanonicalNames.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.*;
-
-/**
- * List of canonical names that we borrowed from Freebase.
- *
- * These names and helper methods are independent from the Freebase schema
- * (even though the names begin with "fb:").
- *
- * @author ppasupat
- */
-public final class CanonicalNames {
- private CanonicalNames() { }
-
- // Standard type names
- public static final String PREFIX = "fb:";
- public static final String BOOLEAN = "fb:type.boolean";
- public static final String INT = "fb:type.int";
- public static final String FLOAT = "fb:type.float";
- public static final String DATE = "fb:type.datetime";
- public static final String TIME = "fb:type.time";
- public static final String TEXT = "fb:type.text";
- public static final String NUMBER = "fb:type.number";
- public static final String ENTITY = "fb:common.topic";
- public static final String ANY = "fb:type.any";
-
- public static final List PRIMITIVES = Collections.unmodifiableList(
- Arrays.asList(BOOLEAN, INT, FLOAT, DATE, TEXT, NUMBER));
-
- // Standard relations
- public static final String TYPE = "fb:type.object.type";
- public static final String NAME = "fb:type.object.name";
-
- // Special Unary: star (*)
- public static final String STAR = "*";
-
- // Special Binaries: comparison
- public static final Map COMPARATOR_REVERSE = new HashMap<>();
- static {
- COMPARATOR_REVERSE.put("!=", "!="); // a != b implies b != a
- COMPARATOR_REVERSE.put("<", ">=");
- COMPARATOR_REVERSE.put(">", "<=");
- COMPARATOR_REVERSE.put("<=", ">");
- COMPARATOR_REVERSE.put(">=", "<");
- }
- public static final Set COMPARATORS = COMPARATOR_REVERSE.keySet();
-
- // Special Binary: colon (:)
- public static final String COLON = ":";
-
- // SemType for special unaries and binaries
- public static final Map SPECIAL_SEMTYPES = new HashMap<>();
- static {
- SPECIAL_SEMTYPES.put("*", SemType.anyType);
- SPECIAL_SEMTYPES.put("!=", SemType.anyAnyFunc);
- SPECIAL_SEMTYPES.put("<", SemType.compareFunc);
- SPECIAL_SEMTYPES.put(">", SemType.compareFunc);
- SPECIAL_SEMTYPES.put("<=", SemType.compareFunc);
- SPECIAL_SEMTYPES.put(">=", SemType.compareFunc);
- SPECIAL_SEMTYPES.put(":", SemType.anyAnyFunc);
- }
-
- // Unary: fb:domain.type [contains exactly one period]
- // Special Unary: star (*)
- public static boolean isUnary(String s) {
- if (STAR.equals(s)) return true;
- int i = s.indexOf('.');
- if (i == -1) return false;
- i = s.indexOf('.', i + 1);
- if (i == -1) return true;
- return false;
- }
- public static boolean isUnary(Value value) {
- return value instanceof NameValue && isUnary((((NameValue) value).id));
- }
-
- // Binary: fb:domain.type.property [contains two periods]
- // Also catch reversed binary shorthand [!fb:people.person.parent]
- // Special Binaries: comparison (<, >, etc.) and colon (:)
- public static boolean isBinary(String s) {
- if (COMPARATORS.contains(s) || COLON.equals(s)) return true;
- int i = s.indexOf('.');
- if (i == -1) return false;
- i = s.indexOf('.', i + 1);
- if (i == -1) return false;
- return true;
- }
- public static boolean isBinary(Value value) {
- return value instanceof NameValue && isBinary((((NameValue) value).id));
- }
-
- // Return whether |property| is the name of a reverse property.
- // Convention: ! is the prefix for reverses.
- public static boolean isReverseProperty(String property) {
- return property.startsWith("!") && !property.equals("!=");
- }
- public static boolean isReverseProperty(Value value) {
- return value instanceof NameValue && isReverseProperty(((NameValue) value).id);
- }
-
- // Return the reverse property as a String
- public static String reverseProperty(String property) {
- if (COMPARATORS.contains(property))
- return COMPARATOR_REVERSE.get(property);
- if (isReverseProperty(property))
- return property.substring(1);
- else return "!" + property;
- }
- public static NameValue reverseProperty(Value value) {
- if (!(value instanceof NameValue))
- throw new RuntimeException("Cannot call reverseProperty on " + value);
- return new NameValue(reverseProperty(((NameValue) value).id));
- }
-
-
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CatSizeBound.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CatSizeBound.java
deleted file mode 100644
index 4c3e0e2333..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CatSizeBound.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.*;
-
-import fig.basic.*;
-
-/**
- * Given the maximum formula size in a floating grammar, compute the maximum size
- * that each floating grammar category can have.
- *
- * For example, if the grammar looks like this:
- * $ROOT -> $A | $A $B
- * $A -> $C $A
- * $B -> $C
- * $C -> $D $B | nothing
- * ...
- * and the maximum formula size (for $ROOT) is 10, then the maximum formula sizes for
- * $A, $B, $C and $D are 9, 9, 8, and 7, respectively.
- *
- * The bound is = maxFormulaSize - (shortest distance from $ROOT to cat)
- *
- * @author ppasupat
- */
-public class CatSizeBound {
- public static class Options {
- @Option(gloss = "verbosity") public int verbose = 0;
- }
- public static Options opts = new Options();
-
- private final int maxFormulaSize;
- private final Map bound = new HashMap<>();
-
- public CatSizeBound(int maxFormulaSize, Grammar grammar) {
- this(maxFormulaSize, grammar.getRules());
- }
-
- public CatSizeBound(int maxFormulaSize, List rules) {
- this.maxFormulaSize = maxFormulaSize;
- if (!FloatingParser.opts.useSizeInsteadOfDepth) {
- LogInfo.warnings("Currently CatSizeBound is usable only when useSizeInsteadOfDepth = true.");
- return;
- }
- // Construct graph
- Map> graph = new HashMap<>();
- for (Rule rule : rules) {
- if (!Rule.isCat(rule.lhs))
- throw new RuntimeException("Non-cat found in LHS of rule " + rule);
- for (String rhsCat : rule.rhs) {
- if (Rule.isCat(rhsCat))
- MapUtils.addToSet(graph, rule.lhs, rhsCat);
- }
- }
- // Breadth first search
- bound.put(Rule.rootCat, maxFormulaSize);
- Queue queue = new ArrayDeque<>();
- queue.add(Rule.rootCat);
- while (!queue.isEmpty()) {
- String cat = queue.remove();
- if (!graph.containsKey(cat)) continue;
- for (String rhsCat : graph.get(cat)) {
- if (bound.containsKey(rhsCat)) continue;
- bound.put(rhsCat, bound.get(cat) - 1);
- queue.add(rhsCat);
- }
- }
- if (opts.verbose >= 1) {
- LogInfo.begin_track("CatSizeBound: distances");
- for (Map.Entry entry : bound.entrySet())
- LogInfo.logs("%25s : %2d", entry.getKey(), entry.getValue());
- LogInfo.end_track();
- }
- }
-
- public int getBound(String cat) {
- return bound.getOrDefault(cat, maxFormulaSize);
- }
-
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ChartParserState.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ChartParserState.java
deleted file mode 100644
index c4708ba28b..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ChartParserState.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import fig.basic.LogInfo;
-import fig.basic.MapUtils;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Actually does the parsing. Main method is infer(), whose job is to fill in
- *
- * @author Roy Frostig
- * @author Percy Liang
- */
-public abstract class ChartParserState extends ParserState {
- // cell (start, end, category) -> list of derivations (sorted by decreasing score) [beam]
- protected final Map>[][] chart;
-
- // For visualizing how chart is filled
- protected List chartFillingList = new ArrayList<>();
-
- protected String[][] phrases; // the phrases in the example
-
- @SuppressWarnings({ "unchecked" })
- public ChartParserState(Parser parser, Params params, Example ex, boolean computeExpectedCounts) {
- super(parser, params, ex, computeExpectedCounts);
-
- // Initialize the chart.
- this.chart = (HashMap>[][])
- Array.newInstance(HashMap.class, numTokens, numTokens + 1);
- this.phrases = new String[numTokens][numTokens + 1];
-
- for (int start = 0; start < numTokens; start++) {
- StringBuilder sb = new StringBuilder();
- for (int end = start + 1; end <= numTokens; end++) {
- if (end - start > 1)
- sb.append(' ');
- sb.append(this.ex.languageInfo.tokens.get(end - 1));
- phrases[start][end] = sb.toString();
- chart[start][end] = new HashMap<>();
- }
- }
- }
-
- public void clearChart() {
- for (int start = 0; start < numTokens; start++) {
- for (int end = start + 1; end <= numTokens; end++) {
- chart[start][end].clear();
- }
- }
- }
-
- // Call this method in infer()
- protected void setPredDerivations() {
- predDerivations.clear();
- predDerivations.addAll(MapUtils.get(chart[0][numTokens], Rule.rootCat, Derivation.emptyList));
- }
-
- private void visualizeChart() {
- for (int len = 1; len <= numTokens; ++len) {
- for (int i = 0; i + len <= numTokens; ++i) {
- for (String cat : chart[i][i + len].keySet()) {
- List derivations = chart[i][i + len].get(cat);
- for (Derivation deriv : derivations) {
- LogInfo.logs("ParserState.visualize: %s(%s:%s): %s", cat, i, i + len, deriv);
- }
- }
- }
- }
- }
-
- protected void addToChart(Derivation deriv) {
- if (parser.verbose(3)) LogInfo.logs("addToChart %s: %s", deriv.cat, deriv);
-
- if (Parser.opts.pruneErrorValues && deriv.value instanceof ErrorValue) return;
-
- List derivations = chart[deriv.start][deriv.end].get(deriv.cat);
- if (chart[deriv.start][deriv.end].get(deriv.cat) == null)
- chart[deriv.start][deriv.end].put(deriv.cat, derivations = new ArrayList<>());
- derivations.add(deriv);
- totalGeneratedDerivs++;
-
- if (Parser.opts.visualizeChartFilling) {
- chartFillingList.add(new CatSpan(deriv.start, deriv.end, deriv.cat));
- }
- }
-
- public Map>[][] getChart() {
- return chart;
- }
-
- // TODO(joberant): move to visualization utility class
- public static class CatSpan {
- @JsonProperty
- public final int start;
- @JsonProperty public final int end;
- @JsonProperty public final String cat;
-
- @JsonCreator
- public CatSpan(@JsonProperty("start") int start, @JsonProperty("end") int end,
- @JsonProperty("cat") String cat) {
- this.start = start;
- this.end = end;
- this.cat = cat;
- }
- }
-
- public static class ChartFillingData {
- @JsonProperty public final String id;
- @JsonProperty public final String utterance;
- @JsonProperty public final int numOfTokens;
- @JsonProperty public final List catSpans;
-
- @JsonCreator
- public ChartFillingData(@JsonProperty("id") String id, @JsonProperty("catspans") List catSpans,
- @JsonProperty("utterance") String utterance, @JsonProperty("numOfTokens") int numOfTokens) {
- this.id = id;
- this.utterance = utterance;
- this.numOfTokens = numOfTokens;
- this.catSpans = catSpans;
- }
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ChildDerivationsGroup.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ChildDerivationsGroup.java
deleted file mode 100644
index c6ca9e0e92..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ChildDerivationsGroup.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.List;
-
-/**
- * A group containing one or two lists of potential child derivations.
- *
- * The motivation is to group potential child derivations based on type compatibility.
- * For example, when building (and __ __), considering all pairs of derivations
- * is time-wasting since a lot of pairs don't type-check. We instead group
- * derivations by type, and only apply the rule to the pairs that type-check.
- *
- * This idea also extends to one-argument rules. For example, for (sum ___),
- * we should only look at child derivations with number type.
- *
- * During parsing, for each DerivationGroup:
- * - For a one-argument rule (derivations2 == null):
- * Apply the rule on all derivations in derivations1
- * - For a two-argument rule (derivations2 != null):
- * Apply the rule to all pairs (d1, d2) where d1 is in derivations1 and d2 is in derivations2
- *
- * @author ppasupat
- */
-public class ChildDerivationsGroup {
- public final List derivations1, derivations2;
-
- public ChildDerivationsGroup(List derivations1) {
- this.derivations1 = derivations1;
- this.derivations2 = null;
- }
-
- public ChildDerivationsGroup(List derivations1, List derivations2) {
- this.derivations1 = derivations1;
- this.derivations2 = derivations2;
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CoarseParser.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CoarseParser.java
deleted file mode 100644
index 908fcf79f1..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/CoarseParser.java
+++ /dev/null
@@ -1,284 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.google.common.base.Joiner;
-import fig.basic.LogInfo;
-import fig.basic.MapUtils;
-import fig.basic.Pair;
-import fig.basic.StopWatch;
-
-import java.lang.reflect.Array;
-import java.util.*;
-
-/**
- * Parser that only has information on what categories can parse what spans
- * Does not hold backpointers for getting full parse, only reachability information
- * Important: assumes that the grammar is binary
- * Independent from the Parser code and therefore there is duplicate code (traverse(), keepTopDownReachable())
- * @author jonathanberant
- */
-public class CoarseParser {
-
- public final Grammar grammar;
- private Map, Set> rhsToLhsMap;
- ArrayList catUnaryRules; // Unary rules with category on RHS
- Map> terminalsToRulesList = new HashMap<>();
-
- public CoarseParser(Grammar grammar) {
- this.grammar = grammar;
- catUnaryRules = new ArrayList<>();
- rhsToLhsMap = new HashMap<>();
-
- Map> graph = new HashMap<>(); // Node from LHS to list of rules
- for (Rule rule : grammar.rules) {
- if (rule.rhs.size() > 2)
- throw new RuntimeException("We assume that the grammar is binarized, rule: " + rule);
- if (rule.isCatUnary())
- MapUtils.addToList(graph, rule.lhs, rule);
- else if (rule.rhs.size() == 2) { // binary grammar
- MapUtils.addToSet(rhsToLhsMap, Pair.newPair(rule.rhs.get(0), rule.rhs.get(1)), rule.lhs);
- } else {
- assert rule.isRhsTerminals();
- MapUtils.addToList(terminalsToRulesList, Joiner.on(' ').join(rule.rhs), rule);
- }
- }
- // Topologically sort catUnaryRules so that B->C occurs before A->B
- Map done = new HashMap<>();
- for (String node : graph.keySet())
- traverse(catUnaryRules, node, graph, done);
- LogInfo.logs("Coarse parser: %d catUnaryRules (sorted), %d nonCatUnaryRules", catUnaryRules.size(), grammar.rules.size() - catUnaryRules.size());
- }
-
- /** Helper function for transitive closure of unary rules. */
- private void traverse(List catUnaryRules,
- String node,
- Map> graph,
- Map done) {
- Boolean d = done.get(node);
- if (Boolean.TRUE.equals(d)) return;
- if (Boolean.FALSE.equals(d))
- throw new RuntimeException("Found cycle of unaries involving " + node);
- done.put(node, false);
- for (Rule rule : MapUtils.getList(graph, node)) {
- traverse(catUnaryRules, rule.rhs.get(0), graph, done);
- catUnaryRules.add(rule);
- }
- done.put(node, true);
- }
-
- public CoarseParserState getCoarsePrunedChart(Example ex) {
- CoarseParserState res = new CoarseParserState(ex, this);
- res.infer();
- return res;
- }
-
- class CoarseParserState {
-
- private Map>[][] chart;
- public final Example example;
- public final CoarseParser parser;
- private int numTokens;
- private long time;
- private String[][] phrases;
-
-
-
- @SuppressWarnings({ "unchecked" })
- public CoarseParserState(Example example, CoarseParser parser) {
- this.example = example;
- this.parser = parser;
- numTokens = example.numTokens();
- // Initialize the chart.
- this.chart = (HashMap>[][])
- Array.newInstance(
- HashMap.class,
- numTokens, numTokens + 1);
- phrases = new String[numTokens][numTokens + 1];
-
- for (int start = 0; start < numTokens; start++) {
- StringBuilder sb = new StringBuilder();
- for (int end = start + 1; end <= numTokens; end++) {
- if (end - start > 1)
- sb.append(' ');
- sb.append(example.languageInfo.tokens.get(end - 1));
- phrases[start][end] = sb.toString();
- chart[start][end] = new HashMap<>();
- }
- }
- }
-
- public long getCoarseParseTime() { return time; }
-
- public void infer() {
-
- StopWatch watch = new StopWatch();
- watch.start();
- // parse with rules with tokens or RHS
- parseTokensAndPhrases();
- // complete bottom up parsing
- for (int len = 1; len <= numTokens; len++)
- for (int i = 0; i + len <= numTokens; i++)
- build(i, i + len);
- // prune away things that are not reachable from the top
- keepTopDownReachable();
- watch.stop();
- time = watch.getCurrTimeLong();
- }
-
- public boolean coarseAllows(String cat, int start, int end) {
- return chart[start][end].containsKey(cat);
- }
-
- private void build(int start, int end) {
- handleBinaryRules(start, end);
- handleUnaryRules(start, end);
- }
-
- private void parseTokensAndPhrases() {
- for (int i = 0; i < numTokens; ++i) {
- addToChart(Rule.tokenCat, i, i + 1);
- addToChart(Rule.lemmaTokenCat, i, i + 1);
- }
- for (int i = 0; i < numTokens; i++) {
- for (int j = i + 1; j <= numTokens; j++) {
- addToChart(Rule.phraseCat, i, j);
- addToChart(Rule.lemmaPhraseCat, i, j);
- }
- }
- }
-
- private void addToChart(String cat, int start, int end) {
- if (Parser.opts.verbose >= 5)
- LogInfo.logs("Adding to chart %s(%s,%s)", cat, start, end);
- MapUtils.putIfAbsent(chart[start][end], cat, new ArrayList());
- }
-
- private void addToChart(String parentCat, String childCat, int start, int end) {
- if (Parser.opts.verbose >= 5)
- LogInfo.logs("Adding to chart %s(%s,%s)-->%s(%s,%s)", parentCat, start, end, childCat, start, end);
- MapUtils.addToList(chart[start][end], parentCat, new CategorySpan(childCat, start, end)); }
-
- private void addToChart(String parentCat, String leftCat, String rightCat, int start, int i, int end) {
- if (Parser.opts.verbose >= 5)
- LogInfo.logs("Adding to chart %s(%s,%s)-->%s(%s,%s) %s(%s,%s)", parentCat, start, end, leftCat, start, i, rightCat, i, end);
- MapUtils.addToList(chart[start][end], parentCat, new CategorySpan(leftCat, start, i));
- MapUtils.addToList(chart[start][end], parentCat, new CategorySpan(rightCat, i, end));
- }
-
- private void handleBinaryRules(int start, int end) {
- for (int i = start + 1; i < end; ++i) {
- List left = new ArrayList<>(chart[start][i].keySet());
- List right = new ArrayList<>(chart[i][end].keySet());
- if (i - start == 1) left.add(phrases[start][i]); // handle single terminal
- if (end - i == 1) right.add(phrases[i][end]); // handle single terminal
-
- for (String l : left) {
- for (String r : right) {
- Set parentCats = rhsToLhsMap.get(Pair.newPair(l, r));
-
- if (parentCats != null) {
- for (String parentCat : parentCats) {
- addToChart(parentCat, l, r, start, i, end);
- }
- }
- }
- }
- }
- }
-
- private void handleUnaryRules(int start, int end) {
-
- // terminals on RHS
- for (Rule rule : MapUtils.get(terminalsToRulesList, phrases[start][end], Collections.emptyList())) {
- addToChart(rule.lhs, start, end);
- }
- // catUnaryRules
- for (Rule rule : parser.catUnaryRules) {
- String rhsCat = rule.rhs.get(0);
- if (chart[start][end].containsKey(rhsCat)) {
- addToChart(rule.lhs, rhsCat, start, end);
- }
- }
- }
-
- public void keepTopDownReachable() {
- if (numTokens == 0) return;
-
- Set reachable = new HashSet();
- collectReachable(reachable, new CategorySpan(Rule.rootCat, 0, numTokens));
-
- // Remove all derivations associated with (cat, start, end) that aren't reachable.
- for (int start = 0; start < numTokens; start++) {
- for (int end = start + 1; end <= numTokens; end++) {
- List toRemoveCats = new LinkedList();
- for (String cat : chart[start][end].keySet()) {
- if (!reachable.contains(new CategorySpan(cat, start, end))) {
- toRemoveCats.add(cat);
- }
- }
- Collections.sort(toRemoveCats);
- for (String cat : toRemoveCats) {
- if (Parser.opts.verbose >= 5)
- LogInfo.logs("Pruning chart %s(%s,%s)", cat, start, end);
- chart[start][end].remove(cat);
- }
- }
- }
- }
-
- private void collectReachable(Set reachable, CategorySpan catSpan) {
- if (reachable.contains(catSpan))
- return;
- if (!chart[catSpan.start][catSpan.end].containsKey(catSpan.cat)) {
- // This should only happen for the root when there are no parses.
- return;
- }
- reachable.add(catSpan);
- for (CategorySpan childCatSpan : chart[catSpan.start][catSpan.end].get(catSpan.cat)) {
- collectReachable(reachable, childCatSpan);
- }
- }
- }
-
- class CategorySpan {
- public final String cat;
- public final int start;
- public final int end;
-
- public CategorySpan(String cat, int start, int end) {
- this.cat = cat;
- this.start = start;
- this.end = end;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cat == null) ? 0 : cat.hashCode());
- result = prime * result + end;
- result = prime * result + start;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- CategorySpan other = (CategorySpan) obj;
- if (cat == null) {
- if (other.cat != null)
- return false;
- } else if (!cat.equals(other.cat))
- return false;
- if (end != other.end)
- return false;
- if (start != other.start)
- return false;
- return true;
- }
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Colorizer.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Colorizer.java
deleted file mode 100644
index 62291c2bd8..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Colorizer.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-/**
- * Tools for colorizing output to console so easier to read
- *
- * @author Ziang Xie
- */
-
-public class Colorizer {
-
- public Colorizer() { }
-
- public String colorize(String s, String color) {
- String cp = "";
-
- // NOTE JDK 7+ feature
- switch (color) {
- case "black":
- cp = "\u001B[30m";
- break;
- case "red":
- cp = "\u001B[31m";
- break;
- case "green":
- cp = "\u001B[32m";
- break;
- case "yellow":
- cp = "\u001B[33m";
- break;
- case "blue":
- cp = "\u001B[34m";
- break;
- case "purple":
- cp = "\u001B[35m";
- break;
- case "cyan":
- cp = "\u001B[36m";
- break;
- case "white":
- cp = "\u001B[37m";
- break;
- default:
- throw new RuntimeException("Invalid color: " + color);
- }
-
- if (cp.equals(""))
- return s;
- return cp + s + "\u001B[0m";
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ConcatFn.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ConcatFn.java
deleted file mode 100644
index 39202e5a7c..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ConcatFn.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import fig.basic.LispTree;
-/**
- * Takes two strings and returns their concatenation.
- *
- * @author Percy Liang
- */
-public class ConcatFn extends SemanticFn {
- String delim;
-
- public ConcatFn() { }
-
- public ConcatFn(String delim) {
- this.delim = delim;
- }
-
- public void init(LispTree tree) {
- super.init(tree);
- delim = tree.child(1).value;
- }
-
- public DerivationStream call(Example ex, final Callable c) {
- return new SingleDerivationStream() {
- @Override
- public Derivation createDerivation() {
- StringBuilder out = new StringBuilder();
- for (int i = 0; i < c.getChildren().size(); i++) {
- if (i > 0) out.append(delim);
- out.append(c.childStringValue(i));
- }
- return new Derivation.Builder()
- .withCallable(c)
- .withStringFormulaFrom(out.toString())
- .createDerivation();
- }
- };
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ConstantFn.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ConstantFn.java
deleted file mode 100644
index c719d7a80d..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ConstantFn.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import fig.basic.LispTree;
-
-/**
- * Just returns a fixed logical formula.
- *
- * @author Percy Liang
- */
-public class ConstantFn extends SemanticFn {
- Formula formula; // Formula to return
- SemType type;
-
- public ConstantFn() { }
-
- public ConstantFn(Formula formula) {
- init(LispTree.proto.newList("ConstantFn", formula.toLispTree()));
- }
-
- public void init(LispTree tree) {
- super.init(tree);
- this.formula = Formulas.fromLispTree(tree.child(1));
- if (2 < tree.children.size())
- this.type = SemType.fromLispTree(tree.child(2));
- else {
- this.type = TypeInference.inferType(formula);
- }
- if (!this.type.isValid())
- throw new RuntimeException("ConstantFn: " + formula + " does not type check");
- }
-
- public DerivationStream call(final Example ex, final Callable c) {
- return new SingleDerivationStream() {
- @Override
- public Derivation createDerivation() {
- Derivation res = new Derivation.Builder()
- .withCallable(c)
- .formula(formula)
- .type(type)
- .createDerivation();
- // don't generate feature if it is not grounded to a string
- if (FeatureExtractor.containsDomain("constant") && c.getStart() != -1)
- res.addFeature("constant", ex.phraseString(c.getStart(), c.getEnd()) + " --- " + formula.toString());
- return res;
- }
- };
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ContextFn.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ContextFn.java
deleted file mode 100644
index c8e5f11e7b..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ContextFn.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import java.util.*;
-import fig.basic.*;
-
-/**
- * Produces predicates (like LexiconFn) but do it from the logical forms
- * in the context (inspects the ContextValue of the example).
- *
- * Takes depth, restrictType, and forbiddenTypes arguments allowing you
- * to specify the depth/size and type of (formula) subtrees that you want to
- * extract from the context.
- *
- * ONLY USE WITH TYPES!!
- *
- * E.g.,
- *
- * (rule $X (context) (ContextFn (depth 0) (type fb:type.any))
- * would extract any unary/entity.
- *
- * (rule $X (context) (ContextFn (depth 1) (type (-> fb:type.any
- * fb:type.any)) (forbidden (-> fb:type.any fb:type.something)) would
- * extract all binaries except those with arg1 of type fb:type.something
- *
- * @author William Hamilton
- */
-// TODO(Will): Reintegrate useful functionality from old implementation.
-public class ContextFn extends SemanticFn {
- // the depth/size of subtrees to extract
- private int depth;
- // the type that you want to extract
- private SemType restrictType = SemType.topType;
-
- // set of types to not extract (overrides restrictType).
- // For example, if restrict type is very general (e.g., (-> type.any type.any))
- // and you don't want some specific subtype (e.g., (-> type.something type.any))
- // then you would say specify (forbidden (-> type.something type.any))
- // and all subtypes of (-> type.any type.any) would be permissible
- // except the forbidden one(s).
- private Set forbiddenTypes = new HashSet();
-
- public void init(LispTree tree) {
- super.init(tree);
- for (int i = 1; i < tree.children.size(); i++) {
- LispTree arg = tree.child(i);
- if ("type".equals(arg.child(0).value)) {
- restrictType = SemType.fromLispTree(arg.child(1));
- } else if ("depth".equals(arg.child(0).value)) {
- depth = Integer.parseInt(arg.child(1).value);
- } else if ("forbidden".equals(arg.child(0).value)) {
- forbiddenTypes.add(SemType.fromLispTree(arg.child(1)));
- } else {
- throw new RuntimeException("Unknown argument: " + arg);
- }
- }
- }
-
- public DerivationStream call(final Example ex, final Callable c) {
- return new MultipleDerivationStream() {
- int index = 0;
- List formulas;
-
- public Derivation createDerivation() {
- if (ex.context == null) return null;
-
- if (formulas == null) {
- formulas = new ArrayList();
- for (int i = ex.context.exchanges.size() - 1; i >= 0; i--) {
- ContextValue.Exchange e = ex.context.exchanges.get(i);
- extractFormulas(e.formula.toLispTree());
- }
- }
- if (index >= formulas.size()) return null;
- Formula formula = formulas.get(index++);
- for (SemType forbiddenType : forbiddenTypes) {
- if (TypeInference.inferType(formula).meet(forbiddenType).isValid())
- return null;
- }
- return new Derivation.Builder()
- .withCallable(c)
- .formula(formula)
- .type(TypeInference.inferType(formula))
- .createDerivation();
- }
-
- private void addFormula(Formula formula) {
- if (formulas.contains(formula))
- return;
- formulas.add(formula);
- }
-
- // Extract from the logical form.
- private void extractFormulas(LispTree formula) {
- if (correctDepth(formula, 0) && typeCheck(formula)) {
- addFormula(Formulas.fromLispTree(formula));
- }
- if (formula.isLeaf())
- return;
- for (LispTree child : formula.children)
- extractFormulas(child);
- }
-
- private boolean correctDepth(LispTree formula, int currentLevel) {
- if (formula.isLeaf()) {
- return currentLevel == depth;
- } else {
- boolean isCorrect = true;
- for (LispTree child : formula.children)
- isCorrect = isCorrect && correctDepth(child, currentLevel + 1);
- return isCorrect;
- }
- }
-
- private boolean typeCheck(LispTree treeFormula) {
- Formula formula = Formulas.fromLispTree(treeFormula);
- SemType type = TypeInference.inferType(formula);
- type = restrictType.meet(type);
- return type.isValid();
- }
-
- };
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ContextValue.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ContextValue.java
deleted file mode 100644
index bf7238347d..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/ContextValue.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonValue;
-import fig.basic.LispTree;
-import java.util.*;
-
-/**
- * Represents the discourse context (time, place, history of exchanges).
- * This is part of an Example and used by ContextFn.
- *
- * @author Percy Liang
- */
-public class ContextValue extends Value {
- // A single exchange between the user and the system
- // Note: we are not storing the entire derivation right now.
- public static class Exchange {
- public final String utterance;
- public final Formula formula;
- public final Value value;
- public Exchange(String utterance, Formula formula, Value value) {
- this.utterance = utterance;
- this.formula = formula;
- this.value = value;
- }
- public Exchange(LispTree tree) {
- utterance = tree.child(1).value;
- formula = Formulas.fromLispTree(tree.child(2));
- value = Values.fromLispTree(tree.child(3));
- }
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild("exchange");
- tree.addChild(utterance);
- tree.addChild(formula.toLispTree());
- tree.addChild(value.toLispTree());
- return tree;
- }
- @Override public String toString() { return toLispTree().toString(); }
- }
-
- public final String user;
- public final DateValue date;
- public final List exchanges; // List of recent exchanges with the user
- public final KnowledgeGraph graph; // Mini-knowledge graph that captures the context
-
- public ContextValue withDate(DateValue newDate) {
- return new ContextValue(user, newDate, exchanges, graph);
- }
-
- public ContextValue withNewExchange(List newExchanges) {
- return new ContextValue(user, date, newExchanges, graph);
- }
-
- public ContextValue withGraph(KnowledgeGraph newGraph) {
- return new ContextValue(user, date, exchanges, newGraph);
- }
-
- public ContextValue(String user, DateValue date, List exchanges, KnowledgeGraph graph) {
- this.user = user;
- this.date = date;
- this.exchanges = exchanges;
- this.graph = graph;
- }
-
- public ContextValue(String user, DateValue date, List exchanges) {
- this(user, date, exchanges, null);
- }
-
- public ContextValue(KnowledgeGraph graph) {
- this(null, null, new ArrayList(), graph);
- }
-
- // Example:
- // (context (user pliang)
- // (date 2014 4 20)
- // (exchange "when was chopin born" (!fb:people.person.date_of_birth fb:en.frederic_chopin) (date 1810 2 22))
- // (graph NaiveKnowledgeGraph ((string Obama) (string "born in") (string Hawaii)) ...))
- public ContextValue(LispTree tree) {
- String user = null;
- DateValue date = null;
- KnowledgeGraph graph = null;
- exchanges = new ArrayList();
- for (int i = 1; i < tree.children.size(); i++) {
- String key = tree.child(i).child(0).value;
- if (key.equals("user")) {
- user = tree.child(i).child(1).value;
- } else if (key.equals("date")) {
- date = new DateValue(tree.child(i));
- } else if (key.equals("graph")) {
- graph = KnowledgeGraph.fromLispTree(tree.child(i));
- } else if (key.equals("exchange")) {
- exchanges.add(new Exchange(tree.child(i)));
- } else {
- throw new RuntimeException("Invalid: " + tree.child(i));
- }
- }
- this.user = user;
- this.date = date;
- this.graph = graph;
- }
-
- public LispTree toLispTree() {
- LispTree tree = LispTree.proto.newList();
- tree.addChild("context");
- if (user != null)
- tree.addChild(LispTree.proto.newList("user", user));
- if (date != null)
- tree.addChild(date.toLispTree());
- // When logging examples, logging the entire graph takes too much screen space.
- // I don't think that we ever deserialize a graph from a serialized context,
- // so this should be fine.
- if (graph != null)
- tree.addChild(graph.toShortLispTree());
- for (Exchange e : exchanges)
- tree.addChild(LispTree.proto.newList("exchange", e.toLispTree()));
- return tree;
- }
-
- @Override public int hashCode() {
- int hash = 0x7ed55d16;
- hash = hash * 0xd3a2646c + user.hashCode();
- hash = hash * 0xd3a2646c + date.hashCode();
- hash = hash * 0xd3a2646c + exchanges.hashCode();
- hash = hash * 0xd3a2646c + graph.hashCode();
- return hash;
- }
-
- @Override public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- ContextValue that = (ContextValue) o;
- if (!this.user.equals(that.user)) return false;
- if (!this.date.equals(that.date)) return false;
- if (!this.exchanges.equals(that.exchanges)) return false;
- if (!this.graph.equals(that.graph)) return false;
- return true;
- }
-
- @JsonValue
- public String toString() { return toLispTree().toString(); }
-
- @JsonCreator
- public static ContextValue fromString(String str) {
- return new ContextValue(LispTree.proto.parseFromString(str));
- }
-}
diff --git a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Dataset.java b/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Dataset.java
deleted file mode 100644
index 674a3113f9..0000000000
--- a/examples/lassie/sempre/src/edu/stanford/nlp/sempre/Dataset.java
+++ /dev/null
@@ -1,283 +0,0 @@
-package edu.stanford.nlp.sempre;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.google.common.collect.Lists;
-
-import fig.basic.*;
-import fig.exec.Execution;
-import fig.prob.SampleUtils;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * A dataset contains a set of examples, which are keyed by group (e.g., train,
- * dev, test).
- *
- * @author Percy Liang
- */
-public class Dataset {
- public static class Options {
- @Option(gloss = "Paths to read input files (format: :)")
- public ArrayList> inPaths = new ArrayList>();
- @Option(gloss = "Maximum number of examples to read")
- public ArrayList> maxExamples = new ArrayList>();
-
- // Training file gets split into:
- // | trainFrac --> | | <-- devFrac |
- @Option(gloss = "Fraction of trainExamples (from the beginning) to keep for training")
- public double trainFrac = 1;
- @Option(gloss = "Fraction of trainExamples (from the end) to keep for development")
- public double devFrac = 0;
- @Option(gloss = "Used to randomly divide training examples")
- public Random splitRandom = new Random(1);
- @Option(gloss = "whether to split dev from train")
- public boolean splitDevFromTrain = true;
-
- @Option(gloss = "Only keep examples which have at most this number of tokens")
- public int maxTokens = Integer.MAX_VALUE;
-
- @Option(gloss = "Path to a knowledge graph that will be uploaded as global context")
- public String globalGraphPath;
- }
-
- public static Options opts = new Options();
-
- // Group id -> examples in that group
- private LinkedHashMap> allExamples = new LinkedHashMap>();
-
- // General statistics about the examples.
- private final HashSet tokenTypes = new HashSet();
- private final StatFig numTokensFig = new StatFig(); // For each example, number of tokens
-
- public Set groups() { return allExamples.keySet(); }
- public List examples(String group) { return allExamples.get(group); }
-
- /** For JSON. */
- static class GroupInfo {
- @JsonProperty final String group;
- @JsonProperty final List examples;
- String path; // Optional, used if this was read from a path.
- @JsonCreator
- public GroupInfo(@JsonProperty("group") String group,
- @JsonProperty("examples") List examples) {
- this.group = group;
- this.examples = examples;
- }
- }
-
- /** For JSON. */
- @JsonProperty("groups")
- public List getAllGroupInfos() {
- List all = Lists.newArrayList();
- for (Map.Entry> entry : allExamples.entrySet())
- all.add(new GroupInfo(entry.getKey(), entry.getValue()));
- return all;
- }
-
- /** For JSON. */
- // Allows us to creates dataset from arbitrary JSON, not requiring a
- // path from which to read.
- @JsonCreator
- public static Dataset fromGroupInfos(@JsonProperty("groups") List groups) {
- Dataset d = new Dataset();
- d.readFromGroupInfos(groups);
- return d;
- }
-
- public void read() {
- readFromPathPairs(opts.inPaths);
- }
-
- public void readFromPathPairs(List> pathPairs) {
- // Try to detect whether we need JSON.
- for (Pair pathPair : pathPairs) {
- if (pathPair.getSecond().endsWith(".json")) {
- readJsonFromPathPairs(pathPairs);
- return;
- }
- }
- readLispTreeFromPathPairs(pathPairs);
- updateGlobalContext();
- }
-
- private void updateGlobalContext() {
- if (opts.globalGraphPath != null) {
- KnowledgeGraph graph = NaiveKnowledgeGraph.fromFile(opts.globalGraphPath);
- for (String group : allExamples.keySet()) {
- for (Example ex : allExamples.get(group)) {
- ex.setContext(new ContextValue(graph));
- }
- }
- }
- }
-
-
- private void readJsonFromPathPairs(List> pathPairs) {
- List groups = Lists.newArrayListWithCapacity(pathPairs.size());
- for (Pair pathPair : pathPairs) {
- String group = pathPair.getFirst();
- String path = pathPair.getSecond();
- List examples = Json.readValueHard(
- IOUtils.openInHard(path),
- new TypeReference