Skip to content

Commit

Permalink
Merge pull request #4 from SuffolkLITLab/spellchecking
Browse files Browse the repository at this point in the history
Add a basic spellchecking functionality to information page
  • Loading branch information
nonprofittechy authored Apr 26, 2022
2 parents 54efa18 + 6cabcb7 commit da9a1eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions docassemble/ALLinter/data/questions/interview_wide_linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ code: |
code: |
warnings = text_violations(interview_texts_no_mako)
---
code: |
misspelled = get_misspelled_words(paragraph)
---
event: results
question: |
Interview Suggestions
Expand All @@ -67,6 +70,16 @@ subquestion: |
* ${ key } : ${ val }
% endfor
% if misspelled:
### Misspelled words
It looks like these words are misspelled:
% for misspelled_word in misspelled:
* ${ misspelled_word }
% endfor
% endif
% if headings_warnings or warnings:
### Warnings:
Expand All @@ -83,6 +96,8 @@ subquestion: |
% endfor
% endif
help:
label: |
Text used
Expand Down
28 changes: 27 additions & 1 deletion docassemble/ALLinter/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,33 @@
import mako.exceptions
import docassemble.webapp.screenreader
import docassemble.base.filter
from typing import List, Tuple
from typing import List, Tuple, Dict, Mapping, Set, Union
from spellchecker import SpellChecker

__all__ = [
"get_misspelled_words",
"get_corrections",
"load_interview",
"remove_mako",
"get_all_headings",
"get_heading_width",
"headings_violations",
"text_violations",
"get_all_text",
]

def get_misspelled_words(text:str, language:str="en")->Set[str]:
spell = SpellChecker(language=language)
return spell.unknown(re.findall(r'\w+', text))

def get_corrections(misspelled:Union[Set[str], List[str]], language:str="en")->Mapping[str, Set[str]]:
spell = SpellChecker(language=language)
return [
{
misspelled_word: spell.corrections(misspelled_word)
}
for misspelled_word in misspelled
]

mega_list = ('default', 'input type', 'using', 'keep for training',
'validation messages', 'validate', 'rows', 'maximum image size',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
url='https://docassemble.org',
packages=find_packages(),
namespace_packages=['docassemble'],
install_requires=['Mako>=1.1.4', 'ruamel.yaml>=0.17.4', 'plumbum>=1.7.2', 'textstat>=0.7.0'],
install_requires=['Mako>=1.1.4', 'pyspellchecker>=0.6.3', 'ruamel.yaml>=0.17.4', 'plumbum>=1.7.2', 'textstat>=0.7.0'],
zip_safe=False,
package_data=find_package_data(where='docassemble/ALLinter/', package='docassemble.ALLinter'),
)
Expand Down

0 comments on commit da9a1eb

Please sign in to comment.