mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Initial Integration of GrammarX
This commit is contained in:
parent
a0878b5d01
commit
0073fe48f4
101
scripts/grammarX/README.md
Normal file
101
scripts/grammarX/README.md
Normal file
|
@ -0,0 +1,101 @@
|
|||
# GrammarX
|
||||
|
||||
GrammarX is a python tool which is check grammar mistakes from input file (i.e. whatever written in `demo.txt` ) as well as it will suggest possible fix to it.
|
||||
|
||||
## Requirements
|
||||
|
||||
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install [language-tool-python](https://pypi.org/project/language-tool-python/).
|
||||
|
||||
```bash
|
||||
pip install language-tool-python
|
||||
```
|
||||
|
||||
## Usage
|
||||
- Any input text you want to check you can put in `demo.txt` file
|
||||
- In terminal run this command
|
||||
```python
|
||||
python3 tool.py
|
||||
```
|
||||
|
||||
## Output
|
||||
- Step 1 : Run This command in terminal
|
||||
```
|
||||
python3 tool.py
|
||||
```
|
||||
- Step 2 : You will see this output, this is the original text
|
||||
```
|
||||
******************************************************************************************
|
||||
Original Text
|
||||
******************************************************************************************
|
||||
another big problem in the speech analytics space.
|
||||
When customers first bring the software on,
|
||||
is that they they are blown away by the fact that an engine can monitor hundreds of Kpis.
|
||||
Right? Everything from my new compliance issues to, you know,
|
||||
human human interaction, empathy measurements to upsell aptitude to closing aptitude.
|
||||
They're hundreds literally of Kpis that one could look at. And the speech analytics
|
||||
companies have typically gone to the customer and really bang that trump. We'll get all
|
||||
of these things that we're gonna help you keep an eye on. The reality, however, is that
|
||||
a company even a contact center manager, they can't keep track in their brain even if
|
||||
they have a report in front of. Of that many Kpis. Mh. And frankly, it's overwhelming.
|
||||
So what successful companies do is they bite off no more than they can chew at any given time.
|
||||
The reality is is you can only train a call center agent on a maximum of three skills at any given day. Right?
|
||||
And by focusing on focusing on problem areas, for a week for a month depending on how bad things are.
|
||||
And then once you've mastered that skill to take a baseline of of your performance and move on to the next worst skill.
|
||||
Right, is the way that companies succeed using this product?
|
||||
```
|
||||
- Step 3: Grammar mistakes & Imporvements
|
||||
```
|
||||
******************************************************************************************
|
||||
Grammar mistakes & Improvements
|
||||
******************************************************************************************
|
||||
This sentence does not start with an uppercase letter. => another big problem in the speech analytics space.
|
||||
Suggestion : Another
|
||||
Possible typo: you repeated a word => When customers first bring the software on,
|
||||
is that they they are blown away by the fact that an engine can monitor hundreds of Kpis.
|
||||
Suggestion : they
|
||||
Possible spelling mistake found. => When customers first bring the software on,
|
||||
is that they they are blown away by the fact that an engine can monitor hundreds of Kpis.
|
||||
Suggestion : KPIs
|
||||
Possible typo: you repeated a word => Everything from my new compliance issues to, you know,
|
||||
human human interaction, empathy measurements to upsell aptitude to closing aptitude.
|
||||
Suggestion : human
|
||||
Possible spelling mistake found. => They're hundreds literally of Kpis that one could look at.
|
||||
Suggestion : KPIs
|
||||
The word ‘gonna’ is informal. => We'll get all
|
||||
of these things that we're gonna help you keep an eye on.
|
||||
Suggestion : going to
|
||||
Possible spelling mistake found. => Of that many Kpis.
|
||||
Suggestion : KPIs
|
||||
Possible spelling mistake found. => Mh.
|
||||
Suggestion : MH
|
||||
Possible typo: you repeated a word => The reality is is you can only train a call center agent on a maximum of three skills at any given day.
|
||||
Suggestion : is
|
||||
This phrase is duplicated. You should probably use “focusing on” only once. => And by focusing on focusing on problem areas, for a week for a month depending on how bad things are.
|
||||
Suggestion : focusing on
|
||||
Possible typo: you repeated a word => And then once you've mastered that skill to take a baseline of of your performance and move on to the next worst skill.
|
||||
Suggestion : of
|
||||
```
|
||||
- Step 4 : This is corrected step
|
||||
```
|
||||
******************************************************************************************
|
||||
CORRECTED TEXT
|
||||
******************************************************************************************
|
||||
Another big problem in the speech analytics space.
|
||||
When customers first bring the software on,
|
||||
is that they are blown away by the fact that an engine can monitor hundreds of KPIs.
|
||||
Right? Everything from my new compliance issues to, you know,
|
||||
human interaction, empathy measurements to upsell aptitude to closing aptitude.
|
||||
They're hundreds literally of KPIs that one could look at. And the speech analytics
|
||||
companies have typically gone to the customer and really bang that trump. We'll get all
|
||||
of these things that we're going to help you keep an eye on. The reality, however, is that
|
||||
a company even a contact center manager, they can't keep track in their brain even if
|
||||
they have a report in front of. Of that many KPIs. MH. And frankly, it's overwhelming.
|
||||
So what successful companies do is they bite off no more than they can chew at any given time.
|
||||
The reality is you can only train a call center agent on a maximum of three skills at any given day. Right?
|
||||
And by focusing on problem areas, for a week for a month depending on how bad things are.
|
||||
And then once you've mastered that skill to take a baseline of your performance and move on to the next worst skill.
|
||||
Right, is the way that companies succeed using this product?
|
||||
```
|
||||
|
||||
## License
|
||||
[MIT](https://choosealicense.com/licenses/mit/)
|
15
scripts/grammarX/demoFile.txt
Normal file
15
scripts/grammarX/demoFile.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
another big problem in the speech analytics space.
|
||||
When customers first bring the software on,
|
||||
is that they they are blown away by the fact that an engine can monitor hundreds of Kpis.
|
||||
Right? Everything from my new compliance issues to, you know,
|
||||
human human interaction, empathy measurements to upsell aptitude to closing aptitude.
|
||||
They're hundreds literally of Kpis that one could look at. And the speech analytics
|
||||
companies have typically gone to the customer and really bang that trump. We'll get all
|
||||
of these things that we're gonna help you keep an eye on. The reality, however, is that
|
||||
a company even a contact center manager, they can't keep track in their brain even if
|
||||
they have a report in front of. Of that many Kpis. Mh. And frankly, it's overwhelming.
|
||||
So what successful companies do is they bite off no more than they can chew at any given time.
|
||||
The reality is is you can only train a call center agent on a maximum of three skills at any given day. Right?
|
||||
And by focusing on focusing on problem areas, for a week for a month depending on how bad things are.
|
||||
And then once you've mastered that skill to take a baseline of of your performance and move on to the next worst skill.
|
||||
Right, is the way that companies succeed using this product?
|
47
scripts/grammarX/tool.py
Normal file
47
scripts/grammarX/tool.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import language_tool_python
|
||||
import sys
|
||||
from pathlib import Path
|
||||
script_location = Path(__file__).absolute().parent
|
||||
|
||||
|
||||
def checkGrammar(data):
|
||||
tool = language_tool_python.LanguageTool('en-US')
|
||||
matches = tool.check(data)
|
||||
corrected = language_tool_python.utils.correct(data, matches)
|
||||
tool.close()
|
||||
formatAndDisplay(data, matches, corrected)
|
||||
|
||||
|
||||
def formatAndDisplay(data='', matches=[], corrected=''):
|
||||
print('***'*30)
|
||||
print('Original Text')
|
||||
print('***'*30)
|
||||
print(data)
|
||||
print('***'*30)
|
||||
print('Grammar mistakes & Improvements')
|
||||
print('***'*30)
|
||||
for match in matches:
|
||||
incorrect_text = match.sentence.replace(match.matchedText, '\033[44;33m{}\033[m'.format(match.matchedText))
|
||||
rule_text = '\033[3;31;40m{}\033[m'.format(match.message)
|
||||
suggestion = '\033[4;32;40m{}\033[m'.format(match.replacements[0])
|
||||
print(f"{rule_text} => {incorrect_text}")
|
||||
print(f"Suggestion : {suggestion}")
|
||||
|
||||
# Corrected ----------
|
||||
print('***'*30)
|
||||
print('CORRECTED TEXT')
|
||||
print('***'*30)
|
||||
print('\033[3;33;40m{}\033[m'.format(corrected))
|
||||
print('---'*30)
|
||||
|
||||
|
||||
try:
|
||||
file_location = script_location / 'demoFile.txt'
|
||||
f = open(file_location, "r")
|
||||
fileText = f.read()
|
||||
checkGrammar(fileText)
|
||||
|
||||
except Exception as e:
|
||||
exception_type, exception_object, exception_traceback = sys.exc_info()
|
||||
line_number = exception_traceback.tb_lineno
|
||||
print(f'line {line_number}: {exception_type} - {e}')
|
Loading…
Reference in New Issue
Block a user