SHARE
TWEET

Untitled

a guest Oct 21st, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     def kb_retract(self, fact_or_rule):
  2.         """Retract a fact from the KB
  3.         Args:
  4.             fact (Fact) - Fact to be retracted
  5.         Returns:
  6.             None
  7.         """
  8.         printv("Retracting {!r}", 0, verbose, [fact_or_rule])
  9.         ####################################################
  10.         # Student code goes here
  11.  
  12.         if isinstance(fact_or_rule, Fact) and fact_or_rule in self.facts:
  13.             arg_in_kb = self.facts.index(fact_or_rule)
  14.             if (self.facts[arg_in_kb].asserted is True and not self.facts[arg_in_kb].supported_by) or \
  15.                     (self.facts[arg_in_kb].asserted is False and not self.facts[arg_in_kb].supported_by):
  16.                 facts_to_be_checked = self.facts[arg_in_kb].supports_facts
  17.                 rules_to_be_checked = self.facts[arg_in_kb].supports_rules
  18.                 if facts_to_be_checked:
  19.                     for fact in facts_to_be_checked:
  20.                         self.kb_retract_helper(fact, fact_or_rule, "f")
  21.                 if rules_to_be_checked:
  22.                     for rule in rules_to_be_checked:
  23.                         self.kb_retract_helper(rule, fact_or_rule, "r")
  24.                 self.facts.remove(fact_or_rule)
  25.  
  26.             elif self.facts[arg_in_kb].asserted is True and self.facts[arg_in_kb].supported_by:
  27.                 self.facts[arg_in_kb].asserted = False
  28.  
  29.         elif isinstance(fact_or_rule, Rule) and fact_or_rule in self.rules:
  30.             arg_in_kb = self.rules.index(fact_or_rule)
  31.             if self.rules[arg_in_kb].asserted is False and not self.rules[arg_in_kb].supported_by:
  32.                 facts_to_be_checked = self.rules[arg_in_kb].supports_facts
  33.                 rules_to_be_checked = self.rules[arg_in_kb].supports_rules
  34.                 if facts_to_be_checked:
  35.                     for fact in facts_to_be_checked:
  36.                         self.kb_retract_helper(fact, fact_or_rule, "f")
  37.                 if rules_to_be_checked:
  38.                     for rule in rules_to_be_checked:
  39.                         self.kb_retract_helper(rule, fact_or_rule, "r")
  40.                 self.rules.remove(fact_or_rule)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top