CLIF Compiler
Bases: Compiler
Compiles a Theory to the Common Logic Interchange Format (CLIF).
Example:
>>> from typedlogic import Forall, Implies, PredicateDefinition, Term, Theory, Variable
>>> theory = Theory(name="friends")
>>> x = Variable("x")
>>> y = Variable("y")
>>> theory.predicate_definitions = [PredicateDefinition("FriendOf", {"x": "str", "y": "str"})]
>>> theory.add(Term("FriendOf", "Alice", "Bob"))
>>> theory.add(Forall([x, y], Implies(Term("FriendOf", x, y), Term("FriendOf", y, x))))
>>> compiler = ClifCompiler()
>>> print(compiler.compile(theory))
(cl-text friends
(FriendOf Alice Bob)
(forall (x y) (if (FriendOf x y) (FriendOf y x)))
)
Source code in src/typedlogic/compilers/clif_compiler.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
compile(theory, syntax=None, **kwargs)
Compile a Theory object into a CLIF document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theory
|
Theory
|
the theory to compile |
required |
syntax
|
Optional[Union[str, ModelSyntax]]
|
unused |
None
|
kwargs
|
unused |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
CLIF representation of the theory |
Source code in src/typedlogic/compilers/clif_compiler.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
compile_sentence(sentence, syntax=None, **kwargs)
Compile an individual sentence to CLIF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sentence
|
Sentence
|
the sentence to compile |
required |
syntax
|
Optional[Union[str, ModelSyntax]]
|
unused |
None
|
kwargs
|
unused |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
CLIF representation of the sentence |
Source code in src/typedlogic/compilers/clif_compiler.py
228 229 230 231 232 233 234 235 236 237 | |