Skip to content

Commit

Permalink
Merge pull request #1072 from azenla/spellcheck
Browse files Browse the repository at this point in the history
Spellcheck Ontology
  • Loading branch information
trav3711 authored Jul 18, 2023
2 parents 6482fb1 + 74e50ed commit d4087bd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Empty file added tools/spellcheck/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tools/spellcheck/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
textblob
40 changes: 40 additions & 0 deletions tools/spellcheck/spellcheck.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit d4087bd

Please sign in to comment.