clingo-hmknf-test/ontology.py

29 lines
825 B
Python
Raw Normal View History

2022-06-30 16:55:42 -06:00
from typing import Dict, Iterable, Set, Union
2022-06-25 18:57:56 -06:00
2022-06-28 16:37:06 -06:00
models = None
DL_ATOMS = "abc"
2022-06-30 16:55:42 -06:00
def set_models(alphabet: Iterable[str], v: Iterable[Dict[str, bool]]):
2022-06-28 16:37:06 -06:00
global models, DL_ATOMS
DL_ATOMS = "".join(alphabet)
2022-06-30 16:55:42 -06:00
models = tuple(set(atom for atom, v in model.items() if v) for model in v)
2022-06-25 18:57:56 -06:00
def propagate(atoms: Set[str]) -> Set[str]:
atoms = atoms.intersection(DL_ATOMS)
2022-06-29 16:06:09 -06:00
sup_models = (model for model in models if atoms <= model)
first: set = next(sup_models, None)
2022-06-25 18:57:56 -06:00
if first is None:
return set()
2022-06-29 16:06:09 -06:00
return first.intersection(*sup_models)
2022-06-25 18:57:56 -06:00
2022-06-28 16:37:06 -06:00
2022-06-29 16:06:09 -06:00
def check(atoms: Set[str]) -> Union[Set[str], None]:
2022-06-25 18:57:56 -06:00
atoms = atoms.intersection(DL_ATOMS)
2022-06-29 16:06:09 -06:00
if atoms not in models:
return None
sub_models = (model for model in models if model < atoms)
return atoms - atoms.intersection(*sub_models)