Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# The first rule which matches is retained
rule_th = [Rule(AbstractPosition(Rank.first, None, []), th, th),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=True)]), th, th),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=True)], []), th, th),
Rule(AbstractPosition(Rank.inner, [], []), th, dh),
Rule(AbstractPosition(Rank.last, [], None), th, dh)]
rule_f = [Rule(AbstractPosition(Rank.first, None, []), f, f),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=False)]), f, f),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=False)], []), f, f),
Rule(AbstractPosition(Rank.inner, [], []), f, v),
Rule(AbstractPosition(Rank.last, [], None), f, v)]
rule_g = [Rule(AbstractPosition(Rank.first, None, None), g, g),
Rule(AbstractPosition(Rank.inner, [n.to_abstract()], None), g, g),
Rule(AbstractPosition(Rank.inner, None, [AbstractConsonant(voiced=False)]), g, k),
Rule(AbstractPosition(Rank.inner, [], []), g, gh),
Rule(AbstractPosition(Rank.last, [], None), g, gh)]
old_norse_rules = []
old_norse_rules.extend(rule_f)
old_norse_rules.extend(rule_g)
old_norse_rules.extend(rule_th)
def measure_old_norse_syllable(syllable: list) -> Union[Length, None]:
"""
Old Norse syllables are considered as:
- short if
- long if
- overlong if
"kk": "kː",
"ll": "lː",
"mm": "mː",
"nn": "nː",
"pp": "pː",
"rr": "rː",
"ss": "sː",
"tt": "tː",
"vv": "vː",
}
# Some Old Norse rules
# The first rule which matches is retained
rule_th = [Rule(AbstractPosition(Rank.first, None, []), th, th),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=True)]), th, th),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=True)], []), th, th),
Rule(AbstractPosition(Rank.inner, [], []), th, dh),
Rule(AbstractPosition(Rank.last, [], None), th, dh)]
rule_f = [Rule(AbstractPosition(Rank.first, None, []), f, f),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=False)]), f, f),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=False)], []), f, f),
Rule(AbstractPosition(Rank.inner, [], []), f, v),
Rule(AbstractPosition(Rank.last, [], None), f, v)]
rule_g = [Rule(AbstractPosition(Rank.first, None, None), g, g),
Rule(AbstractPosition(Rank.inner, [n.to_abstract()], None), g, g),
Rule(AbstractPosition(Rank.inner, None, [AbstractConsonant(voiced=False)]), g, k),
Rule(AbstractPosition(Rank.inner, [], []), g, gh),
Rule(AbstractPosition(Rank.last, [], None), g, gh)]
old_norse_rules = []
# Some Old Norse rules
# The first rule which matches is retained
rule_th = [Rule(AbstractPosition(Rank.first, None, []), th, th),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=True)]), th, th),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=True)], []), th, th),
Rule(AbstractPosition(Rank.inner, [], []), th, dh),
Rule(AbstractPosition(Rank.last, [], None), th, dh)]
rule_f = [Rule(AbstractPosition(Rank.first, None, []), f, f),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=False)]), f, f),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=False)], []), f, f),
Rule(AbstractPosition(Rank.inner, [], []), f, v),
Rule(AbstractPosition(Rank.last, [], None), f, v)]
rule_g = [Rule(AbstractPosition(Rank.first, None, None), g, g),
Rule(AbstractPosition(Rank.inner, [n.to_abstract()], None), g, g),
Rule(AbstractPosition(Rank.inner, None, [AbstractConsonant(voiced=False)]), g, k),
Rule(AbstractPosition(Rank.inner, [], []), g, gh),
Rule(AbstractPosition(Rank.last, [], None), g, gh)]
old_norse_rules = []
old_norse_rules.extend(rule_f)
old_norse_rules.extend(rule_g)
old_norse_rules.extend(rule_th)
def measure_old_norse_syllable(syllable: list) -> Union[Length, None]:
"""
Old Norse syllables are considered as:
- short if
- long if
"vv": "vː",
}
# Some Old Norse rules
# The first rule which matches is retained
rule_th = [Rule(AbstractPosition(Rank.first, None, []), th, th),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=True)]), th, th),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=True)], []), th, th),
Rule(AbstractPosition(Rank.inner, [], []), th, dh),
Rule(AbstractPosition(Rank.last, [], None), th, dh)]
rule_f = [Rule(AbstractPosition(Rank.first, None, []), f, f),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=False)]), f, f),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=False)], []), f, f),
Rule(AbstractPosition(Rank.inner, [], []), f, v),
Rule(AbstractPosition(Rank.last, [], None), f, v)]
rule_g = [Rule(AbstractPosition(Rank.first, None, None), g, g),
Rule(AbstractPosition(Rank.inner, [n.to_abstract()], None), g, g),
Rule(AbstractPosition(Rank.inner, None, [AbstractConsonant(voiced=False)]), g, k),
Rule(AbstractPosition(Rank.inner, [], []), g, gh),
Rule(AbstractPosition(Rank.last, [], None), g, gh)]
old_norse_rules = []
old_norse_rules.extend(rule_f)
old_norse_rules.extend(rule_g)
old_norse_rules.extend(rule_th)
def measure_old_norse_syllable(syllable: list) -> Union[Length, None]:
"""
Old Norse syllables are considered as:
"ff": "fː",
"gg": "gː",
"kk": "kː",
"ll": "lː",
"mm": "mː",
"nn": "nː",
"pp": "pː",
"rr": "rː",
"ss": "sː",
"tt": "tː",
"vv": "vː",
}
# Some Old Norse rules
# The first rule which matches is retained
rule_th = [Rule(AbstractPosition(Rank.first, None, []), th, th),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=True)]), th, th),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=True)], []), th, th),
Rule(AbstractPosition(Rank.inner, [], []), th, dh),
Rule(AbstractPosition(Rank.last, [], None), th, dh)]
rule_f = [Rule(AbstractPosition(Rank.first, None, []), f, f),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=False)]), f, f),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=False)], []), f, f),
Rule(AbstractPosition(Rank.inner, [], []), f, v),
Rule(AbstractPosition(Rank.last, [], None), f, v)]
rule_g = [Rule(AbstractPosition(Rank.first, None, None), g, g),
Rule(AbstractPosition(Rank.inner, [n.to_abstract()], None), g, g),
Rule(AbstractPosition(Rank.inner, None, [AbstractConsonant(voiced=False)]), g, k),
Rule(AbstractPosition(Rank.inner, [], []), g, gh),
Rule(AbstractPosition(Rank.last, [], None), g, gh)]
before = self.before
else:
before = []
before.extend(self.before)
before.extend(other.before)
if self.after is None and other.after is None:
after = None
elif self.after is None:
after = other.after
elif other.after is None:
after = self.after
else:
after = []
after.extend(self.after)
after.extend(other.after)
return AbstractPosition(self.position, before, after)
core_search = re.search(core_pattern, re_rule)
after_search = re.search(after_pattern, re_rule)
if before_search is None:
before = None
else:
before = [ipa_class[ipar].to_abstract() for ipar in before_search.group(0)]
if core_search is not None:
core = ipa_class[core_search.group(0)]
else:
logger.error("No core")
raise ValueError
if after_search is None:
after = None
else:
after = [ipa_class[ipar].to_abstract() for ipar in after_search.group(0)]
abstract_position = AbstractPosition(place, before, after)
return Rule(abstract_position, core, ipa_class[estimated_sound])
# Some Old Norse rules
# The first rule which matches is retained
rule_th = [Rule(AbstractPosition(Rank.first, None, []), th, th),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=True)]), th, th),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=True)], []), th, th),
Rule(AbstractPosition(Rank.inner, [], []), th, dh),
Rule(AbstractPosition(Rank.last, [], None), th, dh)]
rule_f = [Rule(AbstractPosition(Rank.first, None, []), f, f),
Rule(AbstractPosition(Rank.inner, [], [AbstractConsonant(voiced=False)]), f, f),
Rule(AbstractPosition(Rank.inner, [AbstractConsonant(voiced=False)], []), f, f),
Rule(AbstractPosition(Rank.inner, [], []), f, v),
Rule(AbstractPosition(Rank.last, [], None), f, v)]
rule_g = [Rule(AbstractPosition(Rank.first, None, None), g, g),
Rule(AbstractPosition(Rank.inner, [n.to_abstract()], None), g, g),
Rule(AbstractPosition(Rank.inner, None, [AbstractConsonant(voiced=False)]), g, k),
Rule(AbstractPosition(Rank.inner, [], []), g, gh),
Rule(AbstractPosition(Rank.last, [], None), g, gh)]
old_norse_rules = []
old_norse_rules.extend(rule_f)
old_norse_rules.extend(rule_g)
old_norse_rules.extend(rule_th)
def measure_old_norse_syllable(syllable: list) -> Union[Length, None]:
"""
Old Norse syllables are considered as:
- short if
- long if
- overlong if
def real_sound_match_abstract_sound(self, abstract_pos: AbstractPosition) -> bool:
"""
If an observed position
:param abstract_pos:
:return:
"""
assert isinstance(abstract_pos, AbstractPosition)
if self.before is not None and self.after is not None:
return self.position == abstract_pos.position and self.before.match_list(abstract_pos.before) and \
self.after.match_list(abstract_pos.after)
elif self.before is None and self.after is None:
return self.position == abstract_pos.position
elif self.before is None:
return self.position == abstract_pos.position and self.after.match_list(abstract_pos.after)
else:
return self.position == abstract_pos.position and self.before.match_list(abstract_pos.before)