Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/libRLP.py
diff options
context:
space:
mode:
Diffstat (limited to 'libRLP.py')
-rw-r--r--libRLP.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/libRLP.py b/libRLP.py
index 9f238b1..055b5a5 100644
--- a/libRLP.py
+++ b/libRLP.py
@@ -7,6 +7,7 @@ from nltk import tokenize
import math
import os
+import random
class InputBreaker:
def __init__(self, text):
@@ -59,10 +60,17 @@ class Match:
else:
pass
if successmeter > 0:
- listofmetricsforsentence.append([self.tomatchwords, successmeter, linetosave, ])
+ listofmetricsforsentence.append([self.tomatchwords,\
+ successmeter, linetosave, ])
#print listofmetricsforsentence
- self.mostprobableQ = self.doMath(listofmetricsforsentence)[2]
+ try:
+ self.mostprobableQ = self.doMath(listofmetricsforsentence)[2]
+ except IndexError:
+ self.mostprobableQ = random.choice(\
+ ["Sorry, can you be a bit more Sugar specific?"\
+ , "Hmm, I don't know about it",\
+ "Ask someone more knowledgeable than me."])
print self.mostprobableQ
self.file.close()
@@ -101,4 +109,9 @@ class Match:
content = file.read()
tuple = content.split(self.mostprobableQ)
file.close()
- return tuple[1].split('Q.')[0]
+ try:
+ answer = tuple[1].split('Q.')[0]
+ except IndexError:
+ answer = ""
+ return answer
+