# Path: pyke/contexts.py
# class simple_context(object):
# class bc_context(simple_context):
# class variable(pattern.pattern):
# class anonymous(variable):
#     def __init__(self):
#     def dump(self):
#     def bind(self, var_name, var_context, val, val_context = None):
#     def is_bound(self, var):
#     def lookup_data(self, var_name, allow_vars = False, final = None):
#     def lookup(self, var, allow_variable_in_ans = False):
#     def mark(self, save_all_undo = False):
#     def end_save_all_undo(self):
#     def undo_to_mark(self, mark, *var_names_to_undo):
#     def done(self):
#     def _unbind(self, var_name):
#     def __init__(self, rule):
#     def name(self): return self.rule.name
#     def __repr__(self):
#     def create_plan(self, final = None):
#     def __new__(cls, name):
#     def __init__(self, name):
#     def __repr__(self): return '$' + self.name
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
#     def __init__(self, name):
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
# 
# Path: pyke/fact_base.py
# class fact_base(knowledge_base.knowledge_base):
#     ''' Not much to fact_bases.  The real work is done in fact_list! '''
#     def __init__(self, engine, name, register = True):
#         super(fact_base, self).__init__(engine, name, fact_list, register)
# 
#     def dump_universal_facts(self):
#         for fl_name in sorted(self.entity_lists.iterkeys()):
#             self.entity_lists[fl_name].dump_universal_facts()
# 
#     def dump_specific_facts(self):
#         for fl_name in sorted(self.entity_lists.iterkeys()):
#             self.entity_lists[fl_name].dump_specific_facts()
# 
#     def add_universal_fact(self, fact_name, args):
#         self.get_entity_list(fact_name).add_universal_fact(args)
# 
#     def add_case_specific_fact(self, fact_name, args):
#         self.get_entity_list(fact_name).add_case_specific_fact(args)
# 
#     def assert_(self, fact_name, args):
#         self.add_case_specific_fact(fact_name, args)
# 
#     def get_stats(self):
#         num_fact_lists = num_universal = num_case_specific = 0
#         for fact_list in self.entity_lists.itervalues():
#             universal, case_specific = fact_list.get_stats()
#             num_universal += universal
#             num_case_specific += case_specific
#             num_fact_lists += 1
#         return num_fact_lists, num_universal, num_case_specific
# 
#     def print_stats(self, f):
#         num_fact_lists, num_universal, num_case_specific = self.get_stats()
#         f.write("%s: %d fact names, %d universal facts, "
#                 "%d case_specific facts\n" %
#                 (self.name, num_fact_lists, num_universal, num_case_specific))


from pyke import contexts, fact_base
import itertools

'''



class rule(object):
    ''' Common to both fc_rules and bc_rules. '''
    def __init__(self, name, rule_base, patterns):
        self.name = name
        self.rule_base = rule_base
        self.patterns = patterns

    def __repr__(self):
        return "<%s %s>" % (self.__class__.__name__, self.name)

    def pattern(self, pattern_index):
        return self.patterns[pattern_index]

class fc_rule(rule):
    def __init__(self, name, rule_base, rule_fn, foreach_facts, patterns):
        super(fc_rule, self).__init__(name, rule_base, patterns)
        rule_base.add_fc_rule(self)
        self.rule_fn = rule_fn
        self.foreach_facts = foreach_facts # (kb_name, fact_name, arg_pats,
                                           #  multi_match?)...
        self.ran = False

    def register_rule(self):
        for i, (kb_name, fact_name, arg_patterns, multi_match) \
         in enumerate(self.foreach_facts):

# Path: pyke/contexts.py
# class simple_context(object):
# class bc_context(simple_context):
# class variable(pattern.pattern):
# class anonymous(variable):
#     def __init__(self):
#     def dump(self):
#     def bind(self, var_name, var_context, val, val_context = None):
#     def is_bound(self, var):
#     def lookup_data(self, var_name, allow_vars = False, final = None):
#     def lookup(self, var, allow_variable_in_ans = False):
#     def mark(self, save_all_undo = False):
#     def end_save_all_undo(self):
#     def undo_to_mark(self, mark, *var_names_to_undo):
#     def done(self):
#     def _unbind(self, var_name):
#     def __init__(self, rule):
#     def name(self): return self.rule.name
#     def __repr__(self):
#     def create_plan(self, final = None):
#     def __new__(cls, name):
#     def __init__(self, name):
#     def __repr__(self): return '$' + self.name
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
#     def __init__(self, name):
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
# 
# Path: pyke/fact_base.py
# class fact_base(knowledge_base.knowledge_base):
#     ''' Not much to fact_bases.  The real work is done in fact_list! '''
#     def __init__(self, engine, name, register = True):
#         super(fact_base, self).__init__(engine, name, fact_list, register)
# 
#     def dump_universal_facts(self):
#         for fl_name in sorted(self.entity_lists.iterkeys()):
#             self.entity_lists[fl_name].dump_universal_facts()
# 
#     def dump_specific_facts(self):
#         for fl_name in sorted(self.entity_lists.iterkeys()):
#             self.entity_lists[fl_name].dump_specific_facts()
# 
#     def add_universal_fact(self, fact_name, args):
#         self.get_entity_list(fact_name).add_universal_fact(args)
# 
#     def add_case_specific_fact(self, fact_name, args):
#         self.get_entity_list(fact_name).add_case_specific_fact(args)
# 
#     def assert_(self, fact_name, args):
#         self.add_case_specific_fact(fact_name, args)
# 
#     def get_stats(self):
#         num_fact_lists = num_universal = num_case_specific = 0
#         for fact_list in self.entity_lists.itervalues():
#             universal, case_specific = fact_list.get_stats()
#             num_universal += universal
#             num_case_specific += case_specific
#             num_fact_lists += 1
#         return num_fact_lists, num_universal, num_case_specific
# 
#     def print_stats(self, f):
#         num_fact_lists, num_universal, num_case_specific = self.get_stats()
#         f.write("%s: %d fact names, %d universal facts, "
#                 "%d case_specific facts\n" %
#                 (self.name, num_fact_lists, num_universal, num_case_specific))


# Path: pyke/fc_rule.py
from pyke import contexts, fact_base
import itertools


'''



class rule(object):
    ''' Common to both fc_rules and bc_rules. '''
    def __init__(self, name, rule_base, patterns):
        self.name = name
        self.rule_base = rule_base
        self.patterns = patterns

    def __repr__(self):
        return "<%s %s>" % (self.__class__.__name__, self.name)

    def pattern(self, pattern_index):
        return self.patterns[pattern_index]

class fc_rule(rule):
    def __init__(self, name, rule_base, rule_fn, foreach_facts, patterns):
        super(fc_rule, self).__init__(name, rule_base, patterns)
        rule_base.add_fc_rule(self)
        self.rule_fn = rule_fn
        self.foreach_facts = foreach_facts # (kb_name, fact_name, arg_pats,
                                           #  multi_match?)...
        self.ran = False

    def register_rule(self):
        for i, (kb_name, fact_name, arg_patterns, multi_match) \
         in enumerate(self.foreach_facts):

            self.rule_base.engine.get_kb(kb_name, fact_base.fact_base) \