clingo-hmknf-test/ontology.py

26 lines
626 B
Python

from typing import Iterable, Set
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)
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)
def check(atoms: Set[str]) -> bool:
atoms = atoms.intersection(DL_ATOMS)
return atoms in models