NLP Lab Assignment-2
NLP Lab Assignment-2
REG NO - 22BCE8334
CODE
import nltk
nltk.download('punkt_tab')
import nltk
nltk.download('punkt')
def split_sentences(text):
sentences = nltk.sent_tokenize(text)
return sentences
document = """Every Saturday I have NLP lab and NLP class.My professor is vishalakshi annepu"""
sentences = split_sentences(document)
print(sentence)
OUTPUT-
Q2.Perform tokenizing and stemming by reading the input string?
CODE -
tokens = word_tokenize(input_string)
stemmer = PorterStemmer()
print("Tokens:", tokens)
print("Stems:", stems)
OUTPUT -
CODE -
drive.mount('/content/drive')
file_path = '/content/nlpLab2.txt'
with open(file_path, 'r') as file:
document = file.read()
print("Document Content:")
print(document)
import nltk
file_path = '/content/nlpLab2.txt'
document = file.read()
tokens = word_tokenize(document.lower())
stop_words = set(stopwords.words('english'))
filtered_tokens = [word for word in tokens if word.isalnum() and word not in stop_words]
word_counts = Counter(filtered_tokens)
OUTPUT -
CODE -
import nltk
nltk.download('averaged_perceptron_tagger')
import spacy
nlp = spacy.load("en_core_web_sm")
text = file.read()
doc = nlp(text)
OUTPUT -
END.