Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVamsi Krishna Davuluri <iwikiwi@huecomundo.themachineninja.org>2009-10-21 09:22:06 (GMT)
committer Vamsi Krishna Davuluri <iwikiwi@huecomundo.themachineninja.org>2009-10-21 09:22:06 (GMT)
commit36617200af5b9d296aacbe35ab8a37344372fd5c (patch)
tree258c02fe5bf8954afb3e27eb041e2e25c3a3adf3
parent41420d63709f188edb631bc49286a3f6f2377964 (diff)
added basic exception handling for no match found caseHEADmaster
-rw-r--r--libRLP.py19
-rw-r--r--libRLP.pycbin3709 -> 4023 bytes
-rw-r--r--test.py2
3 files changed, 17 insertions, 4 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
+
diff --git a/libRLP.pyc b/libRLP.pyc
index 675c991..f353a6a 100644
--- a/libRLP.pyc
+++ b/libRLP.pyc
Binary files differ
diff --git a/test.py b/test.py
index 3afc1b2..1eb8c80 100644
--- a/test.py
+++ b/test.py
@@ -1,5 +1,5 @@
from libRLP import *
-process = InputBreaker('tell me about sugar development')
+process = InputBreaker('what is my name?')
matchobj = Match(process.qEntitySentences)
answer = matchobj.reportAnswer()
print '\n\n'