cdactvm commited on
Commit
089cd84
·
verified ·
1 Parent(s): 71ca02a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -49
app.py CHANGED
@@ -180,63 +180,68 @@ def is_numword(x):
180
  return True
181
  return False
182
 
183
- def from_numword(x):
184
- if is_number(x):
185
- scale = 0
186
- increment = int(x.replace(',', ''))
187
- return scale, increment
188
- return numwords[x]
189
-
190
- for word in textnum.split():
191
- if word in ordinal_words:
192
- scale, increment = (1, ordinal_words[word])
193
- current = current * scale + increment
194
- if scale > 100:
195
- result += current
196
- current = 0
197
- onnumber = True
198
- lastunit = False
199
- lastscale = False
200
- else:
201
- for ending, replacement in ordinal_endings:
202
- if word.endswith(ending):
203
- word = "%s%s" % (word[:-len(ending)], replacement)
204
-
205
- if (not is_numword(word)) or (word == 'and' and not lastscale):
206
- if onnumber:
207
- curstring += repr(result + current) + " "
208
- curstring += word + " "
209
- result = current = 0
210
- onnumber = False
211
- lastunit = False
212
- lastscale = False
213
- else:
214
- scale, increment = from_numword(word)
215
- onnumber = True
216
 
217
- if lastunit and (word not in scales):
218
- curstring += repr(result + current)
219
- result = current = 0
220
-
221
- if scale > 1:
222
- current = max(1, current)
223
 
 
 
 
224
  current = current * scale + increment
225
  if scale > 100:
226
  result += current
227
  current = 0
228
-
229
- lastscale = False
230
  lastunit = False
231
- if word in scales:
232
- lastscale = True
233
- elif word in units:
234
- lastunit = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
- if onnumber:
237
- curstring += repr(result + current)
238
-
239
- return curstring
240
 
241
  # Convert sentence to transcript using Soundex
242
  def sentence_to_transcript(sentence, word_to_code_map):
 
180
  return True
181
  return False
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
+ def from_numword(x):
185
+ if is_number(x):
186
+ scale = 0
187
+ increment = int(x.replace(',', ''))
188
+ return scale, increment
189
+ return numwords[x]
190
 
191
+ for word in textnum.split():
192
+ if word in ordinal_words:
193
+ scale, increment = (1, ordinal_words[word])
194
  current = current * scale + increment
195
  if scale > 100:
196
  result += current
197
  current = 0
198
+ onnumber = True
 
199
  lastunit = False
200
+ lastscale = False
201
+ else:
202
+ for ending, replacement in ordinal_endings:
203
+ if word.endswith(ending):
204
+ word = "%s%s" % (word[:-len(ending)], replacement)
205
+
206
+ if (not is_numword(word)) or (word == 'and' and not lastscale):
207
+ if onnumber:
208
+ # Flush the current number we are building
209
+ curstring += repr(result + current) + " "
210
+ curstring += word + " "
211
+ result = current = 0
212
+ onnumber = False
213
+ lastunit = False
214
+ lastscale = False
215
+ else:
216
+ scale, increment = from_numword(word)
217
+ onnumber = True
218
+
219
+ if lastunit and (word not in scales):
220
+ # Assume this is part of a string of individual numbers to
221
+ # be flushed, such as a zipcode "one two three four five"
222
+ curstring += repr(result + current)
223
+ result = current = 0
224
+
225
+ if scale > 1:
226
+ current = max(1, current)
227
+
228
+ current = current * scale + increment
229
+ if scale > 100:
230
+ result += current
231
+ current = 0
232
+
233
+ lastscale = False
234
+ lastunit = False
235
+ if word in scales:
236
+ lastscale = True
237
+ elif word in units:
238
+ lastunit = True
239
+
240
+ if onnumber:
241
+ curstring += repr(result + current)
242
+
243
+ return curstring
244
 
 
 
 
 
245
 
246
  # Convert sentence to transcript using Soundex
247
  def sentence_to_transcript(sentence, word_to_code_map):