def declare(kb, input): while input: sent_str, input = Sentence.next(input) sent_type = Sentence.classify(sent_str) if sent_type == 'fact': fact = Facts.parse_fact(sent_str) kb.add_fact(fact) elif sent_type == 'rule': rule = Rules.parse_rule(sent_str) kb.add_rule(rule)
def declare(kb, list_data): # initialize a knowledge database while list_data: current_line, list_data = Sentence.read_list( list_data) # return a comment/fact/rule and update list type = Sentence.classify(current_line) if type == 'fact': fact = Fact.parse_fact(current_line) kb.add_fact(fact) kb.add_fact_predicate(fact.predicate) elif type == 'rule': rule = Rule.parse_rule(current_line) kb.add_rule(rule) kb.add_rule_conclusion_predicate(rule.conclusion.predicate)