(** Tree-like structure to hold patterns and point at projected databases. *) open Util open Printf (** Indicate if this is an S-extension or I-extension *) type extension_type = | S_extension (** This item starts a new itemset *) | I_extension (** This item continues the current itemset *) type t = { item: Item.t; (** The item itself *) extension: extension_type; (** Indicate S vs I extension *) support: int; (** Number of DB rows that this pattern covers *) projected_db: Database.t ref; (** Point at the projected DB *) mutable children: t ref list; (** List of pointers to child nodes *) } let extension_type_to_string = function | S_extension -> "s" | I_extension -> "i" let rec to_string lattice = Item.to_string lattice.item ^ "_" ^ (extension_type_to_string lattice.extension) ^ ":" ^ (string_of_int lattice.support) ^ " [" ^ join "; " (List.map (fun lref -> to_string !lref) lattice.children) ^ "]\n" let rec to_pretty_string indent lattice = let new_indent = indent ^ " " in "\n" ^ indent ^ Item.to_string lattice.item ^ "_" ^ (extension_type_to_string lattice.extension) ^ ":" ^ (string_of_int lattice.support) ^ " [" ^ join ";" (List.map (fun lref -> to_pretty_string new_indent !lref) lattice.children) ^ "]" let pretty_print lattice = printf "%s\n" (to_pretty_string "" lattice) (** Create the initial base lattice, given a DB *) let initial_lattice db = { item = Item.null(); extension = S_extension; support = Database.size !db; projected_db = db; children = []; } let add_child lattice child = lattice.children <- (ref child)::(lattice.children) let rec print_sequences' prefix lattice = let prefix = prefix ^ (if lattice.extension = S_extension then ")(" else " ") ^ Item.to_string lattice.item in prefix ^ "):" ^ (string_of_int lattice.support) ^ "\n" ^ (join "" (List.map (fun lref -> print_sequences' prefix !lref) lattice.children)) let print_sequences lattice = printf "%s\n" (print_sequences' "" lattice)