jitenbot/bot/expressions.py

24 lines
682 B
Python
Raw Normal View History

import re
def expand_shouryaku(shouryaku):
"""Return a list of words described by a 省略 notation.
eg. "有(り)合(わ)せ" -> [
2023-04-23 02:01:52 +00:00
"有り合わせ", "有合わせ", "有り合せ", "有合せ"
]
"""
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