clingo-hmknf-test/ontology.py

29 lines
825 B
Python

from typing import Dict, Iterable, Set, Union
models = None
DL_ATOMS = "abc"
def set_models(alphabet: Iterable[str], v: Iterable[Dict[str, bool]]):
global models, DL_ATOMS
DL_ATOMS = "".join(alphabet)
models = tuple(set(atom for atom, v in model.items() if v) for model in v)
def propagate(atoms: Set[str]) -> Set[str]:
atoms = atoms.intersection(DL_ATOMS)
sup_models = (model for model in models if atoms <= model)
first: set = next(sup_models, None)
if first is None:
return set()
return first.intersection(*sup_models)
def check(atoms: Set[str]) -> Union[Set[str], None]:
atoms = atoms.intersection(DL_ATOMS)
if atoms not in models:
return None
sub_models = (model for model in models if model < atoms)
return atoms - atoms.intersection(*sub_models)