Commits

Sébastien Ferré committed 94b4ec2

Added simple comparatives (greater P2 than NP).

- ex: like 'Which city has a greater population than Rennes?'

Comments (0)

Files changed (3)

 	| _ = match "contains?" as "contain(s)" -> `Appl "contains"
 	| _ = match "match\\(es\\)?" as "match(es)" -> `Appl "REGEX"
 	| _ = match "lang-match\\(es\\)?" as "lang-match(es)" -> `Appl "langMatches" ]
-    method parse_pred2_rel : 'p = dcg
-	[ _ = kwd "equal"; _ = ws; _ = kwd "to" -> `Eq
-        | _ = kwd "different"; _ = ws; _ = kwd "from" -> `Neq
-	| _ = kwd "other"; _ = ws; _ = kwd "than" -> `Neq
-	| _ = kwds ["greater"; "higher"; "later"]; _ = ws; _ = kwd "than" -> `Gt
-	| _ = kwds ["lesser"; "lower"; "earlier"]; _ = ws; _ = kwd "than" -> `Lt
-	| _ = kwds ["greater"; "higher"; "later"]; _ = ws; _ = kwd "or"; _ = ws; _ = kwd "equal"; _ = ws; _ = kwd "to" -> `Geq
-	| _ = kwds ["lesser"; "lower"; "earlier"]; _ = ws; _ = kwd "or"; _ = ws; _ = kwd "equal"; _ = ws; _ = kwd "to" -> `Leq ]
-	(* TODO: complete with string matching *)
     method parse_func1 : 'p = dcg
 	[ _ = match "str\\(ings?\\)?" as "str(ing)" -> `Appl "str"
         | _ = match "lang\\(uages?\\)?" as "lang(uage)" -> `Appl "lang"
 let parse_pred1 = dcg [ ?ctx; op = ctx#parse_pred1 -> op ]
 let parse_func0 = dcg [ ?ctx; op = ctx#parse_func0 -> op ]
 let parse_pred2 = dcg [ ?ctx; op = ctx#parse_pred2 -> op ]
-let parse_pred2_rel = dcg [ ?ctx; op = ctx#parse_pred2_rel -> op ]
 let parse_func1 = dcg [ ?ctx; op = ctx#parse_func1 -> op ]
 let parse_addop = dcg [ ?ctx; op = ctx#parse_addop -> op ]
 let parse_mulop = dcg [ ?ctx; op = ctx#parse_mulop -> op ]
 	(fun z -> prep z s)
     | _ = at_in; _ = ws; _ = kwd "which"; _ = ws; prep = parse_prep; rel_opt = parse_rel_opt; _ = ws; s = parse_s_for ->
 	rel_opt (Some (fun z -> prep z s))
-    | p2 = parse_pred2_rel; _ = ws; op = parse_op -> init (fun x -> op (pred2 p2 x))
+    | comp = parse_comp_prefix; _ = ws; _ = parse_comp_suffix; _ = ws; op = parse_op -> init (fun x -> op (pred2 comp x))
     | _ = kwd "between"; _ = ws; op1 = parse_op; _ = ws; _ = kwd "and"; _ = ws; op2 = parse_op ->
         init (fun x -> bool0#and_ [op1 (pred2 pred2_geq x); op2 (pred2 pred2_leq x)]) ]
 and parse_vp = dcg
     | np2 = parse_np2; rel_opt = parse_rel_opt ->
 	(fun x -> np2 x (rel_opt None))
     | p2 = parse_p2; _ = ws; op = parse_op ->
-	(fun x -> op (fun y -> p2 x y)) ]
+	(fun x -> op (fun y -> p2 x y))
+    | _ = a_the; _ = ws; comp = parse_comp_prefix; _ = ws; p2 = parse_p2; _ = ws; _ = parse_comp_suffix;
+	_ = ws; np = parse_np; y = new_var; y' = new_var ->
+	  (fun x -> np (fun x' -> exists y (fun y -> exists y' (fun y' -> bool0#and_ [p2 x y; p2 x' y'; pred2 comp y y'])))) ]
+and parse_comp_prefix = dcg
+    [ _ = kwds ["same"; "equal"] -> pred2_eq
+    | _ = kwds ["other"; "different"] -> pred2_neq
+    | _ = kwds ["greater"; "higher"; "later"];
+      ( _ = ws; _ = kwd "or"; _ = ws; _ = kwd "equal" -> pred2_geq
+      |  -> pred2_gt )
+    | _ = kwds ["lesser"; "lower"; "earlier"];
+      ( _ = ws; _ = kwd "or"; _ = ws; _ = kwd "equal" -> pred2_leq
+      |  -> pred2_lt ) ]
+and parse_comp_suffix = dcg
+    [ _ = kwds ["than"; "as"; "to"; "from"] -> () ]
 and parse_vp_share = dcg
     [ det = parse_det; _ = ws; y, p2 = parse_ng2; _ = ws; _ = kwd "with"; _ = ws; np = parse_np ->
         (fun x1 -> det y (p2 x1) (fun y -> np (fun x2 -> p2 x2 y)))
 		   example_item "Who is the producer of the most Film-s ?";
 		   example_item "Which foaf:Person has foaf:givenName \"Jimmy\"@en ?";
 		   example_item "Is there a VideoGame that is 'Battle Chess' ?";
-		   example_item "Which Mountain has an dbp:elevationM greater than the dbp:elevationM of res:Nanga_Parbat ?";
+		   example_item "Which Mountain has a greater dbp:elevationM than res:Nanga_Parbat ?";
 		   example_item "Who is the author of res:Wikipedia ?";
 		   example_item "Who are the starring-s of res:Batman_Begins ?";
 		   example_item "Which Software-s have developer an Organisation whose foundationPlace is res:California ?";
 		   example_item "Who has a team whose league is res:Premier_League and has the latest birthDate ?";
 		   example_item "Who is a bandMember of 'The Prodigy' ?";
 		   example_item "Which River has the greatest dbp:length ?";
-		   example_item "Has 'Battlestar Galactica 2004' a numberOfEpisodes greater than the numberOfEpisodes of 'Battlestar Galactica 1978' ?";
+		   example_item "Has 'Battlestar Galactica 2004' a greater numberOfEpisodes than 'Battlestar Galactica 1978' ?";
 		   example_item "Which Automobile has dbp:production or dbp:assembly res:Germany or has a dbp:manufacturer that is a yago:AutomotiveCompaniesOfGermany and whose locationCountry is res:Germany ?";
 		   example_item "OUT OF SCOPE";
 		   example_item "Who has birthPlace res:Vienna and has deathPlace res:Berlin ?";
 		   example_item "What is the dbp:residence of res:Prime_Minister_of_Spain ?";
 		   example_item "Which yago:StatesOfTheUnitedStates has dbp:postalabbreviation \"MN\"@en ?";
 		   example_item "Which Song has artist res:Bruce_Springsteen and has a releaseDate between 1980-01-01 and 1990-12-31 ?";
-		   example_item "Which Film has director res:Sam_Raimi and has a releaseDate or dbp:released greater than the releaseDate of res:Army_of_Darkness ?";
+		   example_item "Which Film has director res:Sam_Raimi and has a greater releaseDate than res:Army_of_Darkness ?";
 		   example_item "What is the dbp:foundation of the dbp:brewery of res:Pilsner_Urquell ?";
 		   example_item "Who is the dbp:author of the anthem of res:Poland ?";
 		   example_item "What are the dbp:bSide-s of a thing whose musicalArtist is res:Ramones ?";