+
+(* can restrictions *)
+
+ let (cr_o,cr_r,cr_s) = can_use in
+
+ let uri_of_entry (r, p, d) = r in
+
+ let universe =
+ match cr_o with
+ None -> []
+ | Some cr_o -> List.map uri_of_entry cr_o
+ in
+
+ let tfst (a,b,c) = a in
+ let tsnd (a,b,c) = b in
+ let trd (a,b,c) = c in
+
+ let to_int_list l d =
+ match d with
+ None -> l
+ | Some d -> l@[d]
+ in
+
+ let opos =
+ match cr_o with
+ None -> []
+ | Some cr_o -> (List.map tsnd cr_o) in
+
+ let odep =
+ match cr_o with
+ None -> []
+ | Some cr_o -> let odep_option_list = List.map trd cr_o in
+ let lo_dep_int = List.fold_left to_int_list [] odep_option_list in
+ List.map string_of_int lo_dep_int
+ in
+
+ let rpos =
+ match cr_r with
+ None -> []
+ | Some cr_r -> (List.map fst cr_r) in
+
+ let rdep =
+ match cr_r with
+ None -> []
+ | Some cr_r -> let rdep_option_list = List.map snd cr_r in
+ let lr_dep_int = List.fold_left to_int_list [] rdep_option_list in
+ List.map string_of_int lr_dep_int
+ in
+
+
+ let spos =
+ match cr_s with
+ None -> []
+ | Some cr_s -> (List.map tfst cr_s) in
+
+
+ let sdep =
+ match cr_s with
+ None -> []
+ | Some cr_s -> let sdep_option_list = List.map tsnd cr_s in
+ let ls_dep_int = List.fold_left to_int_list [] sdep_option_list in
+ List.map string_of_int ls_dep_int
+ in
+
+
+ let sor =
+ match cr_s with
+ None -> []
+ | Some cr_s -> List.map trd cr_s in
+
+
+ let q_where_obj = function
+ Some l ->
+ if odep = [] then
+ M.Sub
+ (M.RefOf
+ (M.Select
+ ("uri",
+ M.Relation (false, M.RefineExact, in_path "refObj", M.Ref (M.RefOf (M.RVar "uri0")), [assign "pos" "position"]),
+ M.Ex ["uri"]
+ (M.Meet (M.VVar "obj_positions", M.Record ("uri", in_path "pos"))))),
+ M.VVar "universe")
+ else
+ M.Sub
+ (M.RefOf
+ (M.Select
+ ("uri",
+ M.Relation
+ (false, M.RefineExact, in_path "refObj",
+ M.Ref (M.RefOf (M.RVar "uri0")),
+ [assign "p" "position"; assign "d" "depth"]
+ ),
+ M.Ex ["uri"]
+ (M.And
+ ((M.Meet(M.VVar "obj_positions",M.Record("uri",in_path "p"))),
+ (M.Meet(M.VVar "obj_depths", M.Record("uri",in_path "d")))))
+ )
+ ),
+ M.VVar "universe"
+ )
+
+ | None -> M.True
+ in
+
+ let q_where_rel = function
+ Some l ->
+ let q0 =
+ M.Sub
+ (M.Property
+ (false, M.RefineExact, ("refRel", ["position"]),
+ M.RefOf(M.RVar "uri0")),
+ M.VVar "rel_positions")
+ in
+ if rdep = [] then q0
+ else
+ M.And
+ (q0,
+ M.Sub
+ (M.Property
+ (false, M.RefineExact, ("refRel", ["depth"]),
+ M.RefOf(M.RVar "uri0")),
+ M.VVar "rel_depths"))
+ | None -> M.True
+ in
+
+ let q_where_sort = function
+ Some l ->
+ let q0 =
+ M.And
+ (M.Sub
+ (M.Property
+ (false, M.RefineExact, ("refSort", ["position"]),
+ M.RefOf(M.RVar "uri0")
+ ),
+ M.VVar "sort_positions"),
+ M.Sub
+ (M.Property
+ (false, M.RefineExact, ("refSort", ["sort"]),
+ M.RefOf(M.RVar "uri0")),
+ M.VVar "sorts"))
+ in
+ if sdep = [] then
+ q0
+ else
+ M.And
+ (q0,
+ M.Sub
+ (M.VVar "sort_depths",
+ M.Property
+ (false, M.RefineExact, ("refSort", ["depth"]),
+ M.RefOf(M.RVar "uri0"))))
+ | None -> M.True
+ in
+
+ let q_where cr =
+ let (cr_o,cr_r,cr_s) = cr in
+ M.And(M.And(q_where_obj cr_o, q_where_rel cr_r), q_where_sort cr_s)
+
+ in
+
+(* must restrictions *)
+
+ let build_select_obj (r, pos, dep) =
+ match dep with
+ None -> M.Select
+ ("uri",
+ M.Relation (false, M.RefineExact, ("backPointer", []),
+ M.Ref (M.Const [r]), [assign "pos" "position"]),
+ M.Ex ["uri"]
+ ((M.Sub (M.Const [pos], M.Record ("uri", in_path "pos")))))
+ | Some dep -> let string_dep = string_of_int dep in
+ M.Select
+ ("uri",
+ M.Relation (false, M.RefineExact, ("backPointer", []),
+ M.Ref (M.Const [r]), [assign "p" "position";assign "d" "depth"]),
+ M.Ex ["uri"]
+ (M.And
+ ((M.Sub (M.Const [pos], M.Record ("uri", in_path "p"))),
+ (M.Sub (M.Const [string_dep], M.Record ("uri", in_path "d"))))))
+ in
+
+ let build_select_rel (pos, dep) =
+ match dep with
+ None -> M.Select
+ ("uri",
+ M.Relation (true, M.RefineExact, ("refRel", []), M.Ref (M.Const [""]), [assign "p" "position";assign "d" "depth"]),
+ M.Ex ["uri"]
+ (M.Sub (M.Const [pos], M.Record ("uri", in_path "p"))))
+ | Some dep -> let string_dep = string_of_int dep in
+ M.Select
+ ("uri",
+ M.Relation (true, M.RefineExact, ("refRel", []), M.Ref (M.Const [""]), [assign "p" "position";assign "d" "depth"]),
+ M.Ex ["uri"]
+ (M.And
+ ((M.Sub (M.Const [pos], M.Record ("uri", in_path "p"))),
+ (M.Sub (M.Const [string_dep], M.Record ("uri", in_path "d"))))))
+ in
+
+ let build_select_sort (pos, dep, sor) =
+ match dep with
+ None -> M.Select
+ ("uri",
+ M.Relation (true, M.RefineExact, ("refSort", []), M.Ref (M.Const [""]), [assign "p" "position";assign "d" "depth";assign "s" "sort"]),
+ M.Ex ["uri"]
+ (M.And
+ ((M.Sub (M.Const [pos], M.Record ("uri", in_path "p"))),
+ (M.Sub (M.Const [sor], M.Record ("uri", in_path "s"))))))
+
+ | Some dep -> let string_dep = string_of_int dep in
+ M.Select
+ ("uri",
+ M.Relation (true, M.RefineExact, ("refSort", []), M.Ref (M.Const [""]), [assign "p" "position";assign "d" "depth";assign "s" "sort"]),
+ M.Ex ["uri"]
+ (M.And
+ ((M.And
+ ((M.Sub (M.Const [pos], M.Record ("uri", in_path "p"))),
+ (M.Sub (M.Const [string_dep], M.Record ("uri", in_path "d"))))),
+ (M.Sub (M.Const [sor], M.Record ("uri", in_path "s"))))))
+ in
+
+ let rec build_intersect_obj = function
+ [] -> M.Pattern (M.Const ["[.]*"])
+ | [hd] -> build_select_obj hd
+ | hd :: tl -> M.Intersect (build_select_obj hd, build_intersect_obj tl)