-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToneSandhi.h
More file actions
46 lines (37 loc) · 2.04 KB
/
ToneSandhi.h
File metadata and controls
46 lines (37 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <string>
#include <vector>
#include <unordered_set>
#include <utility>
#include <memory>
#include <functional>
class ToneSandhi {
public:
using PinyinProvider = std::function<std::vector<std::string>(const std::string&)>;
ToneSandhi();
void setPinyinProvider(PinyinProvider provider);
// Core logic: pre-merge
std::vector<std::pair<std::string, std::string>> pre_merge_for_modify(
const std::vector<std::pair<std::string, std::string>>& seg);
// Core logic: modify tone
std::vector<std::string> modified_tone(const std::string& word, const std::string& pos,
std::vector<std::string> finals);
private:
// Internal sandhi rules
std::vector<std::string> _bu_sandhi(const std::string& word, std::vector<std::string> finals);
std::vector<std::string> _yi_sandhi(const std::string& word, std::vector<std::string> finals);
std::vector<std::string> _neural_sandhi(const std::string& word, const std::string& pos, std::vector<std::string> finals);
std::vector<std::string> _three_sandhi(const std::string& word, std::vector<std::string> finals);
// Merge rules
std::vector<std::pair<std::string, std::string>> _merge_bu(const std::vector<std::pair<std::string, std::string>>& seg);
std::vector<std::pair<std::string, std::string>> _merge_yi(const std::vector<std::pair<std::string, std::string>>& seg);
std::vector<std::pair<std::string, std::string>> _merge_reduplication(const std::vector<std::pair<std::string, std::string>>& seg);
std::vector<std::pair<std::string, std::string>> _merge_er(const std::vector<std::pair<std::string, std::string>>& seg);
// Helpers
bool _all_tone_three(const std::vector<std::string>& finals);
std::vector<std::string> _split_word(const std::string& word);
std::unordered_set<std::string> must_neural_tone_words;
std::unordered_set<std::string> must_not_neural_tone_words;
std::string punc;
PinyinProvider pinyin_provider;
};