From 2e4cb2b1fcfe9aa306c69a0ec1ed30136148e2b6 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 30 Aug 2011 12:58:15 +0800 Subject: move pinyin custom settings to pinyin_custom.h --- src/pinyin.h | 27 ++++++++++ src/pinyin_internal.cpp | 0 src/pinyin_internal.h | 0 src/storage/pinyin_base.h | 95 +---------------------------------- src/storage/pinyin_custom.h | 117 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 94 deletions(-) create mode 100644 src/pinyin_internal.cpp create mode 100644 src/pinyin_internal.h create mode 100644 src/storage/pinyin_custom.h diff --git a/src/pinyin.h b/src/pinyin.h index 0d89a43..c4c121d 100644 --- a/src/pinyin.h +++ b/src/pinyin.h @@ -1,3 +1,28 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2011 Peng Wu + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef PINYIN_H +#define PINYIN_H + #include #include "novel_types.h" #include "memory_chunk.h" @@ -61,3 +86,5 @@ bool pinyin_translate_token(pinyin_context_t * context, bool pinyin_train(pinyin_context_t * context); bool pinyin_save(pinyin_context_t * context); bool pinyin_reset(pinyin_context_t * context); + +#endif diff --git a/src/pinyin_internal.cpp b/src/pinyin_internal.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/pinyin_internal.h b/src/pinyin_internal.h new file mode 100644 index 0000000..e69de29 diff --git a/src/storage/pinyin_base.h b/src/storage/pinyin_base.h index 7b8b48f..c093d60 100644 --- a/src/storage/pinyin_base.h +++ b/src/storage/pinyin_base.h @@ -28,6 +28,7 @@ #include #include +#include "pinyin_custom.h" namespace pinyin{ @@ -65,8 +66,6 @@ typedef GArray* PinyinKeyVector; /* Array of PinyinKey */ typedef GArray* PinyinKeyPosVector; /* Array of PinyinKeyPos */ -struct PinyinCustomSettings; - /** * @brief enums of pinyin initial element. * @@ -199,98 +198,6 @@ enum PinyinZhuYinScheme ZHUYIN_DEFAULT = ZHUYIN_STANDARD }; -/** - * @brief enums of pinyin ambiguities. - * - * Some pinyin element maybe confused by somebody, - * We allow these ambiguities. - */ -enum PinyinAmbiguity -{ - PINYIN_AmbAny= 0, - PINYIN_AmbZhiZi, - PINYIN_AmbChiCi, - PINYIN_AmbShiSi, - PINYIN_AmbNeLe, - PINYIN_AmbLeRi, - PINYIN_AmbFoHe, - PINYIN_AmbGeKe, - PINYIN_AmbAnAng, - PINYIN_AmbEnEng, - PINYIN_AmbInIng, - PINYIN_AmbLast = PINYIN_AmbInIng -}; - -/** - * @brief Structure to hold pinyin custom settings. - * - * user can custom the behavor of libpinyin by these settings. - */ -struct PinyinCustomSettings -{ - bool use_incomplete; - /**< allow incomplete pinyin key which only has inital. */ - - bool use_ambiguities [PINYIN_AmbLast + 1]; - /**< allow ambiguous pinyin elements or not. */ - - PinyinCustomSettings (); - - void set_use_incomplete (bool use) { use_incomplete = use; } - void set_use_ambiguities (PinyinAmbiguity amb, bool use) - { - if (amb == PINYIN_AmbAny) - for (size_t i=0; i<=PINYIN_AmbLast; ++i) use_ambiguities [i] = use; - else { - use_ambiguities [0] = false; - use_ambiguities [static_cast(amb)] = use; - for (size_t i=1; i<=PINYIN_AmbLast; ++i) - if (use_ambiguities [i]) { - use_ambiguities [0] = true; - break; - } - } - } - - bool operator == (const PinyinCustomSettings &rhs) const - { - if (use_incomplete != rhs.use_incomplete) - return false; - - for (size_t i=0; i <= PINYIN_AmbLast; ++i) - if (use_ambiguities [i] != rhs.use_ambiguities [i]) - return false; - - return true; - } - - bool operator != (const PinyinCustomSettings &rhs) const - { - return !(*this == rhs); - } - - guint32 to_value () const - { - guint32 val = 0; - - if (use_incomplete) val |= 1; - - for (size_t i=0; i <= PINYIN_AmbLast; ++i) - if (use_ambiguities [i]) - val |= (1 << (i+1)); - - return val; - } - - void from_value (guint32 val) - { - use_incomplete = ((val & 1) != 0); - - for (size_t i=0; i <= PINYIN_AmbLast; ++i) - use_ambiguities [i] = ((val & (1 << (i+1))) != 0); - } -}; - /** * @brief Pinyin key class. * diff --git a/src/storage/pinyin_custom.h b/src/storage/pinyin_custom.h new file mode 100644 index 0000000..04c97ed --- /dev/null +++ b/src/storage/pinyin_custom.h @@ -0,0 +1,117 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2011 Peng Wu + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PINYIN_CUSTOM_H +#define PINYIN_CUSTOM_H + +/** + * @brief enums of pinyin ambiguities. + * + * Some pinyin element maybe confused by somebody, + * We allow these ambiguities. + */ +enum PinyinAmbiguity +{ + PINYIN_AmbAny= 0, + PINYIN_AmbZhiZi, + PINYIN_AmbChiCi, + PINYIN_AmbShiSi, + PINYIN_AmbNeLe, + PINYIN_AmbLeRi, + PINYIN_AmbFoHe, + PINYIN_AmbGeKe, + PINYIN_AmbAnAng, + PINYIN_AmbEnEng, + PINYIN_AmbInIng, + PINYIN_AmbLast = PINYIN_AmbInIng +}; + +/** + * @brief Structure to hold pinyin custom settings. + * + * user can custom the behavor of libpinyin by these settings. + */ +struct PinyinCustomSettings +{ + bool use_incomplete; + /**< allow incomplete pinyin key which only has inital. */ + + bool use_ambiguities [PINYIN_AmbLast + 1]; + /**< allow ambiguous pinyin elements or not. */ + + PinyinCustomSettings (); + + void set_use_incomplete (bool use) { use_incomplete = use; } + void set_use_ambiguities (PinyinAmbiguity amb, bool use) + { + if (amb == PINYIN_AmbAny) + for (size_t i=0; i<=PINYIN_AmbLast; ++i) use_ambiguities [i] = use; + else { + use_ambiguities [0] = false; + use_ambiguities [static_cast(amb)] = use; + for (size_t i=1; i<=PINYIN_AmbLast; ++i) + if (use_ambiguities [i]) { + use_ambiguities [0] = true; + break; + } + } + } + + bool operator == (const PinyinCustomSettings &rhs) const + { + if (use_incomplete != rhs.use_incomplete) + return false; + + for (size_t i=0; i <= PINYIN_AmbLast; ++i) + if (use_ambiguities [i] != rhs.use_ambiguities [i]) + return false; + + return true; + } + + bool operator != (const PinyinCustomSettings &rhs) const + { + return !(*this == rhs); + } + + guint32 to_value () const + { + guint32 val = 0; + + if (use_incomplete) val |= 1; + + for (size_t i=0; i <= PINYIN_AmbLast; ++i) + if (use_ambiguities [i]) + val |= (1 << (i+1)); + + return val; + } + + void from_value (guint32 val) + { + use_incomplete = ((val & 1) != 0); + + for (size_t i=0; i <= PINYIN_AmbLast; ++i) + use_ambiguities [i] = ((val & (1 << (i+1))) != 0); + } +}; + +#endif -- cgit