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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@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 iter_retrieve(self, predicate: str, *args) -> Iterator[Term]:
        """
        Retrieve all ground terms with a given predicate.

        :param predicate:
        :return:
        """
        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 str
required

Returns:

Type Description
Iterator[Term]
Source code in src/typedlogic/solver.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def iter_retrieve(self, predicate: str, *args) -> Iterator[Term]:
    """
    Retrieve all ground terms with a given predicate.

    :param predicate:
    :return:
    """
    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