class Curt(object): INADMISSIBLE = ["That's Greek to me", "Do you get my drift?", "Now, hold your horses!", "Well, I dunno...", "Neither rhyme nor reason."] INCONSISTENT = ["I don't believe that!", "Nice try!", "That's a switch!", "Don't try to butter me up!", "I smell a rat.", "Tell it to the marines!"] UNINFORMATIVE = ["I know that already!", "Whatever!", "You ain't seen nothing yet!", "Hey, that's an oldie.", "Betcha don't know.", "It's all one to me "] OK = ["Nice to know", "OK", "Go on!", "Go ahead!", "No problem!", "Do your thing!", "No kiddin'?", "Really?", "Is that so?", "That's more like it", "What are you driving at?", "C'mon, shake a leg!", "Well, that's the way the cookie crumbles.", "Spill the beans!", "While you live, tell truth and shame the Devil!"] GOODBYE = ["See ya!", "Nice talking to you!", "Bye!", "Take care!", "Cheers!", "So long and thanks for all the fish!"] def __init__(self, grammar_file='file:../data/grammar.fcfg', logic_parser=DrtParser, background=None): self.tester = Tester(grammar_file, logic_parser) self.background = background self.discourse = None def randomize(self, option_list): return option_list[random.randint(0, len(option_list) - 1)] def inadmissible(self): return self.randomize(Curt.INADMISSIBLE) def inconsistent(self): return self.randomize(Curt.INCONSISTENT) def uninformative(self): return self.randomize(Curt.UNINFORMATIVE) def ok(self): return self.randomize(Curt.OK) def goodbye(self): return self.randomize(Curt.GOODBYE) def respond(self, s, explicit): if isinstance(s, AdmissibilityError): return "%s%s" % (self.inadmissible(), "(inadmissible)" if explicit else "") elif isinstance(s, ConsistencyError): return "%s%s" % (self.inconsistent(), "(inconsistent)" if explicit else "") elif isinstance(s, InformativityError): return "%s%s" % (self.uninformative(), "(uninformative)" if explicit else "") def process(self, utterance, explicit=False, verbose=False): if self.discourse is None: self.discourse = self.tester.parse(utterance, utter=True) else: expression = self.tester.parse_new(self.discourse, utterance) inferences, errors = self.tester.interpret_new(self.discourse, expression, background=self.background) if not inferences: out = [] for reading, error in errors: if verbose: print "Error: %s" % error out.append(self.respond(error, explicit)) return ", ".join(out) else: if verbose: for inference in inferences: print "reading: %s" % inference self.discourse = (self.discourse + expression).simplify() return self.ok() def __str__(self): return str(self.discourse)
def __init__(self, grammar_file='file:../data/grammar.fcfg', logic_parser=DrtParser, background=None): self.tester = Tester(grammar_file, logic_parser) self.background = background self.discourse = None
def main(): tester = Tester('file:../data/grammar.fcfg', DrtParser) for header, test in TESTS: print_header("Testing %s" % header) test(tester) print "\n\t{0} THE END {0}".format("#" * 37)