Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
pos_match = True
if not (character_match and pos_match):
continue
# determine if jyutping matches c_jyutping
jyutping_match = False
if not jp_search:
jyutping_match = True
elif not c_jyutping:
pass
else:
try:
c_parsed_jyutpings = parse_jyutping(c_jyutping)
except ValueError:
continue
for c_parsed_jyutping in c_parsed_jyutpings:
booleans = [
_jp_element_match(search_, current_)
for search_, current_ in zip(
jp_search_tuple, c_parsed_jyutping
)
]
if all(booleans):
jyutping_match = True
break
def jyutping2yale(jp_str, as_list=False):
"""
Convert *jp_str* to Yale.
:param as_list: If True (default: False), return a list of Yale strings
for individual syllables.
"""
jp_parsed_list = parse_jyutping(jp_str)
yale_list = []
for jp_parsed in jp_parsed_list:
onset = ONSETS_YALE[jp_parsed[0]]
nucleus = NUCLEI_YALE[jp_parsed[1]]
coda = CODAS_YALE[jp_parsed[2]]
tone = jp_parsed[3] # still in parse_jyutping
# jyutping2yale system uses "h" to mark the three low tones
if tone in {"4", "5", "6"}:
low_tone_h = "h"
else:
low_tone_h = ""
# in jyutping2yale, long "aa" vowel with no coda is denoted by "a"
if nucleus == "aa" and coda == "":
def jyutping2tipa(jp_str):
"""
Convert *jp_str* to a list of LaTeX TIPA strings.
"""
jp_parsed_list = parse_jyutping(jp_str)
tipa_list = []
for jp_parsed in jp_parsed_list:
onset = jp_parsed[0]
# TODO: Separate "final" as "nucleus" and "coda" instead?
final = jp_parsed[1] + jp_parsed[2]
tone = jp_parsed[3]
tipa = ONSETS_TIPA[onset] + FINALS_TIPA[final]
tipa = tipa.strip() + TONES_TIPA[tone]
tipa_list.append(tipa)
return tipa_list
if jyutping and (onset or final or nucleus or coda or tone):
raise ValueError(
"jyutping cannot be used together with other "
"Jyutping elements"
)
if (onset != initial) and onset and initial:
raise ValueError("onset conflicts with initial")
# onset/initial
if initial:
onset = initial
# determine jp_search_tuple
if jyutping:
try:
jp_search_list = parse_jyutping(jyutping)
except ValueError:
raise ValueError("invalid jyutping -- %s" % (repr(jyutping)))
if len(jp_search_list) > 1:
raise ValueError("only jyutping for one character is allowed")
else:
jp_search_tuple = jp_search_list[0]
else:
if final:
nucleus, coda = parse_final(final)
jp_search_tuple = (onset, nucleus, coda, tone)
fn_to_results = {}
for fn, tagged_sents in fn_to_tagged_sents.items():
sent_word_index_pairs = []