mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-12-04 15:49:48 +00:00
ucd: support parsing PropertyValueAliases data
This commit is contained in:
+33
-23
@@ -94,39 +94,51 @@ class CodeRange:
|
|||||||
return self.last.codepoint - self.first.codepoint + 1
|
return self.last.codepoint - self.first.codepoint + 1
|
||||||
|
|
||||||
def codepoint(x):
|
def codepoint(x):
|
||||||
if '..' in x:
|
if '..' in x[0]:
|
||||||
return CodeRange(x)
|
return CodeRange(x[0]), x[1:]
|
||||||
if ' ' in x:
|
if ' ' in x:
|
||||||
return [CodePoint(c) for c in x.split()]
|
return [CodePoint(c) for c in x[0].split()], x[1:]
|
||||||
if x == '':
|
if x[0] == '':
|
||||||
return CodePoint('0000')
|
return CodePoint('0000'), x[1:]
|
||||||
return CodePoint(x)
|
return CodePoint(x[0]), x[1:]
|
||||||
|
|
||||||
def string(x):
|
def string(x):
|
||||||
if x == '':
|
if x[0] == '':
|
||||||
return None
|
return None, x[1:]
|
||||||
return x
|
return x[0], x[1:]
|
||||||
|
|
||||||
|
def integer(x):
|
||||||
|
return int(x[0]), x[1:]
|
||||||
|
|
||||||
def boolean(x):
|
def boolean(x):
|
||||||
if x == 'Y':
|
if x[0] == 'Y':
|
||||||
return True
|
return True, x[1:]
|
||||||
return False
|
return False, x[1:]
|
||||||
|
|
||||||
def script(x):
|
def script(x):
|
||||||
return script_map[x]
|
return script_map[x[0]], x[1:]
|
||||||
|
|
||||||
|
def strlist(x):
|
||||||
|
return x, []
|
||||||
|
|
||||||
data_items = {
|
data_items = {
|
||||||
'Blocks': [
|
'Blocks': [
|
||||||
('Range', codepoint),
|
('Range', codepoint),
|
||||||
('Name', str)
|
('Name', string)
|
||||||
],
|
],
|
||||||
'DerivedAge': [
|
'DerivedAge': [
|
||||||
('Range', codepoint),
|
('Range', codepoint),
|
||||||
('Age', str),
|
('Age', string),
|
||||||
],
|
],
|
||||||
'PropList': [
|
'PropList': [
|
||||||
('Range', codepoint),
|
('Range', codepoint),
|
||||||
('Property', str),
|
('Property', string),
|
||||||
|
],
|
||||||
|
'PropertyValueAliases': [
|
||||||
|
('Property', string),
|
||||||
|
('Key', string),
|
||||||
|
('Value', string),
|
||||||
|
('Aliases', strlist),
|
||||||
],
|
],
|
||||||
'Scripts': [
|
'Scripts': [
|
||||||
('Range', codepoint),
|
('Range', codepoint),
|
||||||
@@ -136,7 +148,7 @@ data_items = {
|
|||||||
('CodePoint', codepoint),
|
('CodePoint', codepoint),
|
||||||
('Name', string),
|
('Name', string),
|
||||||
('GeneralCategory', string),
|
('GeneralCategory', string),
|
||||||
('CanonicalCombiningClass', int),
|
('CanonicalCombiningClass', integer),
|
||||||
('BidiClass', string),
|
('BidiClass', string),
|
||||||
('DecompositionType', string),
|
('DecompositionType', string),
|
||||||
('DecompositionMapping', string),
|
('DecompositionMapping', string),
|
||||||
@@ -152,7 +164,7 @@ data_items = {
|
|||||||
# Supplemental Data:
|
# Supplemental Data:
|
||||||
'Klingon': [
|
'Klingon': [
|
||||||
('CodePoint', codepoint),
|
('CodePoint', codepoint),
|
||||||
('Script', str),
|
('Script', string),
|
||||||
('GeneralCategory', string),
|
('GeneralCategory', string),
|
||||||
('Name', string),
|
('Name', string),
|
||||||
('Transliteration', string),
|
('Transliteration', string),
|
||||||
@@ -166,7 +178,7 @@ def parse_ucd_data(ucd_rootdir, dataset):
|
|||||||
for line in f:
|
for line in f:
|
||||||
line = line.replace('\n', '').split('#')[0]
|
line = line.replace('\n', '').split('#')[0]
|
||||||
linedata = [' '.join(x.split()) for x in line.split(';')]
|
linedata = [' '.join(x.split()) for x in line.split(';')]
|
||||||
if len(linedata) == len(keys):
|
if len(linedata) > 1:
|
||||||
if linedata[1].endswith(', First>'):
|
if linedata[1].endswith(', First>'):
|
||||||
first = linedata
|
first = linedata
|
||||||
continue
|
continue
|
||||||
@@ -177,10 +189,8 @@ def parse_ucd_data(ucd_rootdir, dataset):
|
|||||||
first = None
|
first = None
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
for keydata, value in zip(keys, linedata):
|
for key, typemap in keys:
|
||||||
key, typemap = keydata
|
data[key], linedata = typemap(linedata)
|
||||||
if key:
|
|
||||||
data[key] = typemap(value)
|
|
||||||
yield data
|
yield data
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user