Spaces:
Sleeping
Sleeping
File size: 357 Bytes
438c749 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import language_tool_python
tool = language_tool_python.LanguageTool('en-US')
def grammar_score(text):
matches = tool.check(text)
error_count = len(matches)
words = len(text.split())
if words == 0:
return 0
# simple grammar score
score = max(0, 100 - (error_count / words) * 100)
return round(score, 2), error_count |