Commits

Sébastien Ferré committed 94a72d8

Improvement of the syntax and semantics of aggregations (bis).

Comments (0)

Files changed (4)

     | `Forall (f1,f2) -> `Forall (aux x f1, aux x f2)
     | f -> `Graph (x,f) in
   aux x (s args g mode)
-let aggreg op (y,d) lzp2 x args g mode =
-  let lz = List.map fst lzp2 in
-  `Aggreg (op, x, y, lz,
-	   merge (d y args g `Interrogative ::
-		  List.map (fun (z,p2) -> p2 y z args g `Interrogative) lzp2))
+let aggreg op lz y s x args g mode =
+  `Aggreg (op, x, y, lz, s args g `Interrogative)
 
 let func1_id = `Id
 let pred2_eq = `Eq
 let ifthenelse s1 s2 s3 = bool0#and_ [bool0#forall [] s1 s2; bool0#forall [] (bool0#not_ s1) s3]
 let the x d1 d2 = bool0#the [x] (d1 x) (d2 x)
 let where s1 s2 = bool0#the [] s2 s1
-let a_number y d1 d2 x = aggreg aggreg_count (y,bool1#and_ [d1;d2]) [] x
+let a_number y d1 d2 x = aggreg aggreg_count [] y (bool0#and_ [d1 y; d2 y]) x
 let modif op x args g mode = `Modif (op, x, `True)
 
 let select xs s args g mode = `Select (xs, s args g `Interrogative)
 	    -> `Appl s
 	| uri = Syntax.parse_uri -> `Appl uri ]
     method parse_aggreg : 'p = dcg
-	[ "count" -> `Appl "COUNT"
-        | "number" -> `Appl "COUNT"
-	| "min" -> `Appl "MIN"
-	| "minimum" -> `Appl "MIN"
-	| "max" -> `Appl "MAX"
-	| "maximum" -> `Appl "MAX"
-	| "sum" -> `Appl "SUM"
-	| "total" -> `Appl "SUM"
-	| "average" -> `Appl "AVG"
-	| "sample" -> `Appl "SAMPLE"
-	| "concat" -> `Appl "GROUP_CONCAT" ]
+	[ _ = kwd "count" -> `Appl "COUNT"
+        | _ = kwd "number"; _ = ws; _ = kwd "of" -> `Appl "COUNT"
+	| _ = kwds ["min"; "minimum"] -> `Appl "MIN"
+	| _ = kwds ["max"; "maximum"] -> `Appl "MAX"
+	| _ = kwds ["sum"; "total"] -> `Appl "SUM"
+	| _ = kwd "average" -> `Appl "AVG"
+	| _ = kwd "sample" -> `Appl "SAMPLE"
+	| _ = kwd "concat" -> `Appl "GROUP_CONCAT" ]
     method parse_modif : 'p = dcg
 	[ "decreasing" -> `Mod ("DESC",0,-1)
         | "increasing" -> `Mod ("ASC",0,-1)
     [ _ = left_square; vp = OPT parse_vp ELSE bool1#true_; _ = right_square -> init vp ]
 and parse_det_unary = dcg
     [ _ = a_an;
-      ( _ = ws; x, g = parse_ngg; rel_opt = parse_rel_opt; _ = ws; _ = kwd "of" ->
-	  (fun y d1 d2 -> exists x (bool1#and_ [g (y, bool1#and_ [d1; d2]) []; rel_opt None]))
+      ( _ = ws; x, g = parse_ngg; rel_opt = parse_rel_opt ->
+	  (fun y d1 d2 -> exists x (bool1#and_ [g [] y (bool0#and_ [d1 y; d2 y]); rel_opt None]))
       |  -> (fun x d1 d2 -> exists x (bool1#and_ [d1; d2])) )
     | _ = kwd "the";
       ( _ = ws;
     | m1 = parse_modif_opt;
       ( x = parse_var; rel_opt = parse_rel_opt -> Var x, rel_opt (Some m1)
       | p1 = parse_p1; x = parse_app_opt; rel_opt = parse_rel_opt -> x, rel_opt (Some (bool1#and_ [m1; p1]))
-      | op = parse_aggreg; x = parse_app_opt; ap, lap = parse_g' -> x, bool1#and_ [m1; aggreg op ap lap] ) ]
+      | op = parse_aggreg; x = parse_app_opt; lz,y,s = parse_g' -> x, bool1#and_ [m1; aggreg op lz y s] ) ]
 and parse_ng2 = dcg
     [ m1 = parse_modif_opt; p2 = parse_p2; y = parse_app_opt -> y, (fun x y -> bool0#and_ [m1 y; p2 x y]) ]
 and parse_ngg = dcg
-    [ m1 = parse_modif_opt; op = parse_aggreg; x = parse_app_opt -> x, (fun ap lap -> bool1#and_ [m1; aggreg op ap lap]) ]
+    [ m1 = parse_modif_opt; op = parse_aggreg; x = parse_app_opt -> x, (fun lz y s -> bool1#and_ [m1; aggreg op lz y s]) ]
 and parse_modif_opt = dcg
     [ op = parse_modif; _ = ws -> modif op
     |  -> bool1#true_ ]
 and parse_p2' = dcg
     [ _ = ws; _ = kwd "of"; _ = ws; np = parse_np -> np ]
 and parse_g' = dcg
-(*
-    [ _ = ws; y, p2 = parse_ng2; _ = ws; _ = kwd "of"; _ = ws; x, d = parse_ap; lap2 = parse_per ->
-      (y, (fun y -> exists x (fun x -> bool0#and_ [p2 x y; d x]))), lap2
-*)
-    [ _ = ws; _ = kwd "of"; _ = ws; ap = parse_ap; lap2 = parse_per -> ap, lap2
-    | lap2 = parse_per; _ = ws; _ = kwd "of"; _ = ws; ap = parse_ap -> ap, lap2 ]
+    [ y,d1 = parse_g'_of; lz,d2 = parse_per -> lz, y, bool0#and_ [d1 y; d2 y]
+    | lz,d1 = parse_per; y,d2 = parse_g'_of -> lz, y, bool0#and_ [d1 y; d2 y]
+    | _ = ws; y,p1 = parse_ng1; lz,d = parse_per -> lz, y, bool0#and_ [p1 y; d y]
+    | _ = ws; y,p2 = parse_ng2;
+      ( x, d1 = parse_g'_of; lz,d2 = parse_per ->
+	lz, y, exists x (fun x -> bool0#and_ [p2 x y; d1 x; d2 x])
+      | 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 ]
 and parse_per = dcg
-    [ lap2 = LIST1 [ _ = ws; _ = kwd "per"; _ = ws; ap2 = parse_per_arg -> ap2 ] SEP comma -> lap2
-    |  -> [] ]
+    [ _ = ws; lap = LIST1 [ _ = kwd "per"; _ = ws; ap = parse_per_arg -> ap ] SEP comma ->
+      let lz, ld = List.split lap in
+      lz, bool1#and_ ld
+    |  -> [], bool1#true_ ]
 and parse_per_arg = dcg
-    [ v = parse_var -> Var v, (fun y z -> bool0#true_)
-    | z, p2 = parse_ng2 -> z, (fun y z -> p2 y z)
-    | z, d = parse_ap -> z, (fun y z -> d z) ]
+    [ 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) ]
 and parse_p1 = dcg
     [ p1 = parse_bool bool1 parse_p1_atom -> p1 ]
 and parse_p1_atom = dcg
 		     example_cell "Who is the author of the most publication-s?"]);
                    (dt [pcdata "Grouping"], []),
                    (example_cell "How many person-s have which affiliation ?",
-		    [example_cell "What is the count of the person-s per affiliation ?";
+		    [example_cell "What is the number of person-s per affiliation ?";
 		     example_cell "How many publication-s have an author that has which affiliation?";
-		     example_cell "What is the count of the publication-s ?X per the affiliation of an author of ?X ?";
-		     example_cell "What is the count per ?affil of the publication-s whose author has some affiliation ?affil ?";
+		     example_cell "What is the number of publication-s ?X per the affiliation of an author of ?X ?";
+		     example_cell "What is the number of publication-s whose author has some affiliation ?affil per ?affil ?";
+		     example_cell "What is the average number of publication-s per author ?";
 		     example_cell "What is the average per ?journal of the count per ?publi of the author-s of a publication ?publi that is publishedIn a journal ?journal ?"]);
                    (dt [pcdata "Recursion"], []),
                    (example_cell "What is a subtopic+ of InformationSystems?", []);