|
|
@ -41,30 +41,32 @@ class ToneSandhi():
|
|
|
|
'棺材', '棒槌', '棉花', '核桃', '栅栏', '柴火', '架势', '枕头', '枇杷', '机灵', '本事',
|
|
|
|
'棺材', '棒槌', '棉花', '核桃', '栅栏', '柴火', '架势', '枕头', '枇杷', '机灵', '本事',
|
|
|
|
'木头', '木匠', '朋友', '月饼', '月亮', '暖和', '明白', '时候', '新鲜', '故事', '收拾',
|
|
|
|
'木头', '木匠', '朋友', '月饼', '月亮', '暖和', '明白', '时候', '新鲜', '故事', '收拾',
|
|
|
|
'收成', '提防', '挖苦', '挑剔', '指甲', '指头', '拾掇', '拳头', '拨弄', '招牌', '招呼',
|
|
|
|
'收成', '提防', '挖苦', '挑剔', '指甲', '指头', '拾掇', '拳头', '拨弄', '招牌', '招呼',
|
|
|
|
'抬举', '护士', '折腾', '扫帚', '打量', '打算', '打点', '打扮', '打听', '打发', '扎实',
|
|
|
|
'抬举', '护士', '折腾', '扫帚', '打量', '打算', '打扮', '打听', '打发', '扎实', '扁担',
|
|
|
|
'扁担', '戒指', '懒得', '意识', '意思', '情形', '悟性', '怪物', '思量', '怎么', '念头',
|
|
|
|
'戒指', '懒得', '意识', '意思', '情形', '悟性', '怪物', '思量', '怎么', '念头', '念叨',
|
|
|
|
'念叨', '快活', '忙活', '志气', '心思', '得罪', '张罗', '弟兄', '开通', '应酬', '庄稼',
|
|
|
|
'快活', '忙活', '志气', '心思', '得罪', '张罗', '弟兄', '开通', '应酬', '庄稼', '干事',
|
|
|
|
'干事', '帮手', '帐篷', '希罕', '师父', '师傅', '巴结', '巴掌', '差事', '工夫', '岁数',
|
|
|
|
'帮手', '帐篷', '希罕', '师父', '师傅', '巴结', '巴掌', '差事', '工夫', '岁数', '屁股',
|
|
|
|
'屁股', '尾巴', '少爷', '小气', '小伙', '将就', '对头', '对付', '寡妇', '家伙', '客气',
|
|
|
|
'尾巴', '少爷', '小气', '小伙', '将就', '对头', '对付', '寡妇', '家伙', '客气', '实在',
|
|
|
|
'实在', '官司', '学问', '学生', '字号', '嫁妆', '媳妇', '媒人', '婆家', '娘家', '委屈',
|
|
|
|
'官司', '学问', '字号', '嫁妆', '媳妇', '媒人', '婆家', '娘家', '委屈', '姑娘', '姐夫',
|
|
|
|
'姑娘', '姐夫', '妯娌', '妥当', '妖精', '奴才', '女婿', '头发', '太阳', '大爷', '大方',
|
|
|
|
'妯娌', '妥当', '妖精', '奴才', '女婿', '头发', '太阳', '大爷', '大方', '大意', '大夫',
|
|
|
|
'大意', '大夫', '多少', '多么', '外甥', '壮实', '地道', '地方', '在乎', '困难', '嘴巴',
|
|
|
|
'多少', '多么', '外甥', '壮实', '地道', '地方', '在乎', '困难', '嘴巴', '嘱咐', '嘟囔',
|
|
|
|
'嘱咐', '嘟囔', '嘀咕', '喜欢', '喇嘛', '喇叭', '商量', '唾沫', '哑巴', '哈欠', '哆嗦',
|
|
|
|
'嘀咕', '喜欢', '喇嘛', '喇叭', '商量', '唾沫', '哑巴', '哈欠', '哆嗦', '咳嗽', '和尚',
|
|
|
|
'咳嗽', '和尚', '告诉', '告示', '含糊', '吓唬', '后头', '名字', '名堂', '合同', '吆喝',
|
|
|
|
'告诉', '告示', '含糊', '吓唬', '后头', '名字', '名堂', '合同', '吆喝', '叫唤', '口袋',
|
|
|
|
'叫唤', '口袋', '厚道', '厉害', '千斤', '包袱', '包涵', '匀称', '勤快', '动静', '动弹',
|
|
|
|
'厚道', '厉害', '千斤', '包袱', '包涵', '匀称', '勤快', '动静', '动弹', '功夫', '力气',
|
|
|
|
'功夫', '力气', '前头', '刺猬', '刺激', '别扭', '利落', '利索', '利害', '分析', '出息',
|
|
|
|
'前头', '刺猬', '刺激', '别扭', '利落', '利索', '利害', '分析', '出息', '凑合', '凉快',
|
|
|
|
'凑合', '凉快', '冷战', '冤枉', '冒失', '养活', '关系', '先生', '兄弟', '便宜', '使唤',
|
|
|
|
'冷战', '冤枉', '冒失', '养活', '关系', '先生', '兄弟', '便宜', '使唤', '佩服', '作坊',
|
|
|
|
'佩服', '作坊', '体面', '位置', '似的', '伙计', '休息', '什么', '人家', '亲戚', '亲家',
|
|
|
|
'体面', '位置', '似的', '伙计', '休息', '什么', '人家', '亲戚', '亲家', '交情', '云彩',
|
|
|
|
'交情', '云彩', '事情', '买卖', '主意', '丫头', '丧气', '两口', '东西', '东家', '世故',
|
|
|
|
'事情', '买卖', '主意', '丫头', '丧气', '两口', '东西', '东家', '世故', '不由', '下水',
|
|
|
|
'不由', '不在', '下水', '下巴', '上头', '上司', '丈夫', '丈人', '一辈', '那个', '菩萨',
|
|
|
|
'下巴', '上头', '上司', '丈夫', '丈人', '一辈', '那个', '菩萨', '父亲', '母亲', '咕噜',
|
|
|
|
'父亲', '母亲', '咕噜', '邋遢', '费用', '冤家', '甜头', '介绍', '荒唐', '大人', '泥鳅',
|
|
|
|
'邋遢', '费用', '冤家', '甜头', '介绍', '荒唐', '大人', '泥鳅', '幸福', '熟悉', '计划',
|
|
|
|
'幸福', '熟悉', '计划', '扑腾', '蜡烛', '姥爷', '照顾', '喉咙', '吉他', '弄堂', '蚂蚱',
|
|
|
|
'扑腾', '蜡烛', '姥爷', '照顾', '喉咙', '吉他', '弄堂', '蚂蚱', '凤凰', '拖沓', '寒碜',
|
|
|
|
'凤凰', '拖沓', '寒碜', '糟蹋', '倒腾', '报复', '逻辑', '盘缠', '喽啰', '牢骚', '咖喱',
|
|
|
|
'糟蹋', '倒腾', '报复', '逻辑', '盘缠', '喽啰', '牢骚', '咖喱', '扫把', '惦记', '戏弄',
|
|
|
|
'扫把', '惦记'
|
|
|
|
'将军', '别人'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.must_not_neural_tone_words = {
|
|
|
|
self.must_not_neural_tone_words = {
|
|
|
|
"男子", "女子", "分子", "原子", "量子", "莲子", "石子", "瓜子", "电子", "人人", "虎虎",
|
|
|
|
'男子', '女子', '分子', '原子', '量子', '莲子', '石子', '瓜子', '电子', '人人', '虎虎',
|
|
|
|
"幺幺"
|
|
|
|
'幺幺', '干嘛', '学子', '哈哈', '数数', '袅袅', '局地', '以下', '娃哈哈', '花花草草', '留得',
|
|
|
|
|
|
|
|
'耕地', '想想', '熙熙', '攘攘', '卵子', '死死', '冉冉', '恳恳', '佼佼', '吵吵', '打打',
|
|
|
|
|
|
|
|
'考考', '整整', '莘莘'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.punc = ":,;。?!“”‘’':,;.?!"
|
|
|
|
self.punc = ":,;。?!“”‘’':,;.?!"
|
|
|
|
|
|
|
|
|
|
|
@ -75,27 +77,24 @@ class ToneSandhi():
|
|
|
|
# finals: ['ia1', 'i3']
|
|
|
|
# finals: ['ia1', 'i3']
|
|
|
|
def _neural_sandhi(self, word: str, pos: str,
|
|
|
|
def _neural_sandhi(self, word: str, pos: str,
|
|
|
|
finals: List[str]) -> List[str]:
|
|
|
|
finals: List[str]) -> List[str]:
|
|
|
|
|
|
|
|
if word in self.must_not_neural_tone_words:
|
|
|
|
|
|
|
|
return finals
|
|
|
|
# reduplication words for n. and v. e.g. 奶奶, 试试, 旺旺
|
|
|
|
# reduplication words for n. and v. e.g. 奶奶, 试试, 旺旺
|
|
|
|
for j, item in enumerate(word):
|
|
|
|
for j, item in enumerate(word):
|
|
|
|
if j - 1 >= 0 and item == word[j - 1] and pos[0] in {
|
|
|
|
if j - 1 >= 0 and item == word[j - 1] and pos[0] in {"n", "v", "a"}:
|
|
|
|
"n", "v", "a"
|
|
|
|
|
|
|
|
} and word not in self.must_not_neural_tone_words:
|
|
|
|
|
|
|
|
finals[j] = finals[j][:-1] + "5"
|
|
|
|
finals[j] = finals[j][:-1] + "5"
|
|
|
|
ge_idx = word.find("个")
|
|
|
|
ge_idx = word.find("个")
|
|
|
|
if len(word) >= 1 and word[-1] in "吧呢哈啊呐噻嘛吖嗨呐哦哒额滴哩哟喽啰耶喔诶":
|
|
|
|
if len(word) >= 1 and word[-1] in "吧呢啊呐噻嘛吖嗨呐哦哒额滴哩哟喽啰耶喔诶":
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
elif len(word) >= 1 and word[-1] in "的地得":
|
|
|
|
elif len(word) >= 1 and word[-1] in "的地得":
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
# e.g. 走了, 看着, 去过
|
|
|
|
# e.g. 走了, 看着, 去过
|
|
|
|
elif len(word) == 1 and word in "了着过" and pos in {"ul", "uz", "ug"}:
|
|
|
|
elif len(word) == 1 and word in "了着过" and pos in {"ul", "uz", "ug"}:
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
elif len(word) > 1 and word[-1] in "们子" and pos in {
|
|
|
|
elif len(word) > 1 and word[-1] in "们子" and pos in {"r", "n"}:
|
|
|
|
"r", "n"
|
|
|
|
|
|
|
|
} and word not in self.must_not_neural_tone_words:
|
|
|
|
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
# e.g. 桌上, 地下, 家里
|
|
|
|
# e.g. 桌上, 地下
|
|
|
|
elif len(word) > 1 and word[-1] in "上下里" and pos in {"s", "l", "f"}:
|
|
|
|
elif len(word) > 1 and word[-1] in "上下" and pos in {"s", "l", "f"}:
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
finals[-1] = finals[-1][:-1] + "5"
|
|
|
|
# e.g. 上来, 下去
|
|
|
|
# e.g. 上来, 下去
|
|
|
|
elif len(word) > 1 and word[-1] in "来去" and word[-2] in "上下进出回过起开":
|
|
|
|
elif len(word) > 1 and word[-1] in "来去" and word[-2] in "上下进出回过起开":
|
|
|
@ -147,7 +146,7 @@ class ToneSandhi():
|
|
|
|
for i, char in enumerate(word):
|
|
|
|
for i, char in enumerate(word):
|
|
|
|
if char == "一" and i + 1 < len(word):
|
|
|
|
if char == "一" and i + 1 < len(word):
|
|
|
|
# "一" before tone4 should be yi2, e.g. 一段
|
|
|
|
# "一" before tone4 should be yi2, e.g. 一段
|
|
|
|
if finals[i + 1][-1] == "4":
|
|
|
|
if finals[i + 1][-1] in {'4', '5'}:
|
|
|
|
finals[i] = finals[i][:-1] + "2"
|
|
|
|
finals[i] = finals[i][:-1] + "2"
|
|
|
|
# "一" before non-tone4 should be yi4, e.g. 一天
|
|
|
|
# "一" before non-tone4 should be yi4, e.g. 一天
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -239,7 +238,12 @@ class ToneSandhi():
|
|
|
|
for i, (word, pos) in enumerate(seg):
|
|
|
|
for i, (word, pos) in enumerate(seg):
|
|
|
|
if i - 1 >= 0 and word == "一" and i + 1 < len(seg) and seg[i - 1][
|
|
|
|
if i - 1 >= 0 and word == "一" and i + 1 < len(seg) and seg[i - 1][
|
|
|
|
0] == seg[i + 1][0] and seg[i - 1][1] == "v":
|
|
|
|
0] == seg[i + 1][0] and seg[i - 1][1] == "v":
|
|
|
|
new_seg[i - 1][0] = new_seg[i - 1][0] + "一" + new_seg[i - 1][0]
|
|
|
|
if i - 1 < len(new_seg):
|
|
|
|
|
|
|
|
new_seg[i -
|
|
|
|
|
|
|
|
1][0] = new_seg[i - 1][0] + "一" + new_seg[i - 1][0]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
new_seg.append([word, pos])
|
|
|
|
|
|
|
|
new_seg.append([seg[i + 1][0], pos])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if i - 2 >= 0 and seg[i - 1][0] == "一" and seg[i - 2][
|
|
|
|
if i - 2 >= 0 and seg[i - 1][0] == "一" and seg[i - 2][
|
|
|
|
0] == word and pos == "v":
|
|
|
|
0] == word and pos == "v":
|
|
|
|