|
8 | 8 |
|
9 | 9 | By Dustin Smith, 2011
|
10 | 10 | """
|
11 |
| -import pexpect |
12 | 11 | from simplejson import loads, dumps
|
13 | 12 | import optparse
|
14 | 13 | import sys
|
15 | 14 | import os
|
16 | 15 | import time
|
17 | 16 | import re
|
| 17 | + |
| 18 | +import pexpect |
| 19 | + |
18 | 20 | import jsonrpc
|
19 | 21 | from progressbar import *
|
20 | 22 |
|
@@ -158,6 +160,39 @@ def parse(self, text):
|
158 | 160 | # convert to JSON and return
|
159 | 161 | return dumps(results)
|
160 | 162 |
|
| 163 | + def parse_imperative(self, text): |
| 164 | + """ |
| 165 | + This is kind of hacky way to deal with imperative statements. |
| 166 | +
|
| 167 | + Takes an imperative string, adds a personal pronoun to the parse, |
| 168 | + and then removes it in the resulting parse. |
| 169 | + |
| 170 | + e.g. "open the door" gets parsed as "you open the door" |
| 171 | +
|
| 172 | + """ |
| 173 | + used_pronoun = None |
| 174 | + pronouns = ["you","he", "she","i"] |
| 175 | + for p in pronouns: |
| 176 | + if p not in text: |
| 177 | + used_pronoun = p |
| 178 | + break |
| 179 | + |
| 180 | + if not used_pronoun: |
| 181 | + return self.parse(text) |
| 182 | + |
| 183 | + text = used_pronoun+" "+text.lstrip() |
| 184 | + first_word = "" |
| 185 | + if len(text.split()) > 1: |
| 186 | + first_word = text.split()[1] |
| 187 | + result = self.parse(text) |
| 188 | + if result[0].has_key('text'): |
| 189 | + result[0]['text'] = text |
| 190 | + result[0]['tuples'] = ifilter(lambda x: x[1] == used_pronoun or x[2] |
| 191 | + == used_pronoun, result[0]['tuples']) |
| 192 | + del result[0]['words'][used_pronoun] |
| 193 | + return result |
| 194 | + else: |
| 195 | + return result |
161 | 196 |
|
162 | 197 | if __name__ == '__main__':
|
163 | 198 | parser = optparse.OptionParser(usage="%prog [OPTIONS]")
|
|
0 commit comments