Translate text by google translate

Install:

$ pip install googletrans

Check supported languages :

import googletrans
print(googletrans.LANGUAGES)

{‘af’: ‘afrikaans’, ‘sq’: ‘albanian’, ‘am’: ‘amharic’, ‘ar’: ‘arabic’, ‘hy’: ‘armenian’, ‘az’: ‘azerbaijani’, ‘eu’: ‘basque’, ‘be’: ‘belarusian’, ‘bn’: ‘bengali’, ‘bs’: ‘bosnian’, ‘bg’: ‘bulgarian’, ‘ca’: ‘catalan’, ‘ceb’: ‘cebuano’, ‘ny’: ‘chichewa’, ‘zh-cn’: ‘chinese (simplified)’, ‘zh-tw’: ‘chinese (traditional)’, ‘co’: ‘corsican’, ‘hr’: ‘croatian’, ‘cs’: ‘czech’, ‘da’: ‘danish’, ‘nl’: ‘dutch’, ‘en’: ‘english’, ‘eo’: ‘esperanto’, ‘et’: ‘estonian’, ‘tl’: ‘filipino’, ‘fi’: ‘finnish’, ‘fr’: ‘french’, ‘fy’: ‘frisian’, ‘gl’: ‘galician’, ‘ka’: ‘georgian’, ‘de’: ‘german’, ‘el’: ‘greek’, ‘gu’: ‘gujarati’, ‘ht’: ‘haitian creole’, ‘ha’: ‘hausa’, ‘haw’: ‘hawaiian’, ‘iw’: ‘hebrew’, ‘he’: ‘hebrew’, ‘hi’: ‘hindi’, ‘hmn’: ‘hmong’, ‘hu’: ‘hungarian’, ‘is’: ‘icelandic’, ‘ig’: ‘igbo’, ‘id’: ‘indonesian’, ‘ga’: ‘irish’, ‘it’: ‘italian’, ‘ja’: ‘japanese’, ‘jw’: ‘javanese’, ‘kn’: ‘kannada’, ‘kk’: ‘kazakh’, ‘km’: ‘khmer’, ‘ko’: ‘korean’, ‘ku’: ‘kurdish (kurmanji)’, ‘ky’: ‘kyrgyz’, ‘lo’: ‘lao’, ‘la’: ‘latin’, ‘lv’: ‘latvian’, ‘lt’: ‘lithuanian’, ‘lb’: ‘luxembourgish’, ‘mk’: ‘macedonian’, ‘mg’: ‘malagasy’, ‘ms’: ‘malay’, ‘ml’: ‘malayalam’, ‘mt’: ‘maltese’, ‘mi’: ‘maori’, ‘mr’: ‘marathi’, ‘mn’: ‘mongolian’, ‘my’: ‘myanmar (burmese)’, ‘ne’: ‘nepali’, ‘no’: ‘norwegian’, ‘or’: ‘odia’, ‘ps’: ‘pashto’, ‘fa’: ‘persian’, ‘pl’: ‘polish’, ‘pt’: ‘portuguese’, ‘pa’: ‘punjabi’, ‘ro’: ‘romanian’, ‘ru’: ‘russian’, ‘sm’: ‘samoan’, ‘gd’: ‘scots gaelic’, ‘sr’: ‘serbian’, ‘st’: ‘sesotho’, ‘sn’: ‘shona’, ‘sd’: ‘sindhi’, ‘si’: ‘sinhala’, ‘sk’: ‘slovak’, ‘sl’: ‘slovenian’, ‘so’: ‘somali’, ‘es’: ‘spanish’, ‘su’: ‘sundanese’, ‘sw’: ‘swahili’, ‘sv’: ‘swedish’, ‘tg’: ‘tajik’, ‘ta’: ‘tamil’, ‘te’: ‘telugu’, ‘th’: ‘thai’, ‘tr’: ‘turkish’, ‘uk’: ‘ukrainian’, ‘ur’: ‘urdu’, ‘ug’: ‘uyghur’, ‘uz’: ‘uzbek’, ‘vi’: ‘vietnamese’, ‘cy’: ‘welsh’, ‘xh’: ‘xhosa’, ‘yi’: ‘yiddish’, ‘yo’: ‘yoruba’, ‘zu’: ‘zulu’}


from googletrans import Translator

def translatetxt(strtxt, fromlang, tolang):
    translator = Translator()
    line = translator.translate(src=fromlang, dest=tolang, text=strtxt)
    return line.text

en = English, ar = Arabic, fr = French

Translate from English to Arabic:

print(translatetxt('i love you' , 'en', 'ar'))
>> انا احبك

Translate from English to French:

print(translatetxt('i love you' , 'en', 'fr'))
>> je t'aime

Translate from English to German:

print(translatetxt('i love you' , 'en', 'de'))
>> ich liebe dich

{ Add a Comment }

Emotion from the text (positive, negative) python Example

Install :

$ pip install textblob 
from textblob import TextBlob

feedbacks = ['I dont like this app ', 
             "The experience was bad as hell", 
             "This app is really helpful and ",
             "Damn the app tastes like shit ",
            'Please don\'t download the app you will regret it ']

positive_feedbacks = []
negative_feedbacks = []

for feedback in feedbacks:
  feedback_polarity = TextBlob(feedback).sentiment.polarity
  if feedback_polarity>0:
    positive_feedbacks.append(feedback)
    continue
  negative_feedbacks.append(feedback)
  
print('Positive_feebacks Count : {}'.format(len(positive_feedbacks)))
print('positive ', positive_feedbacks)

print('')

print('Negative_feedback Count : {}'.format(len(negative_feedbacks)))
print('negative ', negative_feedbacks)


Result:
Positive_feebacks Count : 0
positive  []

Negative_feedback Count : 5
negative  ['I dont_heat you ', 'The experience was bad as hell', 'This app is really helpful and bad', 'Damn the app tastes like shit ', "Please don't download the app you will regret it "]

{ Add a Comment }

Get New common words from Twitter

Install :

pip install twitter
pip install tweepy
pip install python-twitter
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import itertools
import collections
import twitter
import seaborn as sns
import tweepy as tw
import nltk
from nltk.corpus import stopwords
import re
import warnings
import faisal

To get all the code, click GitHub

{ Add a Comment }