-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now System is working based on customized dic and also SentiWordNet
- Loading branch information
1 parent
34ad3ff
commit cc82703
Showing
3 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
text = """What can I say about this place. The staff of the restaurant is | ||
nice and the eggplant is not bad. Apart from that, very uninspired food, | ||
lack of atmosphere and too expensive. I am a staunch vegetarian and was | ||
sorely disappointed with the veggie options on the menu. Will be the last | ||
time I visit, I recommend others to avoid.""" | ||
text = "This toy does not look like the picture at all." \ | ||
" The bread, tomato, and lettuce were all hard. " \ | ||
"The only parts that are a bit realistic are the cheese and meats." \ | ||
" This toy came with only one tomato and one lettuce." \ | ||
" That's not enough objects to make multiple full sandwiches." \ | ||
" I would recommend not buying this toy if you want your money's worth." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import nltk | ||
from nltk.corpus import sentiwordnet as swn | ||
import InputTxt | ||
|
||
sentences = nltk.sent_tokenize(InputTxt.text) | ||
print(sentences) | ||
sentences_tokens = [nltk.word_tokenize(s) for s in sentences] | ||
print(sentences_tokens) | ||
tagged_list = [] | ||
for i in sentences_tokens: | ||
tagged_list.append(nltk.pos_tag(i)) | ||
print(tagged_list) | ||
wordNetLemmatizer = nltk.WordNetLemmatizer() | ||
|
||
score_list = [] | ||
for i, j in enumerate(tagged_list): | ||
score_list.append([]) | ||
for m, n in enumerate(j): | ||
new_tag = '' | ||
lemmatized = wordNetLemmatizer.lemmatize(n[0]) | ||
if n[1].startswith('NN'): | ||
new_tag = 'n' | ||
elif n[1].startswith('JJ'): | ||
new_tag = 'a' | ||
elif n[1].startswith('V'): | ||
new_tag = 'v' | ||
elif n[1].startswith('R'): | ||
new_tag = 'r' | ||
else: | ||
new_tag = '' | ||
if new_tag != '': | ||
synsets = list(swn.senti_synsets(lemmatized, new_tag)) | ||
score = 0 | ||
if len(synsets) > 0: | ||
for s in synsets: | ||
score += s.pos_score() - s.neg_score() | ||
score_list[i].append(score/len(synsets)) | ||
|
||
print(score_list) | ||
sentences_sentiment = [] | ||
|
||
for s in score_list: | ||
sentences_sentiment.append(sum([w for w in s])/len(s)) | ||
print("Final Sentiment Analysis for each sentences in Input text: .........") | ||
print(sentences_sentiment) | ||
|
||
|
||
|
||
|
||
|
||
|