|
|
|
bez_diakritiky = ({}
|
|
|
|
# FIXME: funguje jen pro český a slovenský text, jinak jsou špatně
|
|
|
|
# transliterace. Potenciální řešení:
|
|
|
|
# https://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-normalize-in-a-python-unicode-string
|
|
|
|
# (ale přidává to další závislosti…)
|
|
|
|
|
|
|
|
# Tisknutelné ASCII
|
|
|
|
| {chr(a): chr(a) for a in range(32, 126+1)}
|
|
|
|
|
|
|
|
# České, slovenské a blízké diakritiky a divnoznaky
|
|
|
|
| { x: 'a' for x in 'áÁäÄ'}
|
|
|
|
| { x: 'c' for x in 'čČ'}
|
|
|
|
| { x: 'd' for x in 'ďĎ'}
|
|
|
|
| { x: 'e' for x in 'éÉěĚëË'}
|
|
|
|
| { x: 'i' for x in 'íÍ'}
|
|
|
|
| { x: 'l' for x in 'ľĽĺĹ'}
|
|
|
|
| { x: 'n' for x in 'ňŇ'}
|
|
|
|
| { x: 'o' for x in 'óÓöÖôÔ'}
|
|
|
|
| { x: 'r' for x in 'řŘŕŔ'}
|
|
|
|
| { x: 's' for x in 'šŠßẞ'}
|
|
|
|
| { x: 't' for x in 'ťŤ'}
|
|
|
|
| { x: 'u' for x in 'úÚůŮ'}
|
|
|
|
| { x: 'y' for x in 'ýÝ'}
|
|
|
|
| { x: 'z' for x in 'žŽ'}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Tabulka pro str.translate
|
|
|
|
class _bez_diakritiky_translate:
|
|
|
|
def __getitem__(self, it):
|
|
|
|
return ord(bez_diakritiky.get(chr(it), None))
|
|
|
|
bez_diakritiky_translate = _bez_diakritiky_translate()
|
|
|
|
|
|
|
|
# TODO: testy?
|
|
|
|
|
|
|
|
# Pozor: zarovnáno velmi netradičně pro přehlednost
|
|
|
|
roman_numerals = zip((1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
|
|
|
|
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'))
|
|
|
|
|
|
|
|
|
|
|
|
def roman(num):
|
|
|
|
res = ""
|
|
|
|
for i, n in roman_numerals:
|
|
|
|
res += n * (num // i)
|
|
|
|
num %= i
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def from_roman(rom):
|
|
|
|
if not rom:
|
|
|
|
return 0
|
|
|
|
for i, n in roman_numerals:
|
|
|
|
if rom.upper().startswith(n):
|
|
|
|
return i + from_roman(rom[len(n):])
|
|
|
|
raise Exception('Invalid roman numeral: "%s"', rom)
|