forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoneticSymbol.hpp
109 lines (95 loc) · 3.62 KB
/
PhoneticSymbol.hpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* PhoneticSymbol.h
* Copyright © 2012 kbinani
*
* This file is part of libvsq.
*
* libvsq is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* libvsq is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __PhoneticSymbol_h__
#define __PhoneticSymbol_h__
#include "vsqglobal.hpp"
#include <string>
#include "StringUtil.hpp"
VSQ_BEGIN_NAMESPACE
using namespace std;
using namespace VSQ_NS;
/**
* VSQ で使用される発音記号のためのユーティリティ
* @class table
* @name PhoneticSymbol
*/
class PhoneticSymbol
{
public:
/**
* @brief 指定した文字列が子音を表す発音記号かどうかを判定する
* @param symbol (string) 判定対象の発音記号
* @return (boolean) 子音であれば <code>true</code> を、そうでなければ <code>false</code> を返す
*/
static bool isConsonant( const string &symbol ){
string search = "\t" + symbol + "\t";
return isConsonantEN( search ) || isConsonantJP( search );
}
/**
* @brief 指定した文字列が母音を表す発音記号かどうかを判定する
* @param symbol (string) 判定対象の発音記号
* @return (boolean) 母音であれば <code>true</code> を、そうでなければ <code>false</code> を返す
*/
static bool isVowel( const string &symbol ){
string search = "\t" + symbol + "\t";
return isVowelEN( search ) || isVowelJP( search );
}
/**
* @brief 指定した文字列が発音記号として有効かどうかを判定する
* @param symbol (string) 判定対象の発音記号
* @return (boolean) 有効であれば <code>true</code> を、そうでなければ <code>false</code> を返す
*/
static bool isValidSymbol( const string &symbol ){
bool vowel = isVowel( symbol );
bool consonant = isConsonant( symbol );
if( vowel || consonant ){
return true;
}
// ブレスの判定
int symbolCharacterCount = symbol.size();
if( symbol.find( "br" ) == 0 && symbolCharacterCount > 2 ){
// br001とかをfalseにするためのチェック
string s = symbol.substr( 2 );
try{
StringUtil::parseInt<int>( s );
return true;
}catch( StringUtil::IntegerParseException & ){
return false;
}
}
return false;
}
private:
PhoneticSymbol()
{
}
static bool isVowelJP( const string search ){
const string symbolVowelJP = "\ta\ti\tM\te\to\t";
return symbolVowelJP.find( search ) != string::npos;
}
static bool isConsonantJP( const string search ){
const string symbolConsonantJP = "\tk\tk'\tg\tg'\tN\tN'\ts\tS\tz\tZ\tdz\tdZ\tt\tt'\tts\ttS\td\td'\tn\tJ\th\th\\\tC\tp\\\tp\\'\tb\tb'\tp\tp'\tm\tm'\tj\t4\t4'\tw\tN\\\t";
return symbolConsonantJP.find( search ) != string::npos;
}
static bool isVowelEN( const string search ){
const string symbolVowelEN = "\t@\tV\te\te\tI\ti:\t{\tO:\tQ\tU\tu:\t@r\teI\taI\tOI\t@U\taU\tI@\te@\tU@\tO@\tQ@\t";
return symbolVowelEN.find( search ) != string::npos;
}
static bool isConsonantEN( const string search ){
const string symbolConsonantEN = "\tw\tj\tb\td\tg\tbh\tdh\tgh\tdZ\tv\tD\tz\tZ\tm\tn\tN\tr\tl\tl0\tp\tt\tk\tph\tth\tkh\ttS\tf\tT\ts\tS\th\tSil\tAsp\t";
return symbolConsonantEN.find( search ) != string::npos;
}
};
VSQ_END_NAMESPACE
#endif