NLP Lab Exp 01
NLP Lab Exp 01
Marks :
Experiment No. 01
BATCH - Sign :
Programs:
1.Converting to Lowercase
# Implementation of lower case conversion
def lower_case_convertion(text):
"""
Input :- string
Output :- lowercase string
"""
lower_text = text.lower()
return lower_text
## Output::
import re
def remove_html_tags(text):
"""
Return :- String without Html tags
input :- String
Output :- String
"""
html_pattern = r'<.*?>'
without_html = re.sub(pattern=html_pattern, repl=' ', string=text)
return without_html
ex_htmltags = """
<body>
<div>
<h1>Hi, this is an example text with Html tags. </h1>
</div>
</body>
"""
htmltags_result = remove_html_tags(ex_htmltags)
print(f"Result :- \n {htmltags_result}")
## Output::
Result :-
import re
def remove_urls(text):
"""
Return :- String without URLs
input :- String
Output :- String
"""
url_pattern = r'https?://\S+|www\.\S+'
without_urls = re.sub(pattern=url_pattern, repl=' ', string=text)
return without_urls
## Output::
import re
def remove_numbers(text):
"""
Return :- String without numbers
input :- String
Output :- String
"""
number_pattern = r'\d+'
without_number = re.sub(pattern=number_pattern,
repl=" ", string=text)
return without_number
## Output::
## Output::
This is an example sentence for converting numbers to words like one to one, five to five, seventy-four to
seventy-four, etc.
Conclusions:
Hence we’ve performed preprocessing of text (Tokenization, Filtration)