diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index 87419a731..43211b665 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -85,6 +85,11 @@ jobs: python instance_validator.py -i ../../abel/tests/test_resources/good_test_building_config.yaml working-directory: ./tools/validators/instance_validator + - name: Correct Ontology Descriptions + run: | + pip install -r tools/spellcheck/requirements.txt + python tools/spellcheck/spellcheck.py + #---------- ABEL ----------# - name: ABEL install dependencies if: steps.changes.outputs.abel == 'true' || steps.changes.outputs.instance_validator == 'true' || steps.changes.outputs.type_validator == 'true' diff --git a/tools/spellcheck/__init__.py b/tools/spellcheck/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tools/spellcheck/requirements.txt b/tools/spellcheck/requirements.txt new file mode 100644 index 000000000..7a7631b41 --- /dev/null +++ b/tools/spellcheck/requirements.txt @@ -0,0 +1 @@ +textblob diff --git a/tools/spellcheck/spellcheck.py b/tools/spellcheck/spellcheck.py new file mode 100644 index 000000000..da66f920e --- /dev/null +++ b/tools/spellcheck/spellcheck.py @@ -0,0 +1,40 @@ +import yaml +import os + +from pathlib import Path +from textblob import TextBlob + +def process_file(path): + if os.path.splitext(path)[1] != ".yaml": + return + structure = None + try: + structure = yaml.safe_load(Path(path).read_text()) + except: + print("[WARN] Failed to load file %s.") + return + for key in structure.keys(): + value = structure[key] + if type(value) != dict: + continue + if "description" not in value: + continue + description = value["description"] + text_blob = TextBlob(description) + corrected = text_blob.correct() + if corrected != description: + print("[CORRECTIONS] in file %s at key %s" % (path, key)) + print(" Did you mean '%s' instead of '%s'" % (description, corrected)) + +def process_directory(path): + children = os.listdir(path) + for child in children: + full_child = path + os.sep + child + if os.path.isdir(full_child): + process_directory(full_child) + else: + process_file(full_child) + + + +process_directory("ontology/yaml")