jitenbot/bot/util.py
2023-04-11 12:01:23 -05:00

27 lines
706 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
def expand_shouryaku(shouryaku):
"""Return a list of words described by a 省略 notation.
eg. "有(り)合(わ)せ" -> [
"有り合わせ",
"有合わせ",
"有り合せ",
"有合せ"
]
"""
groups = re.findall(r"([^]*)(([^]+))?", shouryaku)
forms = [""]
for group in groups:
new_forms = []
for form in forms:
new_forms.append(form + group[0])
forms = new_forms.copy()
if group[2] == '':
continue
new_forms = []
for form in forms:
new_forms.append(form + group[2])
forms = new_forms.copy() + forms.copy()
return forms