summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-01-20 14:56:36 +0800
committerPeng Wu <alexepico@gmail.com>2017-01-20 14:56:36 +0800
commitccf418653381d6a7973612b88515e63032950a0f (patch)
tree3701e5d4a7de7b50c1e86dfcf01068f1ca12c269 /src
parentc826bc25b9a5f35702db8f0e8a2e2a348ecccaff (diff)
downloadlibpinyin-ccf418653381d6a7973612b88515e63032950a0f.tar.gz
libpinyin-ccf418653381d6a7973612b88515e63032950a0f.tar.xz
libpinyin-ccf418653381d6a7973612b88515e63032950a0f.zip
sort tails
Diffstat (limited to 'src')
-rw-r--r--src/lookup/phonetic_lookup.cpp5
-rw-r--r--src/lookup/phonetic_lookup.h8
2 files changed, 8 insertions, 5 deletions
diff --git a/src/lookup/phonetic_lookup.cpp b/src/lookup/phonetic_lookup.cpp
index 03cce60..aa1fc60 100644
--- a/src/lookup/phonetic_lookup.cpp
+++ b/src/lookup/phonetic_lookup.cpp
@@ -61,11 +61,6 @@ bool dump_all_values(GPtrArray * values) {
return true;
}
-static bool trellis_value_less_than(trellis_value_t * lhs,
- trellis_value_t * rhs){
- return lhs->m_poss < rhs->m_poss;
-}
-
int ForwardPhoneticConstraints::add_constraint(size_t start, size_t end,
phrase_token_t token) {
diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h
index 2489087..c54f483 100644
--- a/src/lookup/phonetic_lookup.h
+++ b/src/lookup/phonetic_lookup.h
@@ -171,6 +171,12 @@ bool get_top_results(size_t num,
return true;
}
+static gint trellis_value_compare(const trellis_value_t ** lhs,
+ const trellis_value_t ** rhs) {
+ /* in descending order */
+ return -((*lhs)->m_poss - (*rhs)->m_poss);
+}
+
template <gint32 nbest>
class ForwardPhoneticTrellis {
private:
@@ -324,6 +330,8 @@ public:
get_candidates(tail_index, candidates);
get_top_results<nbest>(nbest, tails, candidates);
+ g_ptr_array_sort(tails, trellis_value_compare);
+
g_ptr_array_free(candidates, TRUE);
return true;
}