就岩阿深处,结层屋,上空蒙。喜着屐穿花,卷帘看雨,拄笏临风。玲珑。夏云一片,隔篱芭、独立舞仙风。睍睕黄鹂个个,阴森绿树重重。吟翁。
无日不诗筒。杯酒尽从容。更罅石盘梅,阳坡护笋,曲坞移松。芙蓉。古台直上,倚高寒、长啸月明中。谁信扁舟苕霅,得游阆苑崆峒。
这首诗是宋代词人陈著在德清县圃爱山亭时所作,全诗共四十六字。下面是对这首诗逐句的翻译:
def translate_poem(line):
# 将拼音转换为汉字
words = line.split(' ')
translated_words = []
for word in words:
if word[0].isalpha(): # 非标点符号
translated_words.append(pinyin_to_hanyu.get(word[0], word))
else:
translated_words.append(word)
return ' '.join(translated_words)
# 诗句释义
def explain_line(line):
words = line.split(' ')
explanation = ''
for i, word in enumerate(words):
if i > 0 and words[i] == words[i-1]: # 如果是重复字或标点符号,则跳过
continue
if len(words) > 1 and words[i] == words[i+1]: # 如果是连续字或标点符号,则添加顿号
explanation += f'{words[i]}, '
if word[0].isalpha(): # 如果是汉字,则添加到解释中
explanation += f'{word} {explain_line(translated_words[-1])}'
return explanation
poem = "木兰花慢 · 德清县圃爱山亭\n就岩阿深处,结层屋,上空蒙。喜着屐穿花,卷帘看雨,拄笏临风。玲珑。夏云一片,隔篱芭、独立舞仙风。睍睕黄鹂个个,阴森绿树重重。吟翁。无日不诗筒。杯酒尽从容。更罅石盘梅,阳坡护笋,曲坞移松。芙蓉。古台直上,倚高寒、长啸月明中。谁信扁舟苕霅,得游阆苑崆峒。"
lines = poem.split('\n')
translations = [translate_poem(line) for line in lines]
explanations = [' '.join(translations[j]) for j in range(len(lines)) if j < len(lines) - 1] + translations[-1]
explanations = [' '.join(explanations).replace('\n', '') for explanation in explanations]
print(explanations)
# 注释
import pypinyin
# 将拼音转换为汉字
def translate_poem(line):
words = line.split(' ')
translated_words = []
for word in words:
if word[0].isalpha(): # 非标点符号
translated_words.append(pypinyin_to_hanyu.get(word[0], word))
else:
translated_words.append(word)
return ' '.join(translated_words)
# 诗句释义
def explain_line(line):
words = line.split(' ')
explanation = ''
for i, word in enumerate(words):
if i > 0 and words[i] == words[i-1]: # 如果是重复字或标点符号,则跳过
continue
if len(words) > 1 and words[i] == words[i+1]: # 如果是连续字或标点符号,则添加顿号
explanation += f'{words[i]}, '
if word[0].isalpha(): # 如果是汉字,则添加到解释中
explanation += f'{word} {explain_line(translated_words[-1])}'
return explanation
poem = "木兰花慢 · 德清县圃爱山亭\n就岩阿深处,结层屋,上空蒙。喜着屐穿花,卷帘看雨,拄笏临风。玲珑。夏云一片,隔篱芭、独立舞仙风。睍睕黄鹂个个,阴森绿树重重。吟翁。无日不诗筒。杯酒尽从容。更罅石盘梅,阳坡护笋,曲坞移松。芙蓉。古台直上,倚高寒、长啸月明中。谁信扁舟苕霅,得游阆苑崆峒。"
lines = poem.split('\n')
translations = [translate_poem(line) for line in lines]
explanations = [' '.join(translations[j]) for j in range(len(lines)) if j < len(lines) - 1] + translations[-1]
for explanation in explanations:
print(explanation)