allo-media / text2num

Parse and convert numbers written in French, English, Spanish, Portuguese, German and Catalan into their digit representation.
https://text2num.readthedocs.io
MIT License
102 stars 47 forks source link

Carrying last word context forward in a segment #103

Closed skiingpacman closed 11 months ago

skiingpacman commented 11 months ago

The "last word" context wasn't carried forward within a segment after a number (digits or ordinal) was resolved. This resulted in phrases like the "sixth one" being transposed to the "6th 1". This is in English. This change fixes this so now: alpha2digit("the sixth one", "en") --> "the 6th one"

>>> from text_to_num import alpha2digit
>>> alpha2digit("the sixth one", "en")
'the 6th one'
>>> alpha2digit("sixth one", "en")
'6th one'
>>> alpha2digit("six one", "en")
'6 1'
>>> alpha2digit("the sixth. one", "en")
'the 6th. 1'
skiingpacman commented 11 months ago

Addresses issue https://github.com/allo-media/text2num/issues/101

rtxm commented 11 months ago

Thank you for your contribution.