Skip to content

Models

A model is a set of ground terms that satisfy a set of axioms.

Source code in src/typedlogic/solver.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@dataclass
class Model:
    """
    A model is a set of ground terms that satisfy a set of axioms.
    """

    description: Optional[str] = None
    source_object: Optional[Any] = None
    ground_terms: List[Term] = field(default_factory=list)

    def retrieve(self, predicate: Union[str, type], *args) -> List[Term]:
        return list(self.iter_retrieve(predicate, *args))

    def iter_retrieve(self, predicate: Union[str, type], *args) -> Iterator[Term]:
        """
        Retrieve all ground terms with a given predicate.

        :param predicate:
        :return:
        """
        if isinstance(predicate, type):
            predicate = predicate.__name__
        for t in self.ground_terms:
            if t.predicate != predicate:
                continue
            if args:
                is_match = True
                for i in range(len(args)):
                    if args[i] is None:
                        continue
                    if args[i] != t.values[i]:
                        is_match = False
                        break
                if not is_match:
                    continue
            yield t

iter_retrieve(predicate, *args)

Retrieve all ground terms with a given predicate.

Parameters:

Name Type Description Default
predicate Union[str, type]
required

Returns:

Type Description
Iterator[Term]
Source code in src/typedlogic/solver.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def iter_retrieve(self, predicate: Union[str, type], *args) -> Iterator[Term]:
    """
    Retrieve all ground terms with a given predicate.

    :param predicate:
    :return:
    """
    if isinstance(predicate, type):
        predicate = predicate.__name__
    for t in self.ground_terms:
        if t.predicate != predicate:
            continue
        if args:
            is_match = True
            for i in range(len(args)):
                if args[i] is None:
                    continue
                if args[i] != t.values[i]:
                    is_match = False
                    break
            if not is_match:
                continue
        yield t