-
Notifications
You must be signed in to change notification settings - Fork 2
/
AISummarizer.py
49 lines (41 loc) · 1.23 KB
/
AISummarizer.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
import duckduckgo
import re
class SummarizerResponse:
def __init__(self):
pass
def can_response(self, **kwargs):
# Always return something, maybe useful
return True
def respond(self, **kwargs):
plain_text = kwargs.get('plain_text').lower()
try:
for i in range(5):
print "Attempt #%d"%(i + 1)
try:
result = str(duckduckgo.get_zci(plain_text))#.split()
result = re.sub("\(https?.*\)", "", result)
return result
except:
pass
except:
return "Oops! .. Having some problem!"
return "Oops! .. Having some problem!"
'''
# For Unit Testing . . .
import nltk
from nltk.tag.perceptron import PerceptronTagger
sentence = raw_input()
print(sentence)
text_input = sentence.lower()
#print(text_input)
tokens = nltk.word_tokenize(text_input)
#print(tokens)
perceptron_tagger = PerceptronTagger()
tags = nltk.tag._pos_tag(tokens, None, tagger=perceptron_tagger)
print(tags)
cr = SummarizerResponse()
if cr.can_response(tags=tags, plain_text=text_input):
print cr.respond(tags=tags, plain_text=text_input)
else:
print "something wrong"
'''