cdactvm commited on
Commit
9eb3cf7
·
verified ·
1 Parent(s): cb9e139

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -55
app.py CHANGED
@@ -164,70 +164,70 @@ def text2int(textnum, numwords={}):
164
  lastunit = False
165
  lastscale = False
166
 
167
- def is_numword(x):
168
- if is_number(x):
169
- return True
170
- if word in numwords:
171
- return True
172
- return False
173
-
174
- def from_numword(x):
175
- if is_number(x):
176
- scale = 0
177
- increment = int(x.replace(',', ''))
178
- return scale, increment
179
- return numwords[x]
180
-
181
- for word in textnum.split():
182
- if word in ordinal_words:
183
- scale, increment = (1, ordinal_words[word])
184
- current = current * scale + increment
185
- if scale > 100:
186
- result += current
187
- current = 0
188
- onnumber = True
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  lastunit = False
190
  lastscale = False
191
  else:
192
- for ending, replacement in ordinal_endings:
193
- if word.endswith(ending):
194
- word = "%s%s" % (word[:-len(ending)], replacement)
195
-
196
- if (not is_numword(word)) or (word == 'and' and not lastscale):
197
- if onnumber:
198
- curstring += repr(result + current) + " "
199
- curstring += word + " "
200
- result = current = 0
201
- onnumber = False
202
- lastunit = False
203
- lastscale = False
204
- else:
205
- scale, increment = from_numword(word)
206
- onnumber = True
207
 
208
- if lastunit and (word not in scales):
209
- curstring += repr(result + current)
210
- result = current = 0
211
 
212
- if scale > 1:
213
- current = max(1, current)
214
 
215
- current = current * scale + increment
216
- if scale > 100:
217
- result += current
218
- current = 0
219
 
220
- lastscale = False
221
- lastunit = False
222
- if word in scales:
223
- lastscale = True
224
- elif word in units:
225
- lastunit = True
226
 
227
- if onnumber:
228
- curstring += repr(result + current)
229
 
230
- return curstring
231
 
232
  # Convert sentence to transcript using Soundex
233
  def sentence_to_transcript(sentence, word_to_code_map):
 
164
  lastunit = False
165
  lastscale = False
166
 
167
+ def is_numword(x):
168
+ if is_number(x):
169
+ return True
170
+ if word in numwords:
171
+ return True
172
+ return False
173
+
174
+ def from_numword(x):
175
+ if is_number(x):
176
+ scale = 0
177
+ increment = int(x.replace(',', ''))
178
+ return scale, increment
179
+ return numwords[x]
180
+
181
+ for word in textnum.split():
182
+ if word in ordinal_words:
183
+ scale, increment = (1, ordinal_words[word])
184
+ current = current * scale + increment
185
+ if scale > 100:
186
+ result += current
187
+ current = 0
188
+ onnumber = True
189
+ lastunit = False
190
+ lastscale = False
191
+ else:
192
+ for ending, replacement in ordinal_endings:
193
+ if word.endswith(ending):
194
+ word = "%s%s" % (word[:-len(ending)], replacement)
195
+
196
+ if (not is_numword(word)) or (word == 'and' and not lastscale):
197
+ if onnumber:
198
+ curstring += repr(result + current) + " "
199
+ curstring += word + " "
200
+ result = current = 0
201
+ onnumber = False
202
  lastunit = False
203
  lastscale = False
204
  else:
205
+ scale, increment = from_numword(word)
206
+ onnumber = True
 
 
 
 
 
 
 
 
 
 
 
 
 
207
 
208
+ if lastunit and (word not in scales):
209
+ curstring += repr(result + current)
210
+ result = current = 0
211
 
212
+ if scale > 1:
213
+ current = max(1, current)
214
 
215
+ current = current * scale + increment
216
+ if scale > 100:
217
+ result += current
218
+ current = 0
219
 
220
+ lastscale = False
221
+ lastunit = False
222
+ if word in scales:
223
+ lastscale = True
224
+ elif word in units:
225
+ lastunit = True
226
 
227
+ if onnumber:
228
+ curstring += repr(result + current)
229
 
230
+ return curstring
231
 
232
  # Convert sentence to transcript using Soundex
233
  def sentence_to_transcript(sentence, word_to_code_map):