File size: 1,224 Bytes
ba9863e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from .literal import Literal


class Rule:
    """
    Represents a rule in propositional logic.

    Attributes:
        rule_name (str): The name of the rule.
        head (Literal): The head literal of the rule.
        body (set[Literal]): The body literals of the rule.
    """

    def __init__(self, rule_name: str, head: Literal = None, body: set[Literal] = None):
        # TODO : According to the lecture notes : "We say that an ABA framework is flat iff no assumption is the head of a rule."
        # Should we check if the head is an instance of Assumption here ?

        self.rule_name: str = rule_name
        self.head: Literal = head
        self.body: set[Literal] = body if body is not None else set()

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Rule):
            return False
        return (
            self.head == other.head
            and self.body == other.body
        )

    def __str__(self) -> str:
        body_str = ','.join(str(literal)
                            for literal in self.body) if self.body else ''
        return f"{self.head}{body_str}"

    def __hash__(self):
        return hash((self.rule_name, self.head, frozenset(self.body)))