Package: crazytext
crazytextcrazytext:An Easy To Use Text Cleaning Package For NLP Built In PythonSome Times Text Can Become Very Crazy That The Content You Want and Really Useful Become Very Hard To Extract. crazytext is here to help you.
It offers one line code snippets to clean and analyze your text faster than you.why do the hard work when there is an option for smart work-Creator crazytextDependenciespip install pandas
pip install numpy
pip install textblob
pip install sklearn
pip install lxml
pip install nltkInstallationpip install crazytextText Analysis Using crazytextsample_text='AI is the future of HUMAN KIND, & Trendiest Topic of Today. #ai #future @aiforfuture https://ai.com  (555) 555-1234  <p> Mobile Number </p> (555) 345-1234  <span>Pincode:</span> 224 'Let's Import Our LibraryimportcrazytextasctQuick Analysisdoc=ct.Counter(text=sample_text)doc.info()>>LengthofString:153NumberofURLs:1NumberofEmails:0NumberofWords:25AverageWordCount:6.12NumberofStopwords:4TotalHashtags:2TotalMentions:1TotalLengthofNumericData:7SpecialCharacters:154WhiteSpaces:28NumberofVowels:38NumberofConsonants:143TotalUppercaseWords3NumberofPhoneNumberInsideText:2ObservedSentiment:(0.15,'Positive')Step By Step Analysisdoc.count_words()>>25doc.count_stopwords()>>4doc.count_phone_numbers()>>2doc.count_uppercase_words()>>3You Can Try Many More Methods Just Typedoc.countand presstabto get all the available Counter Methods.Note : All The Methods For Counter Class Starts Withcount_Text Extraction Using crazytextsample_text='AI is the future of HUMAN KIND, & Trendiest Topic of Today. #ai #future @aiforfuture www.ai.com (555) 555-1234  xyz@gmail.com <p> Mobile Number </p> (555) 345-1234  <span>Pincode:</span> 224 'Let's Import Our Libraryimportcrazytextasctextractor=ct.Extractor(text=sample_text)Extracting Emailsextractor.get_emails()>>['xyz@gmail.com']Extracting Phone Numbersextractor.get_phone_numbers()['(555) 555-1234','(555) 345-1234']Extracting UPPER CASE wordsextractor.get_uppercase_words()>>['AI','HUMAN','KIND,']Extracting Hashtagsextractor.get_hashtags()>>['#ai','#future']Extracting Mentionsextractor.get_mentions()>>['@aiforfuture']Extracting HTML Tagsextractor.get_html_tags()>>['<p>','</p>','<span>','</span>']Try Other Interesting Methods By Installing The Library Usingpip install crazytext.Note : All The Methods For Extractor Class Starts Withget_Text Cleaning Using crazytextThere Are Two Ways To Clean The TextRemove Text Completly.Replace The Text With Its Saying1.  Remove Text Completly.sample_text='<h1>The Dark ó Knight</h1> a batman ó movie @batman ó #batman https://batman.com (555) 555-1234 ó 21 22 óó ó'Let's Import Our Libraryimportcrazytextasctcleaner=ct.Cleaner(text=sample_text)Removing HTML Tagscleaner.remove_html_tags_c()>>' The Dark ó Knight a batman ó movie @batman ó #batman https://batman.com (555) 555-1234 ó 21 22 óó ó'Removing Phone Numberscleaner.remove_phone_numbers_c()>>'a batman ó movie @batman ó #batman https://batman.com  ó 21 22 óó ó'2. Replace The Text With Its SayingReplacing HTML Tagscleaner.remove_html_tags()>>'HtmlTag The Dark ó Knight a batman ó movie @batman ó #batman https://batman.com (555) 555-1234 ó 21 22 óó ó'Replaxcing Phone Numbercleaner.remove_phone_numbers()>>'The Dark ó Knight</h1> a batman ó movie @batman ó #batman https://batman.com PhoneNumber ó 21 22 óó ó'Quick Cleaning of A DocumentTo Clean A Doucment Quickly You Can Usequickclean()method insideCleanerclass.Quick Cleanimportcrazytextasctct=Cleaner(text=sample_text)ct.quickclean(remove_complete=True,make_base=False)>>'the dark knight batman movie batman batman'You Can Further Remove Duplicates Using Theremove_duplicate_words()method.Working With Dataframes Using crazytextLet's LoadHotel Reviews DataframeFrom My Github.importpandasaspddf=pd.read_csv('https://raw.githubusercontent.com/Abhayparashar31/NLPP_sentiment-analsis-on-hotel-review/main/Restaurant_Reviews.tsv',delimiter="\t",quoting=3)Let's Import Our Library and Creat A Object For Our ClassDataframeimportcrazytextasctdc=ct.Dataframe(df=df,col='Review')Let's Find Our Dataframe Column Word Frequency Count Using crazytextdc.get_df_words_frequency_count()>>the405and378I294was292a228...Seat1dirty-1gross.1unbelievably1check.1Length:2967,dtype:int64Cleaning The Dataframe Using One Line of Code With The Help ofpretty textdf['cleaned_reviews']=dc.clean(remove_complete=True,make_base='lemmatization')df['cleaned_reviews']>>0wowlovedplace1crustnotgood2nottastytexturenasty3stoppedlatemaybankholidayricksteverecom...4theselectionmenugreatprice....Next, Let's Convert This Cleaned Text Into Vectors For Further Processingvector=ct.Dataframe(df=df,col='cleaned_reviews')vector.to_tfidf(max_features=3500)>>array([[0.,0.,0.,1.,0.],[0.,0.72888336,0.6846379,0.,0.],[0.,0.,1.,0.,0.],...,[0.,0.,1.,0.,0.],[0.,0.,0.,0.,1.],[0.,0.,0.,0.,0.]])Project : Sentiment Analysis On Hotel ReviewsLet's Build A Model For Classifying different reviews into two different categories positive and negative using our librarycrazytext.importpandasaspdimportnumpyasnpfromsklearn.model_selectionimporttrain_test_splitfromsklearn.metricsimportconfusion_matrix,accuracy_scorefromsklearn.naive_bayesimportMultinomialNBdataset=pd.read_csv('https://raw.githubusercontent.com/Abhayparashar31/NLPP_sentiment-analsis-on-hotel-review/main/Restaurant_Reviews.tsv',delimiter="\t",quoting=3)doc=ct.Dataframe(df=dataset,col='Review')corpus=doc.clean(remove_complete=True,make_base='lemmatization')## CleaningX,cv=ct.to_cv(corpus,max_features=3500)## Vectorizationy=dataset['Liked']X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)cls=MultinomialNB().fit(X_train,y_train)y_pred=cls.predict(X_test)cm=confusion_matrix(y_test,y_pred)score=accuracy_score(y_test,y_pred)print(cm,score*100)#print(np.concatenate((y_pred.reshape(len(y_pred),1), np.array(y_test).reshape(len(y_test),1)),1))>>>[[7819][2182]]80.0We Received An Accuracy of 80% using our library. Let's use this model to predict some new reviews.new_review=str(input("Enter new review..."))cleaner=ct.Cleaner(text=new_review)cleaned_review=cleaner.quick_clean(remove_complete=True,make_base='lemmatization')new_x=cv.transform([cleaned_review]).toarray()predictions=cls.predict(new_x)ifpredictions[0]==1:print('Positive 😀')else:print("Negative 😞")>>>Enternewreview...worstfoodandexperienceNegative😞FUTURE WORKMore NLP Tasks To Be Added.Inbuilt Model Support To Be Added.UninstallWe Are Unhappy To See You Go, You Can Give Your Feedback By Putting A Comment On The Repo.pip uninstall crazytextContributorAbhay Parashar.