Skip to content

Instantly share code, notes, and snippets.

View mohdsanadzakirizvi's full-sized avatar

Mohd Sanad Zaki Rizvi mohdsanadzakirizvi

View GitHub Profile
import re
# give your filename here
with open("filename.txt", "r") as fp:
text = fp.read()
re.findall(r"[\w.-]+@[\w.-]+", text)
import re
# insert your text here
text = ""
re.findall(r"[\w.-]+@[\w.-]+", text)
#dictionary that contains pos tags and their explanations
pos_dict = {
'CC': 'coordinating conjunction','CD': 'cardinal digit','DT': 'determiner',
'EX': 'existential there (like: \"there is\" ... think of it like \"there exists\")',
'FW': 'foreign word','IN': 'preposition/subordinating conjunction','JJ': 'adjective \'big\'',
'JJR': 'adjective, comparative \'bigger\'','JJS': 'adjective, superlative \'biggest\'',
'LS': 'list marker 1)','MD': 'modal could, will','NN': 'noun, singular \'desk\'',
'NNS': 'noun plural \'desks\'','NNP': 'proper noun, singular \'Harrison\'',
'NNPS': 'proper noun, plural \'Americans\'','PDT': 'predeterminer \'all the kids\'',
'POS': 'possessive ending parent\'s','PRP': 'personal pronoun I, he, she',
from indicnlp.syllable import syllabifier
# Word to be broken into syllables
w='जगदीशचंद्र'
# Language code Hindi in this case
lang='hi'
# Break into syllables
print(' '.join(syllabifier.orthographic_syllabify(w,lang)))
from indicnlp.script import indic_scripts as isc
from indicnlp.script import phonetic_sim as psim
c1='क'
c2='ख'
c3='भ'
lang='hi'
print('Similarity between {} and {}'.format(c1,c2))
print(psim.cosine(
from indicnlp.langinfo import *
# Input character
c='आ'
# Language is Hindi or 'hi'
lang='hi'
print('Is vowel?: {}'.format(is_vowel(c,lang)))
print('Is consonant?: {}'.format(is_consonant(c,lang)))
print('Is velar?: {}'.format(is_velar(c,lang)))
from indicnlp.transliterate.unicode_transliterate import ItransTransliterator
input_text='आज मौसम अच्छा है। इसलिए हम आज खेल सकते हैं!'
# Transliterate Hindi to Roman
print(ItransTransliterator.to_itrans(input_text, 'hi'))
from indicnlp.transliterate.unicode_transliterate import UnicodeIndicTransliterator
# Input text "Today the weather is good. Sun is bright and there are no signs of rain. Hence we can play today."
input_text='आज मौसम अच्छा है। सूरज उज्ज्वल है और बारिश के कोई संकेत नहीं हैं। इसलिए हम आज खेल सकते हैं!'
# Transliterate from Hindi to Telugu
print(UnicodeIndicTransliterator.transliterate(input_text,"hi","te"))
from indicnlp.tokenize import sentence_tokenize
indic_string="""तो क्या विश्व कप 2019 में मैच का बॉस टॉस है? यानी मैच में हार-जीत में \
टॉस की भूमिका अहम है? आप ऐसा सोच सकते हैं। विश्वकप के अपने-अपने पहले मैच में बुरी तरह हारने वाली एशिया की दो टीमों \
पाकिस्तान और श्रीलंका के कप्तान ने हालांकि अपने हार के पीछे टॉस की दलील तो नहीं दी, लेकिन यह जरूर कहा था कि वह एक अहम टॉस हार गए थे।"""
# Split the sentence, language code "hi" is passed for hingi
sentences=sentence_tokenize.sentence_split(indic_string, lang='hi')
# print the sentences
import sys
from indicnlp import common
# The path to the local git repo for Indic NLP library
INDIC_NLP_LIB_HOME=r"indic_nlp_library"
# The path to the local git repo for Indic NLP Resources
INDIC_NLP_RESOURCES=r"indic_nlp_resources"
# Add library to Python path