clingo-hmknf-test/ontology.py

26 lines
626 B
Python
Raw Normal View History

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