-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1072 from azenla/spellcheck
Spellcheck Ontology
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
textblob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |