Skip to content

Commit

Permalink
NLP Profiler: switching to the right grammar checking library: langua…
Browse files Browse the repository at this point in the history
…ge_tool_python
  • Loading branch information
neomatrix369 committed Jul 12, 2020
1 parent 2d620cc commit 5e26563
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions examples/better-nlp/library/org/neomatrix369/nlp_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from textblob import Word

# Grammar Check
import grammar_check
import language_tool_python

import emoji
from nltk.corpus import stopwords
Expand Down Expand Up @@ -54,8 +54,6 @@ def apply_text_profiling(dataframe, text_column, params={}):
granular_analysis = params['granular']

if high_level_analysis:
tool = grammar_check.LanguageTool('en-GB')

new_dataframe['sentiment_polarity_score'] = new_dataframe[text_column].apply(sentiment_polarity_score)
new_dataframe['sentiment_polarity'] = new_dataframe['sentiment_polarity_score'].apply(sentiment_polarity)
new_dataframe['sentiment_subjectivity_score'] = new_dataframe[text_column].apply(sentiment_subjectivity_score)
Expand Down Expand Up @@ -185,13 +183,14 @@ def spelling_quality(score):
### Grammar check

def grammar_check_score(text):
tool = language_tool_python.LanguageTool('en-GB')
matches = tool.check(text)
return len(matches)


def grammar_quality(score):
if score != 0:
return f"{score} issues"
return f"{score} issue(s)"

return "No issues"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
],
"source": [
"!pip install -U nltk"
"!pip install -U nltk language_tool_python textblob"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/better-nlp/notebooks/jupyter/nlp_profiler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
],
"source": [
"!pip install -U textblob"
"!pip install -U textblob language_tool_python"
]
},
{
Expand Down

0 comments on commit 5e26563

Please sign in to comment.