Better alphabet access
This commit is contained in:
parent
3424ab2b5d
commit
010f24578f
@ -159,13 +159,7 @@ def read_token(token):
|
||||
|
||||
|
||||
def in_alphabet(alphabet, c):
|
||||
if alphabet is None:
|
||||
return False
|
||||
try:
|
||||
alphabet.label_from_string(c)
|
||||
return True
|
||||
except KeyError:
|
||||
return False
|
||||
return True if alphabet is None else alphabet.has_char(c)
|
||||
|
||||
|
||||
alphabets = {}
|
||||
@ -200,7 +194,7 @@ def label_filter(label, language):
|
||||
.encode("ascii", "ignore")
|
||||
.decode("ascii", "ignore"))
|
||||
for sc in c:
|
||||
if alphabet is not None and not in_alphabet(alphabet, sc):
|
||||
if not in_alphabet(alphabet, sc):
|
||||
return None, 'illegal character'
|
||||
chars.append(sc)
|
||||
label = ''.join(chars)
|
||||
|
@ -36,6 +36,9 @@ class Alphabet(object):
|
||||
'then add all these to data/alphabet.txt.'.format(string)
|
||||
).with_traceback(e.__traceback__)
|
||||
|
||||
def has_char(self, char):
|
||||
return char in self._str_to_label
|
||||
|
||||
def encode(self, string):
|
||||
res = []
|
||||
for char in string:
|
||||
|
Loading…
x
Reference in New Issue
Block a user