From e5c9ea9efcc95afee3be91e8beb754c0cb4301dc Mon Sep 17 00:00:00 2001 From: Ferruccio Guidi Date: Thu, 14 Nov 2002 17:59:46 +0000 Subject: [PATCH] added inverse switch for relation and attribute removed fun --- helm/ocaml/mathql/mQueryTLexer.mll | 1 + helm/ocaml/mathql/mQueryTParser.mly | 138 ++++++++++---------- helm/ocaml/mathql/mQueryUtil.ml | 47 ++++--- helm/ocaml/mathql/mathQL.ml | 4 +- helm/ocaml/mathql_interpreter/attribute.cmi | Bin 369 -> 0 bytes helm/ocaml/mathql_interpreter/attribute.cmx | Bin 534 -> 0 bytes helm/ocaml/mathql_interpreter/attribute.ml | 2 +- helm/ocaml/mathql_interpreter/mqint.ml | 4 +- 8 files changed, 100 insertions(+), 96 deletions(-) delete mode 100644 helm/ocaml/mathql_interpreter/attribute.cmi delete mode 100644 helm/ocaml/mathql_interpreter/attribute.cmx diff --git a/helm/ocaml/mathql/mQueryTLexer.mll b/helm/ocaml/mathql/mQueryTLexer.mll index a0884e79d..6f4fab954 100644 --- a/helm/ocaml/mathql/mQueryTLexer.mll +++ b/helm/ocaml/mathql/mQueryTLexer.mll @@ -76,6 +76,7 @@ and query_token = parse | "fun" { FUN } | "in" { IN } | "intersect" { INTER } + | "inverse" { INV } | "let" { LET } | "meet" { MEET } | "not" { NOT } diff --git a/helm/ocaml/mathql/mQueryTParser.mly b/helm/ocaml/mathql/mQueryTParser.mly index f32a41187..1228155e6 100644 --- a/helm/ocaml/mathql/mQueryTParser.mly +++ b/helm/ocaml/mathql/mQueryTParser.mly @@ -44,12 +44,12 @@ | s1 :: tl1, s2 :: tl2 -> s1 :: join tl1 tl2 in let rec an_val = function - | M.Const _ -> [] - | M.VVar _ -> [] - | M.Record (rv, _) -> [rv] - | M.Fun (_, x) -> an_val x - | M.Attribute (_, _, x) -> an_val x - | M.RefOf x -> an_set x + | M.Const _ -> [] + | M.VVar _ -> [] + | M.Record (rv, _) -> [rv] + | M.Fun (_, x) -> an_val x + | M.Attribute (_, _, _, x) -> an_val x + | M.RefOf x -> an_set x and an_boole = function | M.False -> [] | M.True -> [] @@ -61,24 +61,24 @@ | M.Meet (x, y) -> join (an_val x) (an_val y) | M.Eq (x, y) -> join (an_val x) (an_val y) and an_set = function - | M.SVar _ -> [] - | M.RVar _ -> [] - | M.Relation (_, _, x, _) -> an_set x - | M.Pattern x -> an_val x - | M.Ref x -> an_val x - | M.Union (x, y) -> join (an_set x) (an_set y) - | M.Intersect (x, y) -> join (an_set x) (an_set y) - | M.Diff (x, y) -> join (an_set x) (an_set y) - | M.LetSVar (_, x, y) -> join (an_set x) (an_set y) - | M.LetVVar (_, x, y) -> join (an_val x) (an_set y) - | M.Select (_, x, y) -> join (an_set x) (an_boole y) + | M.SVar _ -> [] + | M.RVar _ -> [] + | M.Relation (_, _, _, x, _) -> an_set x + | M.Pattern x -> an_val x + | M.Ref x -> an_val x + | M.Union (x, y) -> join (an_set x) (an_set y) + | M.Intersect (x, y) -> join (an_set x) (an_set y) + | M.Diff (x, y) -> join (an_set x) (an_set y) + | M.LetSVar (_, x, y) -> join (an_set x) (an_set y) + | M.LetVVar (_, x, y) -> join (an_val x) (an_set y) + | M.Select (_, x, y) -> join (an_set x) (an_boole y) in an_boole x %} %token ID STR %token SL IS LC RC CM SC LP RP AT PC DL FS DQ EOF - %token AND ATTR ATTRIB BE DIFF EQ EX FALSE FUN IN INTER LET MEET NOT OR - %token PAT REF REFOF REL SELECT SUB SUPER TRUE UNION WHERE + %token AND ATTR ATTRIB BE DIFF EQ EX FALSE FUN IN INTER INV LET MEET NOT + %token OR PAT REF REFOF REL SELECT SUB SUPER TRUE UNION WHERE %left DIFF WHERE REFOF %left OR UNION %left AND INTER @@ -103,33 +103,37 @@ vvar: | DL ID { $2 } ; - qstr_list: - | STR CM qstr_list { $1 :: $3 } - | STR { [$1] } + strs: + | STR CM strs { $1 :: $3 } + | STR { [$1] } ; - vvar_list: - | vvar CM vvar_list { $1 :: $3 } - | vvar { [$1] } + vvars: + | vvar CM vvars { $1 :: $3 } + | vvar { [$1] } ; - qstr_path: - | STR SL qstr_path { $1 :: $3 } - | STR { [$1] } + path: + | STR SL path { $1 :: $3 } + | STR { [$1] } ; - ref_op: + ref: | SUB { MathQL.SubOp } | SUPER { MathQL.SuperOp } | { MathQL.ExactOp } ; + inv: + | INV { true } + | { false } + ; val_exp: - | STR { MathQL.Const [$1] } - | FUN STR val_exp { MathQL.Fun ($2, $3) } - | ATTRIB ref_op qstr_path val_exp { MathQL.Attribute ($2, $3, $4) } - | rvar FS vvar { MathQL.Record ($1, $3) } - | vvar { MathQL.VVar $1 } - | LC qstr_list RC { MathQL.Const $2 } - | LC RC { MathQL.Const [] } - | REFOF set_exp { MathQL.RefOf $2 } - | LP val_exp RP { $2 } + | STR { MathQL.Const [$1] } + | FUN STR val_exp { MathQL.Fun ($2, $3) } + | ATTRIB inv ref path val_exp { MathQL.Attribute ($2, $3, $4, $5) } + | rvar FS vvar { MathQL.Record ($1, $3) } + | vvar { MathQL.VVar $1 } + | LC strs RC { MathQL.Const $2 } + | LC RC { MathQL.Const [] } + | REFOF set_exp { MathQL.RefOf $2 } + | LP val_exp RP { $2 } ; boole_exp: | TRUE { MathQL.True } @@ -144,46 +148,46 @@ | boole_exp OR boole_exp { MathQL.Or ($1, $3) } ; set_exp: - | REF val_exp { MathQL.Ref $2 } - | PAT val_exp { MathQL.Pattern $2 } - | LP set_exp RP { $2 } - | SELECT rvar IN set_exp WHERE boole_exp { MathQL.Select ($2, $4, $6) } - | REL ref_op qstr_path set_exp ATTR vvar_list { MathQL.Relation ($2, $3, $4, $6) } - | REL ref_op qstr_path set_exp { MathQL.Relation ($2, $3, $4, []) } - | svar { MathQL.SVar $1 } - | rvar { MathQL.RVar $1 } - | set_exp UNION set_exp { MathQL.Union ($1, $3) } - | set_exp INTER set_exp { MathQL.Intersect ($1, $3) } - | set_exp DIFF set_exp { MathQL.Diff ($1, $3) } - | LET svar BE set_exp IN set_exp { MathQL.LetSVar ($2, $4, $6) } - | LET vvar BE val_exp IN set_exp { MathQL.LetVVar ($2, $4, $6) } + | REF val_exp { MathQL.Ref $2 } + | PAT val_exp { MathQL.Pattern $2 } + | LP set_exp RP { $2 } + | SELECT rvar IN set_exp WHERE boole_exp { MathQL.Select ($2, $4, $6) } + | REL inv ref path set_exp ATTR vvars { MathQL.Relation ($2, $3, $4, $5, $7) } + | REL inv ref path set_exp { MathQL.Relation ($2, $3, $4, $5, []) } + | svar { MathQL.SVar $1 } + | rvar { MathQL.RVar $1 } + | set_exp UNION set_exp { MathQL.Union ($1, $3) } + | set_exp INTER set_exp { MathQL.Intersect ($1, $3) } + | set_exp DIFF set_exp { MathQL.Diff ($1, $3) } + | LET svar BE set_exp IN set_exp { MathQL.LetSVar ($2, $4, $6) } + | LET vvar BE val_exp IN set_exp { MathQL.LetVVar ($2, $4, $6) } ; query: | set_exp EOF { $1 } ; - attribute: - | STR IS qstr_list { ($1, $3) } - | STR { ($1, []) } + attr: + | STR IS strs { ($1, $3) } + | STR { ($1, []) } ; - attr_list: - | attribute SC attr_list { $1 :: $3 } - | attribute { [$1] } + attrs: + | attr SC attrs { $1 :: $3 } + | attr { [$1] } ; group: - LC attr_list RC { $2 } + LC attrs RC { $2 } ; - group_list: - | group CM group_list { $1 :: $3 } - | group { [$1] } + groups: + | group CM groups { $1 :: $3 } + | group { [$1] } ; resource: - | STR ATTR group_list { ($1, $3) } - | STR { ($1, []) } + | STR ATTR groups { ($1, $3) } + | STR { ($1, []) } ; - resource_list: - | resource SC resource_list { $1 :: $3 } - | resource { [$1] } + resources: + | resource SC resources { $1 :: $3 } + | resource { [$1] } | { [] } ; result: - | resource_list EOF { $1 } + | resources EOF { $1 } diff --git a/helm/ocaml/mathql/mQueryUtil.ml b/helm/ocaml/mathql/mQueryUtil.ml index ea1829719..09759cc45 100644 --- a/helm/ocaml/mathql/mQueryUtil.ml +++ b/helm/ocaml/mathql/mQueryUtil.ml @@ -48,46 +48,45 @@ let text_of_query x = let txt_svar sv = "%" ^ sv in let txt_rvar rv = "@" ^ rv in let txt_vvar vv = "$" ^ vv in + let txt_inv i = if i then "inverse " else "" in let txt_ref = function | M.ExactOp -> "" | M.SubOp -> "sub " | M.SuperOp -> "super " in - let txt_vvar_list l = - l - in + let txt_refpath i r p = txt_inv i ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " in let rec txt_val = function - | M.Const [s] -> txt_qstr s - | M.Const l -> "{" ^ txt_list txt_qstr ", " l ^ "}" - | M.VVar vv -> txt_vvar vv - | M.Record (rv, vv) -> txt_rvar rv ^ "." ^ txt_vvar vv - | M.Fun (s, x) -> "fun " ^ txt_qstr s ^ " " ^ txt_val x - | M.Attribute (r, p, x) -> "attribute " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_val x - | M.RefOf x -> "refof " ^ txt_set x + | M.Const [s] -> txt_qstr s + | M.Const l -> "{" ^ txt_list txt_qstr ", " l ^ "}" + | M.VVar vv -> txt_vvar vv + | M.Record (rv, vv) -> txt_rvar rv ^ "." ^ txt_vvar vv + | M.Fun (s, x) -> "fun " ^ txt_qstr s ^ " " ^ txt_val x + | M.Attribute (i, r, p, x) -> "attribute " ^ txt_refpath i r p ^ txt_val x + | M.RefOf x -> "refof " ^ txt_set x and txt_boole = function | M.False -> "false" | M.True -> "true" | M.Ex b x -> "ex " ^ txt_boole x -(* | M.Ex b x -> "ex [" ^ txt_list txt_rvar "," b ^ "] " ^ txt_boole x *) - | M.Not x -> "not " ^ txt_boole x +(* | M.Ex b x -> "ex [" ^ txt_list txt_rvar "," b ^ "] " ^ txt_boole x +*) | M.Not x -> "not " ^ txt_boole x | M.And (x, y) -> "(" ^ txt_boole x ^ " and " ^ txt_boole y ^ ")" | M.Or (x, y) -> "(" ^ txt_boole x ^ " or " ^ txt_boole y ^ ")" | M.Sub (x, y) -> "(" ^ txt_val x ^ " sub " ^ txt_val y ^ ")" | M.Meet (x, y) -> "(" ^ txt_val x ^ " meet " ^ txt_val y ^ ")" | M.Eq (x, y) -> "(" ^ txt_val x ^ " eq " ^ txt_val y ^ ")" and txt_set = function - | M.SVar sv -> txt_svar sv - | M.RVar rv -> txt_rvar rv - | M.Relation (r, p, x, []) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x - | M.Relation (r, p, x, l) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x ^ " attr " ^ txt_list txt_vvar ", " l - | M.Union (x, y) -> "(" ^ txt_set x ^ " union " ^ txt_set y ^ ")" - | M.Intersect (x, y) -> "(" ^ txt_set x ^ " intersect " ^ txt_set y ^ ")" - | M.Diff (x, y) -> "(" ^ txt_set x ^ " diff " ^ txt_set y ^ ")" - | M.LetSVar (sv, x, y) -> "let " ^ txt_svar sv ^ " be " ^ txt_set x ^ " in " ^ txt_set y - | M.LetVVar (vv, x, y) -> "let " ^ txt_vvar vv ^ " be " ^ txt_val x ^ " in " ^ txt_set y - | M.Select (rv, x, y) -> "select " ^ txt_rvar rv ^ " in " ^ txt_set x ^ " where " ^ txt_boole y - | M.Pattern x -> "pattern " ^ txt_val x - | M.Ref x -> "ref " ^ txt_val x + | M.SVar sv -> txt_svar sv + | M.RVar rv -> txt_rvar rv + | M.Relation (i, r, p, x, []) -> "relation " ^ txt_refpath i r p ^ txt_set x + | M.Relation (i, r, p, x, l) -> "relation " ^ txt_refpath i r p ^ txt_set x ^ " attr " ^ txt_list txt_vvar ", " l + | M.Union (x, y) -> "(" ^ txt_set x ^ " union " ^ txt_set y ^ ")" + | M.Intersect (x, y) -> "(" ^ txt_set x ^ " intersect " ^ txt_set y ^ ")" + | M.Diff (x, y) -> "(" ^ txt_set x ^ " diff " ^ txt_set y ^ ")" + | M.LetSVar (sv, x, y) -> "let " ^ txt_svar sv ^ " be " ^ txt_set x ^ " in " ^ txt_set y + | M.LetVVar (vv, x, y) -> "let " ^ txt_vvar vv ^ " be " ^ txt_val x ^ " in " ^ txt_set y + | M.Select (rv, x, y) -> "select " ^ txt_rvar rv ^ " in " ^ txt_set x ^ " where " ^ txt_boole y + | M.Pattern x -> "pattern " ^ txt_val x + | M.Ref x -> "ref " ^ txt_val x in txt_set x diff --git a/helm/ocaml/mathql/mathQL.ml b/helm/ocaml/mathql/mathQL.ml index 6d112c85b..71682f2a0 100644 --- a/helm/ocaml/mathql/mathQL.ml +++ b/helm/ocaml/mathql/mathQL.ml @@ -55,7 +55,7 @@ type set_exp = SVar of svar | RVar of rvar | Ref of val_exp | Pattern of val_exp - | Relation of refine_op * path * set_exp * vvar_list + | Relation of bool * refine_op * path * set_exp * vvar_list | Select of rvar * set_exp * boole_exp | Union of set_exp * set_exp | Intersect of set_exp * set_exp @@ -77,8 +77,8 @@ and val_exp = Const of string list | RefOf of set_exp | Record of rvar * vvar | VVar of vvar + | Attribute of bool * refine_op * path * val_exp | Fun of string * val_exp - | Attribute of refine_op * path * bool * val_exp type query = set_exp diff --git a/helm/ocaml/mathql_interpreter/attribute.cmi b/helm/ocaml/mathql_interpreter/attribute.cmi deleted file mode 100644 index d81b9a2588a634aba1f74e2b8f30599e56b4418c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 369 zcmZ=x%*`>hw6ydzFtBWyx@;c<1H*G5HUr|_K)il|rejG-QD#zUN$P?H8!B}YVZ8X% z3Wo(74k&Ecv~j`)2Q}Zsl8itfN6n(tw9LHJ`1}Hf{|*xzm{`9)WMKHV;Q$LasydYd zpn4=F-+@X*H*A`)!Br(GKR?F-uJ;E}LKao8YFT1VX)2QDp9JK8LEZ5iO87q0b+e1R$GANcY{L$y*{r~=a$`fcb_y9+w&xs|NVjm&;T(oJ~U(UgH1=~PJM7cUf{Zdlmh_xsFOti diff --git a/helm/ocaml/mathql_interpreter/attribute.cmx b/helm/ocaml/mathql_interpreter/attribute.cmx deleted file mode 100644 index eca5ff81e27365f8463473431a31e4f22fe42144..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 534 zcmZ=x%*`>hw6u&gFtBKux@;c<1LHFW1_n1EEefO`aWF6_FlaiKloVwqm6oI~U}17t zut3Epv$(|I*H+`Oy4DXn*VtBzawjKvE?A)F3^Xk>uOzi7FEPj8-yr1v9#PrrQrFdD zWsJpV)hI7mfH2A6kU+1`>(ser_uZXmU$opQyI_HOXh~*HW=W+%cUz%RlY;x?=?5+J zGfe)ST(CeRAiuaIy(qQV;QaC6h8OufiWfx=2gI)vIJ#hgnoCl0eqNrzv-^{~xV8ip zX-_wt@-A`17NBjOAh#5!CYKnno|qk$_h41!>i~_zMcu8N7c9^UNG&Q$EY2(g8fyRe zpiS+jpJmQ*wLMRA`QHN#^-V0v2=p;9J~U(UgH1=~PJM7cUf{Zd6wvobrsi!GoDmc2 z{hP@yHm>rrQXY~Yo^O76Hu8dETgwvLbM2b4`%x`?cgbUAm;34&QoGoWss>o?Mfl>B z(T-ptu`5X*9A8J@F3=K$g?7SS_55>=r^HhFCMf@2ucCq(+NLbYv!y3A*=%#YxPDom z=?sU76BZn>f=69^d?G9s<5Mf*P0d^!92^$7I4p2-aQNOC#1*?Fu&#>h-o~Qi{|^HI D!@%UB diff --git a/helm/ocaml/mathql_interpreter/attribute.ml b/helm/ocaml/mathql_interpreter/attribute.ml index 2e4f8f5b4..46b8eae9b 100644 --- a/helm/ocaml/mathql_interpreter/attribute.ml +++ b/helm/ocaml/mathql_interpreter/attribute.ml @@ -37,7 +37,7 @@ open Intersect;; let rec attribute_ex rop path inv = function [] -> [] | s::tl -> let tab = List.hd path in - if (not inv) then + if inv then let res = let c = pgc () in let q = ("select " ^ tab ^ ".uri from " ^ tab ^ " where " ^ tab ^ ".value = '" ^ s ^ "'") in diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index 518463bc0..c67d11d15 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -120,7 +120,7 @@ let rec exec_set_exp c = function print_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res - | MathQL.Relation (rop, path, sexp, attl) -> + | MathQL.Relation (inv, rop, path, sexp, attl) -> let before = Sys.time() in if ! dbname = postgres_db then (let res = relation_ex rop path (exec_set_exp c sexp) attl in @@ -207,7 +207,7 @@ and exec_val_exp c = function | MathQL.VVar s -> List.assoc s c.vvars | MathQL.RefOf sexp -> List.map (fun (s,_) -> s) (exec_set_exp c sexp) | MathQL.Fun (s, vexp) -> fun_ex s (exec_val_exp c vexp) - | MathQL.Attribute (rop, path, inv, vexp) -> attribute_ex rop path inv (exec_val_exp c vexp) + | MathQL.Attribute (inv, rop, path, vexp) -> attribute_ex rop path inv (exec_val_exp c vexp) (* valuta una MathQL.set_exp nel contesto vuoto e ritorna un MathQL.resource_set *) and execute x = -- 2.39.2