Conversion Of Roman Numerals
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
It can be a little touchy, but can take a look at improving its handling; or welcome a PR
Hi @remsky, can i take a look at it and I will open PR on it?
Hey @i-rahulkashyap that would be great
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).
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?
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
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!
@remsky
Sorry, i wasnt able to see the response due to notifications were off. Let me know if it's still open.
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.
Sure @remsky, thanks. I will do my POC on it and share my findings.