This file contains hidden or 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
#pip install spacy | |
#python -m spacy download en | |
#pip install multi-rake | |
from multi_rake import Rake | |
import spacy | |
nlp = spacy.load('en') | |
from textblob import TextBlob | |
def computekeywords(sentence): | |
print(sentence) | |
doc = nlp(sentence) | |
rake = Rake() | |
print('using spacy') | |
for ent in doc.ents: | |
print(ent.text, ent.label_) | |
keywords = rake.apply(sentence) | |
print('Keywords using Rake') | |
print(keywords) | |
print('Sentiment of the sentence') | |
analysis = TextBlob(sentence) | |
if(analysis.sentiment[0])>0: | |
intent = 'Positive' | |
elif(analysis.sentiment[0])<0: | |
intent = 'Negative' | |
else: | |
intent = 'Neutral' | |
print(intent) | |
sentence = "I need car insurance" | |
computekeywords(sentence) | |
sentence2 = "I lost my credit card" | |
computekeywords(sentence2) | |
#I need car insurance | |
#using spacy | |
#Keywords using Rake | |
#[('car insurance', 4.0)] | |
#Sentiment of the sentence | |
#Neutral | |
#I lost my credit card | |
#using spacy | |
#Keywords using Rake | |
#[('credit card', 4.0), ('lost', 1.0)] | |
#Sentiment of the sentence | |
#Neutral |
No comments:
Post a Comment