Kokoro-FastAPI icon indicating copy to clipboard operation
Kokoro-FastAPI copied to clipboard

Conversion Of Roman Numerals

Open mark007 opened this issue 2 months ago • 10 comments

Describe the feature you'd like I wonder is it possible for this repo to help with conversion of roman numerals to numbers which kokoro can understand.

eg World War II is currently read as World War I (the letter) and I (the letter) rather than World War 2.

Describe alternatives you've considered I guess I could give instructions to my calls to openai to respond without any use of roman numerals as a workaround.

Additional context na

mark007 avatar Sep 10 '26 09:09 mark007

It can be a little touchy, but can take a look at improving its handling; or welcome a PR

remsky avatar Sep 20 '26 05:09 remsky

Hi @remsky, can i take a look at it and I will open PR on it?

i-rahulkashyap avatar Sep 22 '26 22:09 i-rahulkashyap

Hey @i-rahulkashyap that would be great

remsky avatar Sep 30 '26 08:09 remsky

The repo only protects Roman numerals from being lowercased (ROMAN_PATTERN in normalization/english.py). It never converts them. A context-gated pass fits as a new step in pass_order() in normalization/base.py. Converting every all-caps token breaks "I", "MIX", "DID", "MD" and "DC", so convert only after labels (Chapter, Part, World War), after regnal names, and before "century". inflect is already a dependency:

import re, inflect
p = inflect.engine()
R = r"M{0,3}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3})"
V = dict(I=1, V=5, X=10, L=50, C=100, D=500, M=1000)
def val(s): return sum(-V[a] if V.get(b, 0) > V[a] else V[a] for a, b in zip(s, s[1:] + " "))
def roman(text):
    lab = r"(Chapter|Part|Act|Scene|Book|Section|World War|Super Bowl)"
    roy = r"(Henry|Louis|George|Edward|Charles|Richard|Pius|Leo)"
    text = re.sub(rf"\b{lab} ({R})\b", lambda m: f"{m[1]} {p.number_to_words(val(m[2]))}" if m[2] else m[0], text)
    text = re.sub(rf"\b{roy} ((?=[IVX]{{2}})(?:{R}))\b", lambda m: f"{m[1]} the {p.number_to_words(p.ordinal(val(m[2])))}", text)
    return re.sub(rf"\b((?=[IVX]{{2}})(?:{R})) (centur(?:y|ies))", lambda m: f"{p.number_to_words(p.ordinal(val(m[1])))} {m[2]}", text)

"World War II" becomes "World War two", "Henry VIII" becomes "Henry the eighth". "I", "MIX", "Vitamin C" and "Washington DC" stay unchanged.

Disclosure: I build commercial data tools in this area (details in my GitHub profile).

donmangudata-ops avatar Oct 06 '26 09:10 donmangudata-ops

Hi @remsky, I am a beginner in open source and I would like to contribute to this project. I saw that someone already asked to work on this issue. Is this issue still available, or could you suggest another beginner-friendly issue for me?

se1vapriya avatar Oct 07 '26 08:10 se1vapriya

Hey @se1vapriya

We can see if @i-rahulkashyap responds within a day or so, whether they're in progress on it or would want to collaborate,

Otherwise, I'll add and tag a couple as good-first-issue tomorrow and ping you, cheers

remsky avatar Oct 07 '26 09:10 remsky

Thank you so much for your response, @remsky!

I really appreciate your support. I'm happy to wait and would love to work on a beginner-friendly issue when one becomes available.

Looking forward to contributing to Kokoro-FastAPI!

se1vapriya avatar Oct 08 '26 02:10 se1vapriya

@remsky

Sorry, i wasnt able to see the response due to notifications were off. Let me know if it's still open.

i-rahulkashyap avatar Oct 25 '26 14:10 i-rahulkashyap

Hey @i-rahulkashyap, not a problem. I'll tag you as assigned on it

My thoughts: -Should live in EnglishNormalizer behind a new NormalizationOptions flag -Keep an eye that words like "I", "CD" and "MIX" pass through/ only numbers are getting converted. -Add a ReDoS flood test case for any new regex.

remsky avatar Nov 04 '26 19:11 remsky

Sure @remsky, thanks. I will do my POC on it and share my findings.

i-rahulkashyap avatar Nov 04 '26 19:11 i-rahulkashyap