Commit db8e2a2c authored by Kavindu Jayawardana 's avatar Kavindu Jayawardana

Grammer EF

parent a68290b1
# -*- coding: utf-8 -*-
"""Grammar EF 7/2.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Q_S-irMdz7ylUMu410Et4BykeoPN9ywf
"""
import spacy
nlp = spacy.load("en_core_web_sm")
from gingerit.gingerit import GingerIt
text1 = ("We needed to play Cricket, but we was unable to buy ball, then we came back to hostel and start study")
parser = GingerIt()
parser.parse(text1)
text = ("I'll be there in time, but I also have to do my homhomework too,although I should finish them,so I may be late. And one more thing, can I use your car ?. Anyway after today I also need to work hard because my exam is in the next month.")
doc = nlp(text)
Mcount = 0
for token in doc:
(token.text, token.dep_, token.head.text, token.head.pos_,
[child for child in token.children])
if token.dep_ == 'mark':
Mcount = Mcount + 1
#print(f"\n tagged as mark {Mcount}\n\n\n\n")
for sent in doc.sents:
word_count = 0
(sent.text)
print(f"\n >>>> SENTECNSENTENCE : {(sent.text)}.\n")
for words in sent:
# print(words.text)
word_count = word_count + 1
# print(word_count)
if word_count < 20:
print(f"\n**** GOOD SENTECNSENTENCE **** This sentence contains efficient number of words\n")
if word_count >= 20:
print(f"\n**** LENGTHY SENTECNSENTENCE **** This sentence contains {word_count} WORDS.\n")
nlp = spacy.load("en_core_web_sm")
if word_count >= 20:
transitionWordCount = 0
for token in doc:
if token.text == "also" or token.text == "although" or token.text == "so" or token.text == "however" or token.text == "then" or token.text == "because":
transitionWordCount = transitionWordCount + 1
a = token.text
print(f"\n** {a.upper()}")
if word_count >= 20 and Mcount >= 1 :
print(f"\n**** This sentence contained above {transitionWordCount} TRANSITION words in it, and {Mcount} CONJUNCTION words \n")
print("## Sentence is too long! You shoud not use more than 20 words in a single sentence!\n")
if word_count >= 20:
print(f"\n**** This sentence contained above {transitionWordCount} transition words in it.\n")
print("## Sentence is too long! You shoud not use more than 20 words in a single sentence!\n")
if transitionWordCount == 1 and word_count > 20:
print("## Try to split senetce to two sesentences from transition word!\n")
if transitionWordCount >= 2 and word_count > 20:
print("## To make your English perfect make sure you don't use two transition words in a single sentence. Try to split senetce to two sesentences from transition words or conjunction!\n\n")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment