33 memset(&bigram_table_, 0,
sizeof(bigram_table_));
38 for (
int ch1 = 0; ch1 <= bigram_table_.
max_char; ch1++) {
41 if (char_bigram->
bigram != NULL) {
42 delete []char_bigram->
bigram;
54 file_name = data_file_path +
lang;
55 file_name +=
".cube.bigrams";
71 vector<string> str_vec;
74 for (
int big = 0; big < str_vec.size(); big++) {
78 if (sscanf(str_vec[big].c_str(),
"%d %x %x", &cnt, &ch1, &ch2) != 3) {
79 fprintf(stderr,
"Cube ERROR (CharBigrams::Create): invalid format " 80 "reading line: %s\n", str_vec[big].c_str());
81 delete char_bigrams_obj;
91 (table->
max_char + 1) *
sizeof(*char_bigram));
98 for (
int new_big = table->
max_char + 1; new_big <= ch1; new_big++) {
119 new_big <= ch2; new_big++) {
138 log(
MAX(0.5, static_cast<double>(cnt)) /
142 return char_bigrams_obj;
156 if (!char_32_ptr || char_32_ptr[0] == 0) {
163 if (lower_32 && lower_32[0] != 0) {
165 cost =
MIN(cost, cost_lower);
169 if (upper_32 && upper_32[0] != 0) {
171 cost =
MIN(cost, cost_upper);
184 cost =
PairCost(
' ', char_32_ptr[0]);
185 for (c = 1; c < len; c++) {
186 cost +=
PairCost(char_32_ptr[c - 1], char_32_ptr[c]);
188 cost +=
PairCost(char_32_ptr[len - 1],
' ');
189 return static_cast<int>(cost /
static_cast<double>(len + 1));
static char_32 * ToLower(const char_32 *str32, CharSet *char_set)
int MeanCostWithSpaces(const char_32 *char_32_ptr) const
static CharBigrams * Create(const string &data_file_path, const string &lang)
static bool ReadFileToString(const string &file_name, string *str)
static char_32 * ToUpper(const char_32 *str32, CharSet *char_set)
static int StrLen(const char_32 *str)
static void SplitStringUsing(const string &str, const string &delims, vector< string > *str_vec)
static bool IsCaseInvariant(const char_32 *str32, CharSet *char_set)
int Cost(const char_32 *str, CharSet *char_set) const
int PairCost(char_32 ch1, char_32 ch2) const