Skip to content

Commit

Permalink
NLP Profiler: adding grammar check to the granular set of metrics pro…
Browse files Browse the repository at this point in the history
…cesses
  • Loading branch information
neomatrix369 committed Jul 12, 2020
1 parent 193aedb commit 2d620cc
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion examples/better-nlp/library/org/neomatrix369/nlp_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from textblob import TextBlob
from textblob import Word

# Grammar Check
import grammar_check

import emoji
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
Expand Down Expand Up @@ -50,13 +53,17 @@ def apply_text_profiling(dataframe, text_column, params={}):
if 'granular' in params:
granular_analysis = params['granular']

if high_level_analysis:
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)
new_dataframe['sentiment_subjectivity'] = new_dataframe['sentiment_subjectivity_score'].apply(sentiment_subjectivity)
new_dataframe['spellcheck_score'] = new_dataframe[text_column].apply(spellcheck_score)
new_dataframe['spelling_quality'] = new_dataframe['spellcheck_score'].apply(spelling_quality)
new_dataframe['grammar_check_score'] = new_dataframe[text_column].apply(grammar_check_score)
new_dataframe['grammar_check'] = new_dataframe['grammar_check_score'].apply(grammar_quality)

if granular_analysis:
new_dataframe['sentences_count'] = new_dataframe[text_column].apply(count_sentences)
Expand Down Expand Up @@ -174,6 +181,21 @@ def spelling_quality(score):
if (score >= each_slab[1]) and (score <= each_slab[2]):
return each_slab[0]


### Grammar check

def grammar_check_score(text):
matches = tool.check(text)
return len(matches)


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

return "No issues"


### Emojis

def gather_emojis(text):
Expand Down

0 comments on commit 2d620cc

Please sign in to comment.