Session
momapy_kb.clingo.core
Clingo session for momapy_kb.
Provides a Session class for converting momapy objects to clingo predicates and facts for answer set programming.
Classes:
| Name | Description |
|---|---|
Session |
Session for converting momapy objects to clingo predicates and facts. |
Session
Session for converting momapy objects to clingo predicates and facts.
Example
import momapy_kb.clingo.core with momapy_kb.clingo.core.Session() as session: ... facts = session.make_facts_from_object(my_model)
Methods:
| Name | Description |
|---|---|
get_or_make_predicate_classes_from_type |
Get or create predicate classes for a given Python type. |
make_facts_from_object |
Convert a Python object to clingo facts. |
make_ontology_rules_from_type |
Generate ontology rules expressing type inheritance as ASP rules. |
Source code in src/momapy_kb/clingo/core.py
get_or_make_predicate_classes_from_type
get_or_make_predicate_classes_from_type(type_: type, module: str | None = None, make_predicate_classes_recursively: bool = True) -> list
Get or create predicate classes for a given Python type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The Python type. |
required |
module
|
str | None
|
Module name for resolving forward references. |
None
|
make_predicate_classes_recursively
|
bool
|
Whether to create predicates for nested types. |
True
|
Returns:
| Type | Description |
|---|---|
list
|
A list of predicate classes. |
Source code in src/momapy_kb/clingo/core.py
make_facts_from_object
make_facts_from_object(obj: object, id_to_object: dict | None = None, integration_mode: Literal['hash', 'id'] = 'id', exclude_from_integration: tuple[type, ...] | None = None) -> list
Convert a Python object to clingo facts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to convert. |
required |
id_to_object
|
dict | None
|
Optional cache mapping fact IDs to objects. |
None
|
integration_mode
|
Literal['hash', 'id']
|
How to handle duplicate objects ("hash" or "id"). |
'id'
|
exclude_from_integration
|
tuple[type, ...] | None
|
Types to exclude from integration logic. |
None
|
Returns:
| Type | Description |
|---|---|
list
|
A list of clorm facts. |
Source code in src/momapy_kb/clingo/core.py
make_ontology_rules_from_type
Generate ontology rules expressing type inheritance as ASP rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The Python type to generate rules for. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A sorted list of ASP rule strings. |