diff options
author | Peng Wu <alexepico@gmail.com> | 2017-01-11 11:06:06 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2017-01-11 11:06:06 +0800 |
commit | 52d19b8fad55df8e539af75bf5552488dd2a53e3 (patch) | |
tree | e0d790806419446bdcb975a3208436a9dd1e3c7b /src/lookup | |
parent | fc9efc97091cd0a1b537ca65d4dc161ce3bf5779 (diff) | |
download | libpinyin-52d19b8fad55df8e539af75bf5552488dd2a53e3.tar.gz libpinyin-52d19b8fad55df8e539af75bf5552488dd2a53e3.tar.xz libpinyin-52d19b8fad55df8e539af75bf5552488dd2a53e3.zip |
write phonetic_lookup_linear.h
Diffstat (limited to 'src/lookup')
-rw-r--r-- | src/lookup/phonetic_lookup.h | 87 | ||||
-rw-r--r-- | src/lookup/phonetic_lookup_linear.h | 111 |
2 files changed, 113 insertions, 85 deletions
diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h index 5de61e8..f571fa5 100644 --- a/src/lookup/phonetic_lookup.h +++ b/src/lookup/phonetic_lookup.h @@ -51,49 +51,6 @@ struct trellis_value_t { } }; -template <gint32 nbest> -struct trellis_node { -private: - gint32 m_nelem; - trellis_value_t m_elements[nbest]; - -public: - trellis_node(){ - m_nelem = 0; - /* always assume non-used m_elements contains random data. */ - } - -public: - gint32 length() { return m_nelem; } - const trellis_value_t * begin() { return m_elements; } - const trellis_value_t * end() { return m_elements + m_nelem; } - - /* return true if the item is stored into m_elements. */ - bool eval_item(const trellis_value_t * item) { - /* still have space */ - if (m_nelem < nbest) { - m_elements[m_nelem] = *item; - m_nelem ++; - return true; - } - - /* find minium item */ - trellis_value_t * min = m_elements; - for (gint32 i = 1; i < m_nelem; ++i) { - if (min->m_poss > m_elements[i].m_poss) - min = m_elements + i; - } - - /* compare new item */ - if (item->m_poss > min->m_poss) { - *min = *item; - return true; - } - - return false; - } -}; - struct matrix_value_t { phrase_token_t m_cur_token; gfloat m_poss; @@ -111,48 +68,8 @@ struct matrix_value_t { } }; -template <gint32 nbest> -struct matrix_step { -private: - gint32 m_nelem; - matrix_value_t m_elements[nbest]; - -public: - matrix_step(){ - m_nelem = 0; - /* always assume non-used m_elements contains random data. */ - } - -public: - gint32 length() { return m_nelem; } - const matrix_value_t * begin() { return m_elements; } - const matrix_value_t * end() { return m_elements + m_nelem; } - - /* return true if the item is stored into m_elements. */ - bool eval_item(const trellis_value_t * item) { - /* still have space */ - if (m_nelem < nbest) { - m_elements[m_nelem] = *item; - m_nelem ++; - return true; - } - - /* find minium item */ - matrix_value_t * min = m_elements; - for (gint32 i = 1; i < m_nelem; ++i) { - if (min->m_poss > m_elements[i].m_poss) - min = m_elements + i; - } - - /* compare new item */ - if (item->m_poss > min->m_poss) { - *min = *item; - return true; - } - - return false; - } -}; +/* for debug purpose */ +#include "phonetic_lookup_linear.h" struct trellis_constraint_t { /* the constraint type */ diff --git a/src/lookup/phonetic_lookup_linear.h b/src/lookup/phonetic_lookup_linear.h new file mode 100644 index 0000000..8ce4f4c --- /dev/null +++ b/src/lookup/phonetic_lookup_linear.h @@ -0,0 +1,111 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2017 Peng Wu <alexepico@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef PHONETIC_LOOKUP_LINEAR_H +#define PHONETIC_LOOKUP_LINEAR_H + +template <gint32 nbest> +struct trellis_node { +private: + gint32 m_nelem; + trellis_value_t m_elements[nbest]; + +public: + trellis_node(){ + m_nelem = 0; + /* always assume non-used m_elements contains random data. */ + } + +public: + gint32 length() { return m_nelem; } + const trellis_value_t * begin() { return m_elements; } + const trellis_value_t * end() { return m_elements + m_nelem; } + + /* return true if the item is stored into m_elements. */ + bool eval_item(const trellis_value_t * item) { + /* still have space */ + if (m_nelem < nbest) { + m_elements[m_nelem] = *item; + m_nelem ++; + return true; + } + + /* find minium item */ + trellis_value_t * min = m_elements; + for (gint32 i = 1; i < m_nelem; ++i) { + if (min->m_poss > m_elements[i].m_poss) + min = m_elements + i; + } + + /* compare new item */ + if (item->m_poss > min->m_poss) { + *min = *item; + return true; + } + + return false; + } +}; + +template <gint32 nbest> +struct matrix_step { +private: + gint32 m_nelem; + matrix_value_t m_elements[nbest]; + +public: + matrix_step(){ + m_nelem = 0; + /* always assume non-used m_elements contains random data. */ + } + +public: + gint32 length() { return m_nelem; } + const matrix_value_t * begin() { return m_elements; } + const matrix_value_t * end() { return m_elements + m_nelem; } + + /* return true if the item is stored into m_elements. */ + bool eval_item(const trellis_value_t * item) { + /* still have space */ + if (m_nelem < nbest) { + m_elements[m_nelem] = *item; + m_nelem ++; + return true; + } + + /* find minium item */ + matrix_value_t * min = m_elements; + for (gint32 i = 1; i < m_nelem; ++i) { + if (min->m_poss > m_elements[i].m_poss) + min = m_elements + i; + } + + /* compare new item */ + if (item->m_poss > min->m_poss) { + *min = *item; + return true; + } + + return false; + } +}; + + +#endif |