and an_boole = function
| M.False -> []
| M.True -> []
- | M.Ex _ _ -> []
+ | M.Ex _ -> []
| M.Not x -> an_boole x
| M.And (x, y) -> join (an_boole x) (an_boole y)
| M.Or (x, y) -> join (an_boole x) (an_boole y)
| STR CM strs { $1 :: $3 }
| STR { [$1] }
;
- vvars:
- | vvar CM vvars { $1 :: $3 }
- | vvar { [$1] }
+ subpath:
+ | STR SL subpath { $1 :: $3 }
+ | STR { [$1] }
;
path:
- | STR SL path { $1 :: $3 }
- | STR { [$1] }
- ;
- ref:
- | SUB { MathQL.SubOp }
- | SUPER { MathQL.SuperOp }
- | { MathQL.ExactOp }
- ;
+ | STR SL subpath { ($1, $3) }
+ | STR { ($1, []) }
+ ;
inv:
| INV { true }
| { false }
;
+ ref:
+ | SUB { MathQL.RefineSub }
+ | SUPER { MathQL.RefineSuper }
+ | { MathQL.RefineExact }
+ ;
val_exp:
| 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) }
+ | rvar FS path { MathQL.Record ($1, $3) }
| vvar { MathQL.VVar $1 }
| LC strs RC { MathQL.Const $2 }
| LC RC { MathQL.Const [] }
| 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 ATTR strs { 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 EOF { $1 }
;
attr:
- | STR IS strs { ($1, $3) }
- | STR { ($1, []) }
+ | path IS strs { ($1, $3) }
+ | path { ($1, []) }
;
attrs:
| attr SC attrs { $1 :: $3 }
resources:
| resource SC resources { $1 :: $3 }
| resource { [$1] }
- | { [] }
+ | { [] }
;
result:
| resources EOF { $1 }
| [a] -> f a
| a :: tail -> f a ^ s ^ txt_list f s tail
-let txt_qstr s = "\"" ^ s ^ "\""
+let txt_str s = "\"" ^ s ^ "\""
+
+let txt_path (p0, p1) =
+ txt_str p0 ^ (if p1 <> [] then "/" ^ txt_list txt_str "/" p1 else "")
let text_of_query x =
let module M = MathQL 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 "
+ | M.RefineExact -> ""
+ | M.RefineSub -> "sub "
+ | M.RefineSuper -> "super "
in
- let txt_refpath i r p = txt_inv i ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " in
+ let txt_refpath i r p = txt_inv i ^ txt_ref r ^ txt_path p ^ " " in
let rec txt_val = function
- | M.Const [s] -> txt_qstr s
- | M.Const l -> "{" ^ txt_list txt_qstr ", " l ^ "}"
+ | M.Const [s] -> txt_str s
+ | M.Const l -> "{" ^ txt_list txt_str ", " 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.Record (rv, p) -> txt_rvar rv ^ "." ^ txt_path p
+ | M.Fun (s, x) -> "fun " ^ txt_str 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.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.Relation (i, r, p, x, l) -> "relation " ^ txt_refpath i r p ^ txt_set x ^ " attr " ^ txt_list txt_str ", " 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 ^ ")"
let text_of_result x sep =
let txt_attr = function
- | (s, []) -> txt_qstr s
- | (s, l) -> txt_qstr s ^ "=" ^ txt_list txt_qstr ", " l
+ | (p, []) -> txt_path p
+ | (p, l) -> txt_path p ^ " = " ^ txt_list txt_str ", " l
in
let txt_group l = "{" ^ txt_list txt_attr "; " l ^ "}" in
let txt_res = function
- | (s, []) -> txt_qstr s
- | (s, l) -> txt_qstr s ^ " attr " ^ txt_list txt_group ", " l
+ | (s, []) -> txt_str s
+ | (s, l) -> txt_str s ^ " attr " ^ txt_list txt_group ", " l
in
let txt_set l = txt_list txt_res ("; " ^ sep) l ^ sep in
txt_set x
(******************************************************************************)
+(* output data structures ***************************************************)
+
+type path = string * (string list) (* the name of an attribute *)
+
+type value = string list (* the value of an attribute *)
+
+type attribute = path * value (* an attribute *)
+
+type attribute_group = attribute list (* a group of attributes *)
+
+type attribute_set = attribute_group list (* the attributes of an URI *)
+
+type resource = string * attribute_set (* an attributed URI *)
+
+type resource_set = resource list (* the query result *)
+
+type result = resource_set
+
+
(* input data structures ****************************************************)
type svar = string (* the name of a variable for a resource set *)
type vvar = string (* the name of a variable for an attribute value *)
-type refine_op = ExactOp
- | SubOp
- | SuperOp
+type inverse = bool
-type path = string list
-
-type vvar_list = vvar list
+type refine = RefineExact
+ | RefineSub
+ | RefineSuper
type set_exp = SVar of svar
| RVar of rvar
| Ref of val_exp
| Pattern of val_exp
- | Relation of bool * refine_op * path * set_exp * vvar_list
+ | Relation of inverse * refine * path * set_exp * string list
| Select of rvar * set_exp * boole_exp
| Union of set_exp * set_exp
| Intersect of set_exp * set_exp
and val_exp = Const of string list
| RefOf of set_exp
- | Record of rvar * vvar
+ | Record of rvar * path
| VVar of vvar
- | Attribute of bool * refine_op * path * val_exp
+ | Attribute of inverse * refine * path * val_exp
| Fun of string * val_exp
type query = set_exp
-
-
-(* output data structures ***************************************************)
-
-type value = string list (* the value of an attribute *)
-
-type attribute = string * value (* an attribute *)
-
-type attribute_group = attribute list (* a group of attributes *)
-
-type attribute_set = attribute_group list (* the attributes of an URI *)
-
-type resource = string * attribute_set (* an attributed URI *)
-
-type resource_set = resource list (* the query result *)
-
-type result = resource_set
*)
let rec attribute_ex rop path inv = function
[] -> []
- | s::tl -> let tab = List.hd path in
+ | s::tl -> let tab = fst path in
if inv then
let res =
let c = pgc () in
* http://cs.unibo.it/helm/.
*)
-val attribute_ex: MathQL.refine_op -> MathQL.path -> bool -> MathQL.value -> MathQL.value
+val attribute_ex: MathQL.refine -> MathQL.path -> bool -> MathQL.value -> MathQL.value
if ! dbname = postgres_db then
(let res = relation_ex rop path (exec_set_exp c sexp) attl in
if ! stat then
- (print_string ("RELATION " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
+ (print_string ("RELATION " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
print_endline (string_of_float (Sys.time() -. before) ^ "s");
flush stdout);
res)
else
(let res = relation_galax_ex rop path (exec_set_exp c sexp) attl in
if !stat then
- (print_string ("RELATION-GALAX " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
+ (print_string ("RELATION-GALAX " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
print_endline (string_of_float (Sys.time() -. before) ^ "s");
flush stdout);
res)
let get_prop_id propl =
- let prop = List.hd propl in
+ let prop = fst propl in
if prop="refObj" then "F"
else if prop="backPointer" then "B"
else assert false
let relation_ex rop path rset attl =
- if path = [] then []
- else
let usek = get_prop_id path in
let vvar = if attl = [] then "position"
else List.hd attl
let res = c#exec qq in
(List.map
(function
- [uri;context] -> [(uri,[[(vvar,[context])]])]
+ [uri;context] -> [(uri,[[((vvar, []),[context])]])]
| _ -> assert false )
res#get_list) @ acc
)
let rec rsetl uril vvar =
match uril with
| uri::tl -> let scuri = (*tofname*) uri in
- [(scuri, [[(vvar, [(List.hd tl)])]])]::(rsetl (List.tl tl) vvar)
+ [(scuri, [[((vvar, []), [(List.hd tl)])]])]::(rsetl (List.tl tl) vvar)
| [] -> []
(* prende una resource e una vvar e restituisce la lista delle resource in relazione (refObj o backPointer in base al parametro "path") con tale resource e associa alla proprieta' il nome della vvar contenuto in "attl" *)
let muse path attl r =
- if path = [] then []
- else
let vvar = if attl = [] then "position"
else List.hd attl
in
let uri = fst r in
let furi = tofname uri in
- let dtag = List.hd path in
+ let dtag = fst path in
let dir =
match dtag with
"refObj" -> "/projects/helm/metadata/create4/forward"
*)
val relation_ex :
- MathQL.refine_op -> MathQL.path -> MathQL.resource_set -> MathQL.vvar_list -> MathQL.resource_set
+ MathQL.refine -> MathQL.path -> MathQL.resource_set -> string list -> MathQL.resource_set
val relation_galax_ex :
- MathQL.refine_op -> MathQL.path -> MathQL.resource_set -> MathQL.vvar_list -> MathQL.resource_set
+ MathQL.refine -> MathQL.path -> MathQL.resource_set -> string list -> MathQL.resource_set