Example #1
0
    def query(
        self,
        literal: Literal,
        mode: RuleType = RuleType.DEFEASIBLE
    ) -> Tuple[Answer, Optional[Warrant]]:
        if self._answers is None:
            self._answers = {}

        answers = self._answers.setdefault(mode, {})
        if literal not in answers:
            if literal not in self.get_literals(mode):
                answers.setdefault(literal, (Answer.UNKNOWN, None))
            else:
                warrant = self._get_warrant(literal, mode)
                if warrant is not None:
                    answers.setdefault(literal, (Answer.YES, warrant))
                else:
                    complement = literal.get_complement()
                    warrant = self._get_warrant(complement, mode)
                    if warrant is not None:
                        answers.setdefault(literal, (Answer.NO, warrant))
                    else:
                        answers.setdefault(literal, (Answer.UNDECIDED, None))

        return self._answers.get(mode, {}).get(literal, (Answer.UNKNOWN, None))
Example #2
0
def disagree(literal1: Literal, literal2: Literal,
             rules: Iterable[Rule]) -> bool:
    if literal1.get_complement() == literal2:
        return True

    index = as_index(rules, RuleType.STRICT)
    index.setdefault(literal1, set()).add(literal1.as_fact())
    index.setdefault(literal2, set()).add(literal2.as_fact())

    return bool(is_contradictory(index))