text
stringlengths 0
207
|
---|
# print(len(l)) |
Simple Regex |
Regex on strings¶ |
import re |
egstring = ''' |
Jessica is 15 years old, and Daniel is 27 years old. |
Edward is 97 years old, and his grandfather, Oscar, is 108 years old |
''' |
ages = re.findall(r'\d{1,3}', egstring) |
names = re.findall(r'[A-Z][a-z]*', egstring) |
print(ages) |
print(names) |
result = re.split(r'\d{1,3}', egstring) |
print(result) |
string = "Python is fun" |
match = re.search('\APython', string) |
if match: |
print("pattern found inside the string") |
else: |
print("pattern not found") |
Email |
# example |
#pattern = r'\w{4}_\d{2}\w{5}.\w{4}@w{5}.\w{3} |
#pattern1 = r'[a-z]+_[0-9a-z]+.[a-z]+@[a-z.]+' |
#email_string = "[email protected]" |
generic_pattern = r'[a-zA-Z0-9._]+@[a-z]+.[a-z]+' |
email_string1 = "[email protected]" |
if(re.match(generic_pattern, email_string1) != None): |
print(True) |
else: |
print(False) |
# Entering an Email |
email = input ("Enter an email") |
email_list = ["[email protected]", "[email protected]", " [email protected]", |
email_list.append(email) |
print(email_list) |
#Function definition |
def email_match(email_ls): |
count = len(email_ls) |
gmail_pattern = r'[a-zA-Z0-9._]+@gmail.[a-z]+' |
hotmail_pattern = r'[a-zA-Z0-9._]+@hotmail.[a-z]+' |
yahoo_pattern = r'[a-zA-Z0-9._]+@yahoo.[a-z]+' |
print("---") |
print("GMAIL MAILS") |
for i in range(0,count): |
if(re.match(gmail_pattern, email_ls[i]) != None): |
print(email_ls[i]) |
print("---") |
print("HOTMAIL MAILS") |
for i in range(0,count): |
if(re.match(hotmail_pattern, email_ls[i]) != None): |
print(email_ls[i]) |
print("---") |
print("YAHOO MAILS") |
for i in range(0,count): |
if(re.match(yahoo_pattern, email_ls[i]) !=None): |
print(email_ls[i]) |
#Calling the function |
email_match(email_list) |
POS |
import nltk |
from nltk import pos_tag |
from nltk import word_tokenize |
sample_text = word_tokenize("The classes are reopening on 15th March in St. Joseph's College of Commerce") |
sample_text |
pos_tag(sample_text) |
nltk.help.upenn_tagset("DT") |
nltk.help.upenn_tagset("VBP") |
# do for what is asked or how many ever are asked |
#nltk.help.upenn_tagset("NNS") |
text = nltk.Text(word.lower() for word in nltk.corpus.brown.words()) |
text |
Subsets and Splits