summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-02-07 13:38:09 +0800
committerPeng Wu <alexepico@gmail.com>2017-02-07 13:38:09 +0800
commit55d7fed35b663fa4acadc42e24a2175c228f7c37 (patch)
tree23502de338082c99c8e684f34ad46a8c58f90c8a
parent8df49857ef632ab03c290df8ee6abe9f436d1d3c (diff)
downloadlibpinyin-55d7fed35b663fa4acadc42e24a2175c228f7c37.tar.gz
libpinyin-55d7fed35b663fa4acadc42e24a2175c228f7c37.tar.xz
libpinyin-55d7fed35b663fa4acadc42e24a2175c228f7c37.zip
fixes compile again
-rw-r--r--src/lookup/phonetic_lookup.cpp3
-rw-r--r--src/lookup/phonetic_lookup.h14
-rw-r--r--src/storage/phonetic_key_matrix.cpp12
-rw-r--r--src/storage/phonetic_key_matrix.h18
-rw-r--r--tests/lookup/test_pinyin_lookup.cpp24
5 files changed, 34 insertions, 37 deletions
diff --git a/src/lookup/phonetic_lookup.cpp b/src/lookup/phonetic_lookup.cpp
index 417ee9f..817f837 100644
--- a/src/lookup/phonetic_lookup.cpp
+++ b/src/lookup/phonetic_lookup.cpp
@@ -22,9 +22,6 @@
namespace pinyin{
-/* internal definition */
-static const size_t nbeam = 32;
-
bool dump_max_value(GPtrArray * values){
if (0 == values->len)
return false;
diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h
index 078a467..6c349fb 100644
--- a/src/lookup/phonetic_lookup.h
+++ b/src/lookup/phonetic_lookup.h
@@ -31,6 +31,10 @@
namespace pinyin{
+
+/* internal definition */
+static const size_t nbeam = 32;
+
#define LONG_SENTENCE_PENALTY 1.2
struct trellis_value_t {
@@ -278,8 +282,8 @@ public:
node->number();
const trellis_value_t * value = node->begin();
- for (size_t j = 0; j < node->length(); ++j) {
- g_ptr_array_add(candidates, value);
+ for (gint32 j = 0; j < node->length(); ++j) {
+ g_ptr_array_add(candidates, (trellis_value_t *)value);
}
}
@@ -325,7 +329,7 @@ public:
get_candidates(tail_index, candidates);
get_top_results<nbest>(nbest, tails, candidates);
- g_ptr_array_sort(tails, trellis_value_compare);
+ g_ptr_array_sort(tails, (GCompareFunc)trellis_value_compare);
g_ptr_array_free(candidates, TRUE);
return true;
@@ -749,7 +753,7 @@ public:
continue;
m_trellis.get_candidates(i, candidates);
- get_top_results<nbest>(topresults, candidates);
+ get_top_results<nbest>(nbeam, topresults, candidates);
if (0 == topresults->len)
continue;
@@ -812,7 +816,7 @@ public:
const trellis_value_t * tail = (const trellis_value_t *)
g_ptr_array_index(tails, i);
- assert(extract_result<nbest>(m_trellis, tail, result));
+ assert(extract_result<nbest>(&m_trellis, tail, result));
results->add_result(result);
}
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp
index 543da5b..c6f07f6 100644
--- a/src/storage/phonetic_key_matrix.cpp
+++ b/src/storage/phonetic_key_matrix.cpp
@@ -348,8 +348,8 @@ bool dump_matrix(PhoneticKeyMatrix * matrix) {
}
int search_matrix_recur(GArray * cached_keys,
- FacadeChewingTable2 * table,
- PhoneticKeyMatrix * matrix,
+ const FacadeChewingTable2 * table,
+ const PhoneticKeyMatrix * matrix,
size_t start, size_t end,
PhraseIndexRanges ranges,
size_t & longest) {
@@ -407,8 +407,8 @@ int search_matrix_recur(GArray * cached_keys,
return result;
}
-int search_matrix(FacadeChewingTable2 * table,
- PhoneticKeyMatrix * matrix,
+int search_matrix(const FacadeChewingTable2 * table,
+ const PhoneticKeyMatrix * matrix,
size_t start, size_t end,
PhraseIndexRanges ranges) {
assert(end < matrix->size());
@@ -437,7 +437,7 @@ int search_matrix(FacadeChewingTable2 * table,
return result;
}
-gfloat compute_pronunciation_possibility_recur(PhoneticKeyMatrix * matrix,
+gfloat compute_pronunciation_possibility_recur(const PhoneticKeyMatrix * matrix,
size_t start, size_t end,
GArray * cached_keys,
PhraseItem & item){
@@ -490,7 +490,7 @@ gfloat compute_pronunciation_possibility_recur(PhoneticKeyMatrix * matrix,
return result;
}
-gfloat compute_pronunciation_possibility(PhoneticKeyMatrix * matrix,
+gfloat compute_pronunciation_possibility(const PhoneticKeyMatrix * matrix,
size_t start, size_t end,
GArray * cached_keys,
PhraseItem & item){
diff --git a/src/storage/phonetic_key_matrix.h b/src/storage/phonetic_key_matrix.h
index 62edf73..968b969 100644
--- a/src/storage/phonetic_key_matrix.h
+++ b/src/storage/phonetic_key_matrix.h
@@ -77,7 +77,7 @@ public:
}
/* Array of Item. */
- bool get_items(size_t index, GArray * items) {
+ bool get_items(size_t index, GArray * items) const {
g_array_set_size(items, 0);
if (index >= m_table_content->len)
@@ -99,7 +99,7 @@ public:
return true;
}
- size_t get_column_size(size_t index) {
+ size_t get_column_size(size_t index) const {
assert(index < m_table_content->len);
GArray * column = (GArray *)
@@ -107,7 +107,7 @@ public:
return column->len;
}
- bool get_item(size_t index, size_t row, Item & item) {
+ bool get_item(size_t index, size_t row, Item & item) const {
assert(index < m_table_content->len);
GArray * column = (GArray *)
@@ -141,7 +141,7 @@ public:
}
/* Array of keys and key rests. */
- bool get_items(size_t index, GArray * keys, GArray * key_rests) {
+ bool get_items(size_t index, GArray * keys, GArray * key_rests) const {
bool result = m_keys.get_items(index, keys) &&
m_key_rests.get_items(index, key_rests);
@@ -155,14 +155,14 @@ public:
m_key_rests.append(index, key_rest);
}
- size_t get_column_size(size_t index) {
+ size_t get_column_size(size_t index) const {
const size_t size = m_keys.get_column_size(index);
assert(size == m_key_rests.get_column_size(index));
return size;
}
bool get_item(size_t index, size_t row,
- ChewingKey & key, ChewingKeyRest & key_rest) {
+ ChewingKey & key, ChewingKeyRest & key_rest) const {
return m_keys.get_item(index, row, key) &&
m_key_rests.get_item(index, row, key_rest);
}
@@ -207,12 +207,12 @@ bool fuzzy_syllable_step(pinyin_option_t options,
bool dump_matrix(PhoneticKeyMatrix * matrix);
-int search_matrix(FacadeChewingTable2 * table,
- PhoneticKeyMatrix * matrix,
+int search_matrix(const FacadeChewingTable2 * table,
+ const PhoneticKeyMatrix * matrix,
size_t start, size_t end,
PhraseIndexRanges ranges);
-gfloat compute_pronunciation_possibility(PhoneticKeyMatrix * matrix,
+gfloat compute_pronunciation_possibility(const PhoneticKeyMatrix * matrix,
size_t start, size_t end,
GArray * cached_keys,
PhraseItem & item);
diff --git a/tests/lookup/test_pinyin_lookup.cpp b/tests/lookup/test_pinyin_lookup.cpp
index 8a1647d..86199af 100644
--- a/tests/lookup/test_pinyin_lookup.cpp
+++ b/tests/lookup/test_pinyin_lookup.cpp
@@ -59,18 +59,16 @@ int main( int argc, char * argv[]){
gfloat lambda = system_table_info.get_lambda();
- PinyinLookup2 pinyin_lookup(lambda, &largetable, &phrase_index,
- &system_bigram, &user_bigram);
+ PhoneticLookup<1> pinyin_lookup(lambda, &largetable, &phrase_index,
+ &system_bigram, &user_bigram);
/* prepare the prefixes for get_best_match. */
TokenVector prefixes = g_array_new
(FALSE, FALSE, sizeof(phrase_token_t));
g_array_append_val(prefixes, sentence_start);
-
- CandidateConstraints constraints = g_array_new
- (TRUE, FALSE, sizeof(lookup_constraint_t));
- MatchResult result = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
+ ForwardPhoneticConstraints constraints;
+ NBestMatchResults results;
char* linebuf = NULL; size_t size = 0; ssize_t read;
while( (read = getline(&linebuf, &size, stdin)) != -1 ){
@@ -105,17 +103,17 @@ int main( int argc, char * argv[]){
dump_matrix(&matrix);
/* initialize constraints. */
- g_array_set_size(constraints, matrix.size());
- for ( size_t i = 0; i < constraints->len; ++i){
- lookup_constraint_t * constraint = &g_array_index(constraints, lookup_constraint_t, i);
- constraint->m_type = NO_CONSTRAINT;
- }
+ constraints.validate_constraint(&matrix);
guint32 start_time = record_time();
for (size_t i = 0; i < bench_times; ++i)
- pinyin_lookup.get_best_match(prefixes, &matrix, constraints, result);
+ pinyin_lookup.get_nbest_match(prefixes, &matrix, &constraints, &results);
print_time(start_time, bench_times);
+ assert(1 == results.size());
+ MatchResult result = NULL;
+ assert(results.get_result(0, result));
+
for (size_t i = 0; i < result->len; ++i){
phrase_token_t * token = &g_array_index(result, phrase_token_t, i);
if ( null_token == *token)
@@ -134,8 +132,6 @@ int main( int argc, char * argv[]){
}
g_array_free(prefixes, TRUE);
- g_array_free(constraints, TRUE);
- g_array_free(result, TRUE);
free(linebuf);
return 0;