# Path: scorpion/learners/cn2sd/rule.py
# def fill_in_rules(rules, table, cols=None, cont_dists=None):
#     # compute bounds for columns in self.cols
#     if cols is None:
#         cols = [attr.name for attr in table.domain]
# 
#     nparr = None
#     ref_bounds = {}
#     for col in cols:
#         attr = table.domain[col]
#         if attr.var_type == Orange.feature.Type.Discrete:
#             ref_bounds[col] = None
#             continue
# 
#         if cont_dists:
#           bound = cont_dists[attr.name].min, cont_dists[attr.name].max
#         else:
#           if nparr is None:
#             nparr = table.to_numpyMA('ac')[0]
#           pos = table.domain.index(attr)
#           arr = nparr[:,pos]
#           bound = (arr.min(), arr.max())
# 
#         ref_bounds[col] = bound
# 
# 
#     for rule in rules:
#         rule.fill_in_rule(table, ref_bounds)


import json
import time
import pdb
import sys
import Orange
import orange
import heapq
    import bsddb as bsddb3
    import bsddb as bsddb3
from multiprocessing import Process, Queue, Pool, Pipe
from Queue import Empty
from collections import deque
from itertools import chain
from rtree.index import Index as RTree
from rtree.index import Property as RProp
from scorpionsql.errfunc import ErrTypes
from ..learners.cn2sd.rule import fill_in_rules
from ..learners.cn2sd.refiner import *
from ..bottomup.bounding_box import *
from ..bottomup.cluster import *
from ..util import *
from ..settings import *
from basic import Basic
from sampler import Sampler
from merger import Merger
from rangemerger import RangeMerger, RangeMerger2
from streamrangemerger import *
from frontier import Frontier
from bdtpartitioner import *
    return hash('\n'.join(components))


  def setup_tables(self, full_table, bad_tables, good_tables, **kwargs):
    Basic.setup_tables(self, full_table, bad_tables, good_tables, **kwargs)


    # this is to cache a row's influence 
    self.SCORE_ID = add_meta_column(
      chain([full_table], bad_tables, good_tables),
      SCORE_VAR
    )

    domain = self.full_table.domain
    attrnames = [attr.name for attr in domain]
    self.cont_dists = dict(zip(attrnames, Orange.statistics.basic.Domain(self.full_table)))
    self.disc_dists = dict(zip(attrnames, Orange.statistics.distribution.Domain(self.full_table)))

    self.bad_states = [ef.state(t) for ef, t in zip(self.bad_err_funcs, self.bad_tables)]
    self.good_states = [ef.state(t) for ef, t in zip(self.good_err_funcs, self.good_tables)]


  def nodes_to_clusters(self, nodes, table):
    clusters = []
    rules = []
    for node in nodes:
      node.rule.quality = node.influence
      rule = node.rule.simplify(table, self.cont_dists, self.disc_dists)
      rules.append(rule)


# Path: scorpion/learners/cn2sd/rule.py
# def fill_in_rules(rules, table, cols=None, cont_dists=None):
#     # compute bounds for columns in self.cols
#     if cols is None:
#         cols = [attr.name for attr in table.domain]
# 
#     nparr = None
#     ref_bounds = {}
#     for col in cols:
#         attr = table.domain[col]
#         if attr.var_type == Orange.feature.Type.Discrete:
#             ref_bounds[col] = None
#             continue
# 
#         if cont_dists:
#           bound = cont_dists[attr.name].min, cont_dists[attr.name].max
#         else:
#           if nparr is None:
#             nparr = table.to_numpyMA('ac')[0]
#           pos = table.domain.index(attr)
#           arr = nparr[:,pos]
#           bound = (arr.min(), arr.max())
# 
#         ref_bounds[col] = bound
# 
# 
#     for rule in rules:
#         rule.fill_in_rule(table, ref_bounds)


# Path: scorpion/sigmod/bdt.py
import json
import time
import pdb
import sys
import Orange
import orange
import heapq
    import bsddb as bsddb3
    import bsddb as bsddb3
from multiprocessing import Process, Queue, Pool, Pipe
from Queue import Empty
from collections import deque
from itertools import chain
from rtree.index import Index as RTree
from rtree.index import Property as RProp
from scorpionsql.errfunc import ErrTypes
from ..learners.cn2sd.rule import fill_in_rules
from ..learners.cn2sd.refiner import *
from ..bottomup.bounding_box import *
from ..bottomup.cluster import *
from ..util import *
from ..settings import *
from basic import Basic
from sampler import Sampler
from merger import Merger
from rangemerger import RangeMerger, RangeMerger2
from streamrangemerger import *
from frontier import Frontier
from bdtpartitioner import *

    return hash('\n'.join(components))


  def setup_tables(self, full_table, bad_tables, good_tables, **kwargs):
    Basic.setup_tables(self, full_table, bad_tables, good_tables, **kwargs)


    # this is to cache a row's influence 
    self.SCORE_ID = add_meta_column(
      chain([full_table], bad_tables, good_tables),
      SCORE_VAR
    )

    domain = self.full_table.domain
    attrnames = [attr.name for attr in domain]
    self.cont_dists = dict(zip(attrnames, Orange.statistics.basic.Domain(self.full_table)))
    self.disc_dists = dict(zip(attrnames, Orange.statistics.distribution.Domain(self.full_table)))

    self.bad_states = [ef.state(t) for ef, t in zip(self.bad_err_funcs, self.bad_tables)]
    self.good_states = [ef.state(t) for ef, t in zip(self.good_err_funcs, self.good_tables)]


  def nodes_to_clusters(self, nodes, table):
    clusters = []
    rules = []
    for node in nodes:
      node.rule.quality = node.influence
      rule = node.rule.simplify(table, self.cont_dists, self.disc_dists)
      rules.append(rule)


    fill_in_rules(rules, table, cols=self.cols)