-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_check_utils.py
31 lines (25 loc) · 1.13 KB
/
language_check_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import language_check
################################################################################
# Checks the grammatical correctness of a sentence, or a series of sentences.
################################################################################
def check(conversation):
# The grammar checker
tool = language_check.LanguageTool('en-US')
# Since `conversation` is a list, join all words into a humanly readable form
human_readable_conversation = ""
for word in conversation:
if word in [".", ",", "?", ";"]:
human_readable_conversation += word
else:
human_readable_conversation += " "
human_readable_conversation += word
# Remove whitespaces at the left and right of the conversation
human_readable_conversation = human_readable_conversation.strip()
# Check the grammatical and syntactical correctness of the conversation.
# `errors` will hold all errors found and suggestions made by the
# language checking tool
errors = tool.check(human_readable_conversation)
if len(errors) > 0:
return False
else:
return True