Commits

Sébastien Ferré committed 0025520

Replacement and extension of AP by NPQ.

Comments (0)

Files changed (2)

 	  "be"; "belong"; "belongs"; "between"; "by";
 	  "concat"; "count";
 	  "decreasing"; "defined"; "describe"; "different"; "do"; "does";
-	  "else"; "equal"; "earlier"; "earliest"; "every"; "exactly"; "exist"; "exists";
+	  "else"; "equal"; "each"; "earlier"; "earliest"; "every"; "exactly"; "exist"; "exists";
 	  "first"; "for"; "from";
 	  "graph"; "give"; "greater"; "greatest";
 	  "has"; "have"; "higher"; "highest"; "how";
       | _ = interro -> tell (whether s) ) ]
 and parse_s_whether = dcg
     [ _ = kwd "whether"; _ = ws; s = parse_s_for -> whether s
+(*
+    | _ = kwds ["return"; "list"; "give"; "give me"]; _ = ws; lxd = parse_npq_gen_and ["every"; "each"; "all"; "the"] ->
+	List.fold_right (fun (x,d) s -> which x d (fun x -> s)) lxd bool0#true_
+*)
     | s = parse_s_for -> s ]
 and parse_s_for = dcg
     [ _ = kwd "if"; _ = ws; s1 = parse_s_for; _ = [ _ = comma -> () | _ = ws; _ = kwd "then"; _ = ws -> () ];
 	(dcg [ np = parse_np_gen_atom parse_det -> (fun k1 d -> np (fun x -> k1 x d)) ]) ->
 	  e1 (fun x1 d -> d x1) ]
 and parse_np_gen_atom parse_det = dcg
-    [ np = parse_np_gen_term parse_det -> np
+    [ np = parse_np_gen_term (parse_np_gen_bool parse_det) -> np
     | "_"; x = new_var (* joker *) -> (fun d -> exists x d)
     | patt = parse_pattern; x = new_var -> (fun d -> exists x (bool1#and_ [d; patt]))
     | b = parse_b; x = new_var -> (fun d -> exists x (bool1#and_ [b; d]))
     | det = parse_det; _ = ws; x, p1 = parse_ng1 -> (fun d -> det x (init p1) d)
-    | _ = kwd "which"; _ = ws; x, p1 = parse_ng1 -> (fun d -> which x (init p1) d)
+(*    | _ = kwd "which"; _ = ws; x, p1 = parse_ng1 -> (fun d -> which x (init p1) d) *)
     | np2 = parse_np2_gen parse_det; np = parse_p2' -> (fun d -> np (fun x -> np2 x d))
-    | _ = what; x = new_var -> (fun d -> which x bool1#true_ d)
-    | _ = kwd "whose"; x = new_var; _ = ws; y, p2 = parse_ng2 ->
+    | x, d1 = parse_npq_gen_atom ["which"] -> (fun d -> which x d1 d)
+    | _ = what; x = new_var -> (* = which thing *)
+	(fun d -> which x bool1#true_ d)
+    | _ = kwd "whose"; x = new_var; _ = ws; y, p2 = parse_ng2 -> (* = the NG2 of what *)
 	(fun d ->
 	  which x bool1#true_ (fun x ->
 	    exists y (bool1#and_ [init (p2 x); d]))) ]
 (*    | _ = kwd "that"; _ = ws; s = parse_s_for -> (fun d -> that s d) ] *) (* deprecated *)
+
 and parse_np2_gen parse_det = dcg
     [ np2 = parse_bool bool2 (parse_np2_gen_expr parse_det) -> np2 ]
 and parse_np2_gen_expr parse_det = dcg
 	    e1 (fun x1 x d -> d x1) ]
 and parse_np2_gen_atom parse_det = dcg
     [ det = parse_det; _ = ws; y, p2 = parse_ng2 ->
-        (fun x d -> det y (init (p2 x)) d)
+        (fun x d -> det y (init (p2 x)) d) ]
+(*
     | _ = kwd "which"; _ = ws; y, p2 = parse_ng2 ->
 	(fun x d -> which y bool1#true_ (bool1#and_ [init (p2 x); d])) ]
-and parse_np_gen_term parse_det = dcg "np_term"
+*)
+and parse_np_gen_term parse_np = dcg "np_term"
     [ v = parse_var -> (fun d -> d (Var v))
     | s = parse_literal -> (fun d -> d (Literal s))
     | uri = parse_uri -> (fun d -> d (Uri uri))
     | _ = left_curly; f = parse_text; _ = right_curly -> (fun d -> d (graph_literal f))
     | _ = left_square;
 	( _ = right_square -> (fun d -> d nil)
-        | npl = parse_np_gen_list parse_det; _ = right_square -> npl ) ]
-and parse_np_gen_list parse_det = dcg "np_list"
-    [ np = parse_np_gen_bool parse_det;
-      ( _ = comma; npl = parse_np_gen_list parse_det ->
+        | npl = parse_np_gen_list parse_np; _ = right_square -> npl ) ]
+and parse_np_gen_list parse_np = dcg "np_list"
+    [ np = parse_np;
+      ( _ = comma; npl = parse_np_gen_list parse_np ->
 	(fun dl -> np (fun e -> npl (fun l -> dl (cons e l))))
-      | _ = bar; npl = parse_np_gen_bool parse_det ->
+      | _ = bar; npl = parse_np ->
 	(fun dl -> np (fun e -> npl (fun l -> dl (cons e l))))
       |   ->
 	(fun dl -> np (fun x -> dl (cons x nil))) )
     | "..."; x = new_var;
-      ( _ = comma; npl = parse_np_gen_list parse_det ->
+      ( _ = comma; npl = parse_np ->
 	(fun dl -> npl (fun l -> exists x (fun x -> bool0#and_ [triple x (Uri p2_sublist) l; dl x])))
-      | _ = bar; npl = parse_np_gen_bool parse_det ->
+      | _ = bar; npl = parse_np ->
 	(fun dl -> npl (fun l -> exists x (fun x -> bool0#and_ [triple x (Uri p2_sublist) l; dl x])))
       |  ->
         (fun dl -> exists x dl) ) ]
+
+and parse_npq_gen_and kwds_det = dcg
+    [ lnpq = LIST1 parse_npq_gen_expr kwds_det SEP [ _ = ws; _ = kwd "and"; _ = ws -> () ] -> lnpq ]
+and parse_npq_gen_expr kwds_det = dcg
+    [ npq = parse_npq_gen_atom kwds_det -> npq
+    | e1 = parse_expr bool0
+	(dcg [ x, d = parse_npq_gen_atom kwds_det ->
+	  (fun k0 -> bool0#and_ [d x; k0 x]) ]);
+      x = [ _ = ws; _ = kwd "as"; _ = ws; x = parse_var -> Var x | x = new_var -> x ] ->
+	x, (fun x -> e1 (fun x1 -> unify x1 x)) ]
+and parse_npq_gen_atom kwds_det = dcg
+    [ np = parse_np_gen_term (dcg [ x, d1 = parse_npq_gen_expr kwds_det -> (fun d -> exists x (bool1#and_ [d1; d])) ]); x = new_var ->
+      x, (fun x -> np (fun x1 -> unify x1 x))
+    | _ = kwds kwds_det; _ = ws;
+      ( x, p1 = parse_ng1 -> x, p1
+      | y, p2 = parse_ng2; _ = ws; _ = kwd "of"; _ = ws; np = parse_np -> (* = Det thing that is a NG2 of NP *)
+	  y, (fun y -> np (fun x -> p2 x y)) ) ]
+
 and parse_b = dcg
     [ _ = left_square; vp = OPT parse_vp ELSE bool1#true_; _ = right_square -> init vp ]
 and parse_det_unary = dcg
 	(fun y d1 d2 -> which x bool1#true_ (a_number y d1 d2)) ]
 and parse_det = dcg
     [ det = parse_det_unary -> det
-    | _ = kwd "every" -> (fun x d1 d2 -> forall x d1 d2)
-    | _ = kwd "all" -> (fun x d1 d2 -> forall x d1 d2) ]
+    | _ = kwds ["every"; "all"] -> (fun x d1 d2 -> forall x d1 d2) ]
 (*    | _ = kwd "which" -> (fun x d1 d2 -> which x d1 d2) ] *)
 and parse_np = dcg
     [ np = parse_np_gen parse_det -> np ]
         | _ = ws; op = parse_op -> (fun x -> op (fun y -> p2 x y)) )]
 *)
 and parse_vp_have = dcg
-    [ _ = kwd "which"; _ = ws; y, p2 = parse_ng2; rel_opt = parse_rel_opt ->
+    [ _ = kwd "which"; _ = ws; y, p2 = parse_ng2; rel_opt = parse_rel_opt -> (* = P2 which thing Rel? *)
 	(fun x -> which y (rel_opt None) (p2 x))
     | np2 = parse_np2; rel_opt = parse_rel_opt ->
 	(fun x -> np2 x (rel_opt None))
         (fun x1 -> det y (p2 x1) (fun y -> np (fun x2 -> p2 x2 y)))
     | _ = kwd "with"; _ = ws; np = parse_np; _ = ws; det = parse_det; _ = ws; y, p2 = parse_ng2 ->
 	(fun x1 -> np (fun x2 -> det y (p2 x1) (fun y -> p2 x2 y))) ]
+(*
 and parse_ap = dcg
     [ ap = parse_ap_atom -> ap ]
 (*
     [ _ = a_the; _ = ws;
       ( x, p1 = parse_ng1 -> x, p1
       | y, p2 = parse_ng2; op = parse_p2' -> y, (fun y -> op (fun x -> p2 x y)) ) ]
+*)
 and parse_op = dcg
     [ pp = parse_pp; _ = ws; op = parse_op -> (fun d -> pp (op d))
     | op = parse_op_bool -> op ]
 	  (fun s -> np (fun z -> prep z s))
       | det = parse_det; _ = ws; prep = parse_prep; z = parse_app_opt; rel_opt = parse_rel_opt ->
 	  (fun s -> det z (fun z -> prep z s) (rel_opt None))
-      | _ = kwd "which"; _ = ws; prep = parse_prep; z = parse_app_opt; rel_opt = parse_rel_opt ->
+      | _ = kwd "which"; _ = ws; prep = parse_prep; z = parse_app_opt; rel_opt = parse_rel_opt -> (* = at Prep which thing Rel? *)
 	  (fun s -> which z (rel_opt None) (fun z -> prep z s)) ) ]
 and parse_prep = dcg
     [ _ = kwd "graph" -> graph
       | lz,d1 = parse_per; x,d2 = parse_g'_of ->
 	lz, y, exists x (fun x -> bool0#and_ [p2 x y; d1 x; d2 x]) ) ]
 and parse_g'_of = dcg
-    [ _ = ws; _ = kwd "of"; _ = ws; x, d1 = parse_ap -> x, d1 ]
+    [ _ = ws; _ = kwd "of"; _ = ws; x, d1 = parse_npq_gen_expr ["the"] -> x, d1 ]
 and parse_per = dcg
     [ _ = ws; lap = LIST1 [ _ = kwd "per"; _ = ws; ap = parse_per_arg -> ap ] SEP comma ->
       let lz, ld = List.split lap in
 and parse_per_arg = dcg
     [ v = parse_var -> Var v, (fun y -> bool0#true_)
     | z, p2 = parse_ng2 -> z, (fun y -> p2 y z)
-    | z, d = parse_ap -> z, (fun y -> d z) ]
+    | z, d = parse_npq_gen_expr ["the"] -> z, (fun y -> d z) ]
 and parse_p1 = dcg
     [ p1 = parse_bool bool1 parse_p1_atom -> p1 ]
 and parse_p1_atom = dcg
 		   (dt [pcdata "Imperative questions"], []),
 		   (example_cell "Return the publication-s of X .",
 		    [example_cell "List all author-s of X .";
-		     example_cell "Give me the title of every publication of X ."]);
+		     example_cell "Give me the title of the publication-s of X ."]);
                    (dt [pcdata "Closed questions (ASK)"], []),
                    (example_cell "Whether X has an author that worksFor Y?",
 		    [example_cell "Has X an author that worksFor Y ?"]);