Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -164,70 +164,70 @@ def text2int(textnum, numwords={}):
|
|
164 |
lastunit = False
|
165 |
lastscale = False
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
lastunit = False
|
190 |
lastscale = False
|
191 |
else:
|
192 |
-
|
193 |
-
|
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 |
-
|
209 |
-
|
210 |
-
|
211 |
|
212 |
-
|
213 |
-
|
214 |
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
|
227 |
-
|
228 |
-
|
229 |
|
230 |
-
|
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):
|