-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNLP Assignment 3 POS Tagging.py
78 lines (39 loc) · 1.45 KB
/
NLP Assignment 3 POS Tagging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# coding: utf-8
# In[5]:
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
stop_words = set(stopwords.words('english'))
feedback = "The customer service is very bad. I bought a Breville Barista Pro espresso machine for 468$ "
"which is too cheap because the machine's price is 850$. The third-party seller was a scammer."
tokenized = sent_tokenize(feedback)
for i in tokenized:
# Word tokenizers is used to find the words, punctuation
wordsList = nltk.word_tokenize(i)
# removing stop words
wordsList = [w for w in wordsList if not w in stop_words]
# Using a Tagger. Which is part-of-speech tagger or POS-tagger
tagged = nltk.pos_tag(wordsList)
print(tagged)
# In[6]:
import pandas as pd
df = pd.read_csv('D:\Walmart_reviews_data.csv')
df
# In[7]:
df['Review'] = df['Review'].str.lower()
df['Review']
# In[11]:
all_feedbacks_together_reviews = ' '.join(df['Review'])
print(all_feedbacks_together_reviews)
# In[12]:
tokenized = sent_tokenize(all_feedbacks_together_reviews)
for i in tokenized:
# Word tokenizers is used to find the words, punctuation
wordsList = nltk.word_tokenize(i)
# removing stop words
wordsList = [w for w in wordsList if not w in stop_words]
# Using a Tagger. Which is part-of-speech tagger or POS-tagger
tagged = nltk.pos_tag(wordsList)
print(tagged)
# In[ ]: