Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic spellchecking functionality to information page #4

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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