diff --git a/honoka/m4/Makefile b/honoka/m4/Makefile index 3d8bcd3..bf0f5c5 100644 --- a/honoka/m4/Makefile +++ b/honoka/m4/Makefile @@ -91,7 +91,7 @@ CXX = g++ CXXCPP = g++ -E CXXDEPMODE = depmode=gcc3 -CXXFLAGS = +CXXFLAGS = -O3 -march=i686 -fomit-frame-pointer -fforce-addr -fexpensive-optimizations -fpeephole -fgcse -funroll-loops CYGPATH_W = echo DATADIRNAME = share DEFS = -DHAVE_CONFIG_H @@ -127,7 +127,7 @@ INTLLIBS = INTLOBJS = INTL_LIBTOOL_SUFFIX_PREFIX = -LDFLAGS = +LDFLAGS = -z combreloc LIBADD_DL = -ldl LIBICONV = LIBINTL = diff --git a/honoka/plugins/Makefile.am b/honoka/plugins/Makefile.am index 021f7ca..5fe8b12 100644 --- a/honoka/plugins/Makefile.am +++ b/honoka/plugins/Makefile.am @@ -28,7 +28,7 @@ noinst_HEADERS = wnnproto.h romkan.h wnnconversion.h kanainput.h \ anthyconversion.h skkdic.h skkdicconversion.h wnnplugin.h wnnprediction.h \ - honoka_plugin_def.h simpleprediction.h cannaconversion.h + honoka_plugin_def.h simpleprediction.h cannaconversion.h primeprediction.h moduledir = @SCIM_MODULEDIR@/IMEngine @@ -46,7 +46,7 @@ endif plugindir = @SCIM_MODULEDIR@/honoka -plugin_LTLIBRARIES = $(ANTHY_PLUGIN) $(WNN_PLUGIN) $(CANNA_PLUGIN) plugin-skkdic.la plugin-romkan.la plugin-kanainput.la plugin-simpleprediction.la +plugin_LTLIBRARIES = $(ANTHY_PLUGIN) $(WNN_PLUGIN) $(CANNA_PLUGIN) plugin-skkdic.la plugin-romkan.la plugin-kanainput.la plugin-simpleprediction.la plugin-prime.la plugin_anthy_la_SOURCES = anthyconversion.cpp plugin_anthy_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ @@ -84,6 +84,12 @@ plugin_simpleprediction_la_LDFLAGS = -avoid-version -module -rpath $(plugindir) @LIBTOOL_EXPORT_OPTIONS@ @INTLLIBS@ @SCIM_LIBS@ plugin_simpleprediction_la_LIBADD = $(top_builddir)/libhonoka/libhonoka_plugin.la +plugin_prime_la_SOURCES = primeprediction.cpp +plugin_prime_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ +plugin_prime_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ +plugin_prime_la_LDFLAGS = -avoid-version -module -rpath $(plugindir) @LIBTOOL_EXPORT_OPTIONS@ @INTLLIBS@ @SCIM_LIBS@ +plugin_prime_la_LIBADD = $(top_builddir)/libhonoka/libhonoka_plugin.la + plugin_canna_la_SOURCES = cannaconversion.cpp plugin_canna_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ plugin_canna_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ diff --git a/honoka/plugins/honoka_plugin_def.h b/honoka/plugins/honoka_plugin_def.h index 38a3715..7ebca56 100644 --- a/honoka/plugins/honoka_plugin_def.h +++ b/honoka/plugins/honoka_plugin_def.h @@ -65,4 +65,8 @@ #define HONOKA_CONFIG_SKKDIC_DICFILE "/IMEngine/Honoka/SKKDic/File" #define HONOKA_DEFAULT_SKKDIC_DICFILE "" +// Prime +#define HONOKA_CONFIG_PRIME_PREDICTION_LM "/IMEngine/Honoka/Prime/LookupMethod" +#define HONOKA_DEFAULT_PRIME_PREDICTION_LM "lookup_hybrid" + #endif diff --git a/honoka/plugins/primeprediction.cpp b/honoka/plugins/primeprediction.cpp new file mode 100644 index 0000000..038eea6 --- /dev/null +++ b/honoka/plugins/primeprediction.cpp @@ -0,0 +1,235 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * 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. * + ***************************************************************************/ + +#include "primeprediction.h" +#include + +#ifdef HAVE_CONFIG_H + #include +#endif + +#ifdef HAVE_GETTEXT + #include + #define _(String) dgettext(GETTEXT_PACKAGE,String) + #define N_(String) (String) +#else + #define _(String) (String) + #define N_(String) (String) + #define bindtextdomain(Package,Directory) + #define textdomain(domain) + #define bind_textdomain_codeset(domain,codeset) +#endif + +// �ץ饤�����󲽤Τ��ޤ��ʤ��Ǥ��� +HonokaPluginRegister(PrimePrediction); + + +PrimePrediction::PrimePrediction(ConfigPointer cfg) : Predictor(cfg) +{ + m_iconv.set_encoding ("EUC-JP"); + con = false; + lookup_method = cfg->read(HONOKA_CONFIG_PRIME_PREDICTION_LM,String(HONOKA_DEFAULT_PRIME_PREDICTION_LM)); + if ((lookup_method != "lookup") && + (lookup_method != "lookup_all") && + (lookup_method != "lookup_compact") && + (lookup_method != "lookup_compact_all") && + (lookup_method != "lookup_direct") && + (lookup_method != "lookup_direct_all") && + (lookup_method != "lookup_exact") && + (lookup_method != "lookup_expansion") && + (lookup_method != "lookup_hybrid") && + (lookup_method != "lookup_hybrid_all") && + (lookup_method != "lookup_mixed")) lookup_method = String(HONOKA_DEFAULT_PRIME_PREDICTION_LM); +} + + +PrimePrediction::~PrimePrediction() +{ + disconnect(); +} + + +/*! + \fn PrimePrediction::parser(const String &str) + */ +ResultEntry PrimePrediction::parser(const String &str) +{ + vector rl; + String r; + for(unsigned int i = 0;i < str.length();i ++) { + if ((str[i] == '\t') || (str[i] == ' ')) { + if (r.length()) { + rl.push_back(r); + r = ""; + } + } else r += str[i]; + } + if (r.length()) rl.push_back(r); + + if (rl.size() < 2) return ResultEntry(); + WideString w,a; + for(unsigned int i = 2;i < rl.size();i ++) { + if (rl[i].length() < 7) continue; + if (rl[i].substr(0,6) == "usage=") m_iconv.convert(a,rl[i].substr(6)); + } + m_iconv.convert(w,rl[1]); + if (!a.length()) a = w; + else a = w + utf8_mbstowcs(String(" (")) + a + utf8_mbstowcs(String(")")); + return ResultEntry(w,a); +} + +/*! + \fn PrimePrediction::getPredictionList(const WideString &str) + */ +ResultList PrimePrediction::getPredictionList(const WideString &str) +{ + String s = lookup_method + "\t"; + String t; + m_iconv.convert(t,str); + s = s + t + String("\n"); + write(ifd,s.c_str(),s.length()); + char b[1024]; + vector sl; + s = ""; + while(-1) { + int c = read(ofd,b,1023); + s += String(b,c); + if (s.substr(s.length() - 2,2) == "\n\n") break; + } + t = ""; + for(unsigned int i = 0;i < s.length();i ++) { + if (s[i] == '\n') { + sl.push_back(t); + t = ""; + } else t += s[i]; + } + if (t.length()) sl.push_back(t); + ResultList l; + l.Title = utf8_mbstowcs(String(_("lookup result"))); + l.kType = PREDICTION; + for(unsigned int i = 1;i < sl.size();i ++) { + /*vector rl; + String r; + for(unsigned int j = 0;j < sl[i].length();j ++) { + if ((sl[i][j] == '\t') || (sl[i][j] == ' ')) { + if (r.length()) { + rl.push_back(r); + r = ""; + } + } else r += sl[i][j]; + } + if (r.length()) rl.push_back(r); + if (rl.size() < 2) continue; + WideString w; + m_iconv.convert(w,rl[1]); + l.kouho.push_back(ResultEntry(w)); + */ + ResultEntry e = parser(sl[i]); + if (e.kanji.length()) l.kouho.push_back(e); + } + return l; +} + + +/*! + \fn PrimePrediction::disconnect() + */ +void PrimePrediction::disconnect() +{ + String s = "close\n"; + write(ifd,s.c_str(),s.length()); + close(ifd); + close(ofd); +} + + +/*! + \fn PrimePrediction::connect() + */ +bool PrimePrediction::connect() +{ + int in_fd[2],out_fd[2],i; + if (con) return true; + if (pipe(in_fd) == -1) return false; + if (pipe(out_fd) == -1) return false; + con = true; + switch(fork()) { + case -1: { + close(in_fd[0]); + close(in_fd[1]); + close(out_fd[0]); + close(out_fd[1]); + con = false; + return false; + } + case 0: { + close(in_fd[1]); + close(out_fd[0]); + dup2(in_fd[0],0); + dup2(out_fd[1],1); + close(in_fd[0]); + close(out_fd[1]); + execlp("prime",NULL); + con = false; + exit(1); + } + } + close(in_fd[0]); + close(out_fd[1]); + ifd = in_fd[1]; + ofd = out_fd[0]; + return true; +} + + +/*! + \fn PrimePrediction::isConnected() + */ +bool PrimePrediction::isConnected() +{ + return con; +} + + +/*! + \fn PrimePrediction::getPropertyName() + */ +String PrimePrediction::getPropertyName() +{ + return String(_("PrimePrediction")); +} + +/*! + \fn PrimePrediction::getName() + */ +String PrimePrediction::getName() +{ + return String("PrimePrediction"); +} + +/*! + \fn PrimePrediction::update(const WideString str,const WideString yomi) + */ +void PrimePrediction::update(const WideString str,const WideString yomi) +{ +} + + + diff --git a/honoka/plugins/primeprediction.h b/honoka/plugins/primeprediction.h new file mode 100644 index 0000000..e8b377e --- /dev/null +++ b/honoka/plugins/primeprediction.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * 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 PRIMEPREDICTION_H +#define PRIMEPREDICTION_H + + +#define Uses_SCIM_CONFIG_BASE +#define Uses_SCIM_ICONV + + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/** +@author TAM (Teppei Tamra) +*/ +class PrimePrediction : public Predictor { +public: + PrimePrediction(ConfigPointer cfg); + + ~PrimePrediction(); + virtual ResultList getPredictionList(const WideString &str); + virtual void disconnect(); + virtual bool connect(); + virtual bool isConnected(); + virtual String getPropertyName(); + virtual String getName(); + virtual void update(const WideString str,const WideString yomi); + +protected: + String lookup_method; + int ifd; + int ofd; + bool con; + IConvert m_iconv; +protected: + ResultEntry parser(const String &str); +}; + +#endif diff --git a/honoka/po/POTFILES.in b/honoka/po/POTFILES.in index fe7772c..7e3d7cd 100644 --- a/honoka/po/POTFILES.in +++ b/honoka/po/POTFILES.in @@ -19,6 +19,8 @@ plugins/anthyconversion.cpp plugins/simpleprediction.h plugins/simpleprediction.cpp +plugins/primeprediction.h +plugins/primeprediction.cpp plugins/skkdicconversion.h plugins/skkdicconversion.cpp plugins/cannaconversion.h diff --git a/honoka/po/honoka.pot b/honoka/po/honoka.pot index 0f468f8..c20bec5 100644 --- a/honoka/po/honoka.pot +++ b/honoka/po/honoka.pot @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2005-07-15 06:33+0900\n" +"POT-Creation-Date: 2005-07-31 14:43+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -381,15 +381,15 @@ #: src/honoka_imengine_setup.cpp:363 src/honoka_imengine_setup.cpp:384 #: src/honoka_imengine_setup.cpp:404 src/honoka_imengine_setup.cpp:449 -#: src/honoka_imengine_setup.cpp:463 src/honoka_imengine_setup.cpp:484 -#: src/honoka_imengine_setup.cpp:504 +#: src/honoka_imengine_setup.cpp:463 src/honoka_imengine_setup.cpp:490 +#: src/honoka_imengine_setup.cpp:510 msgid "_Use this plugin: " msgstr "" #: src/honoka_imengine_setup.cpp:365 src/honoka_imengine_setup.cpp:386 #: src/honoka_imengine_setup.cpp:406 src/honoka_imengine_setup.cpp:451 -#: src/honoka_imengine_setup.cpp:465 src/honoka_imengine_setup.cpp:486 -#: src/honoka_imengine_setup.cpp:506 +#: src/honoka_imengine_setup.cpp:465 src/honoka_imengine_setup.cpp:492 +#: src/honoka_imengine_setup.cpp:512 msgid "if you use this plugin, check this." msgstr "" @@ -417,11 +417,11 @@ msgid "Wnn-plugin" msgstr "" -#: src/honoka_imengine_setup.cpp:411 +#: src/honoka_imengine_setup.cpp:411 src/honoka_imengine_setup.cpp:469 msgid "_Server: " msgstr "" -#: src/honoka_imengine_setup.cpp:413 +#: src/honoka_imengine_setup.cpp:413 src/honoka_imengine_setup.cpp:471 msgid "input the server name to connect." msgstr "" @@ -457,35 +457,35 @@ msgid "Canna-plugin" msgstr "" -#: src/honoka_imengine_setup.cpp:469 +#: src/honoka_imengine_setup.cpp:475 msgid "_DicHomeDir: " msgstr "" -#: src/honoka_imengine_setup.cpp:471 +#: src/honoka_imengine_setup.cpp:477 msgid "set your DicHomeDir in this entry." msgstr "" -#: src/honoka_imengine_setup.cpp:481 +#: src/honoka_imengine_setup.cpp:487 msgid "SKKDic-plugin" msgstr "" -#: src/honoka_imengine_setup.cpp:490 +#: src/honoka_imengine_setup.cpp:496 msgid "_SKKDic file: " msgstr "" -#: src/honoka_imengine_setup.cpp:492 +#: src/honoka_imengine_setup.cpp:498 msgid "set SKKDic file in this entry." msgstr "" -#: src/honoka_imengine_setup.cpp:501 +#: src/honoka_imengine_setup.cpp:507 msgid "SimplePrediction-plugin" msgstr "" -#: src/honoka_imengine_setup.cpp:510 +#: src/honoka_imengine_setup.cpp:516 msgid "_max history count: " msgstr "" -#: src/honoka_imengine_setup.cpp:512 +#: src/honoka_imengine_setup.cpp:518 msgid "set maximum size of history count." msgstr "" @@ -493,27 +493,27 @@ msgid "lookup result (M)" msgstr "" -#: plugins/romkan.cpp:536 +#: plugins/romkan.cpp:578 msgid "Roma-Kana" msgstr "" -#: plugins/romkan.cpp:540 +#: plugins/romkan.cpp:582 msgid "Roma-Katakana" msgstr "" -#: plugins/romkan.cpp:544 +#: plugins/romkan.cpp:586 msgid "Half Roma-Kana" msgstr "" -#: plugins/romkan.cpp:548 +#: plugins/romkan.cpp:590 msgid "Ascii" msgstr "" -#: plugins/romkan.cpp:552 +#: plugins/romkan.cpp:594 msgid "Wide Ascii" msgstr "" -#: plugins/romkan.cpp:623 +#: plugins/romkan.cpp:666 msgid "Roma" msgstr "" @@ -538,8 +538,8 @@ msgstr "" #: plugins/wnnconversion.cpp:420 plugins/anthyconversion.cpp:169 -#: plugins/simpleprediction.cpp:70 plugins/skkdicconversion.cpp:103 -#: plugins/cannaconversion.cpp:187 +#: plugins/simpleprediction.cpp:70 plugins/primeprediction.cpp:85 +#: plugins/skkdicconversion.cpp:103 plugins/cannaconversion.cpp:198 msgid "lookup result" msgstr "" @@ -559,11 +559,15 @@ msgid "SimplePrediction" msgstr "" +#: plugins/primeprediction.cpp:159 +msgid "PrimePrediction" +msgstr "" + #: plugins/skkdicconversion.cpp:195 msgid "SKKDic" msgstr "" -#: plugins/cannaconversion.cpp:212 +#: plugins/cannaconversion.cpp:223 msgid "CannaConversion" msgstr "" diff --git a/honoka/po/ja.po b/honoka/po/ja.po index 7b9b3c1..43c63ff 100644 --- a/honoka/po/ja.po +++ b/honoka/po/ja.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: ja\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2005-07-15 06:33+0900\n" +"POT-Creation-Date: 2005-07-31 14:43+0900\n" "PO-Revision-Date: 2004-12-01 14:29+0900\n" "Last-Translator: TAM (Teppei Tamra) \n" "Language-Team: Japanese\n" @@ -383,15 +383,15 @@ #: src/honoka_imengine_setup.cpp:363 src/honoka_imengine_setup.cpp:384 #: src/honoka_imengine_setup.cpp:404 src/honoka_imengine_setup.cpp:449 -#: src/honoka_imengine_setup.cpp:463 src/honoka_imengine_setup.cpp:484 -#: src/honoka_imengine_setup.cpp:504 +#: src/honoka_imengine_setup.cpp:463 src/honoka_imengine_setup.cpp:490 +#: src/honoka_imengine_setup.cpp:510 msgid "_Use this plugin: " msgstr "このプラグインを使う(_U):" #: src/honoka_imengine_setup.cpp:365 src/honoka_imengine_setup.cpp:386 #: src/honoka_imengine_setup.cpp:406 src/honoka_imengine_setup.cpp:451 -#: src/honoka_imengine_setup.cpp:465 src/honoka_imengine_setup.cpp:486 -#: src/honoka_imengine_setup.cpp:506 +#: src/honoka_imengine_setup.cpp:465 src/honoka_imengine_setup.cpp:492 +#: src/honoka_imengine_setup.cpp:512 msgid "if you use this plugin, check this." msgstr "このプラグインを利用する場合はここをチェックします" @@ -421,11 +421,11 @@ msgid "Wnn-plugin" msgstr "Wnnプラグイン" -#: src/honoka_imengine_setup.cpp:411 +#: src/honoka_imengine_setup.cpp:411 src/honoka_imengine_setup.cpp:469 msgid "_Server: " msgstr "サーバ(_S):" -#: src/honoka_imengine_setup.cpp:413 +#: src/honoka_imengine_setup.cpp:413 src/honoka_imengine_setup.cpp:471 msgid "input the server name to connect." msgstr "接続するサーバ名を指定します。" @@ -461,35 +461,35 @@ msgid "Canna-plugin" msgstr "Cannaプラグイン" -#: src/honoka_imengine_setup.cpp:469 +#: src/honoka_imengine_setup.cpp:475 msgid "_DicHomeDir: " msgstr "辞書ホームディレクトリ(_D):" -#: src/honoka_imengine_setup.cpp:471 +#: src/honoka_imengine_setup.cpp:477 msgid "set your DicHomeDir in this entry." msgstr "辞書のホームディレクトリを指定して下さい。" -#: src/honoka_imengine_setup.cpp:481 +#: src/honoka_imengine_setup.cpp:487 msgid "SKKDic-plugin" msgstr "SKKDicプラグイン" -#: src/honoka_imengine_setup.cpp:490 +#: src/honoka_imengine_setup.cpp:496 msgid "_SKKDic file: " msgstr "SKK辞書ファイル(_S):" -#: src/honoka_imengine_setup.cpp:492 +#: src/honoka_imengine_setup.cpp:498 msgid "set SKKDic file in this entry." msgstr "利用するSKK辞書ファイルを指定して下さい。" -#: src/honoka_imengine_setup.cpp:501 +#: src/honoka_imengine_setup.cpp:507 msgid "SimplePrediction-plugin" msgstr "単純予測プラグイン" -#: src/honoka_imengine_setup.cpp:510 +#: src/honoka_imengine_setup.cpp:516 msgid "_max history count: " msgstr "最大履歴数(_M):" -#: src/honoka_imengine_setup.cpp:512 +#: src/honoka_imengine_setup.cpp:518 msgid "set maximum size of history count." msgstr "保持する履歴の最大値を指定して下さい。" @@ -497,27 +497,27 @@ msgid "lookup result (M)" msgstr "必殺技候補" -#: plugins/romkan.cpp:536 +#: plugins/romkan.cpp:578 msgid "Roma-Kana" msgstr "[あ]" -#: plugins/romkan.cpp:540 +#: plugins/romkan.cpp:582 msgid "Roma-Katakana" msgstr "[ア]" -#: plugins/romkan.cpp:544 +#: plugins/romkan.cpp:586 msgid "Half Roma-Kana" msgstr "[アr]" -#: plugins/romkan.cpp:548 +#: plugins/romkan.cpp:590 msgid "Ascii" msgstr "[aa]" -#: plugins/romkan.cpp:552 +#: plugins/romkan.cpp:594 msgid "Wide Ascii" msgstr "[a]" -#: plugins/romkan.cpp:623 +#: plugins/romkan.cpp:666 msgid "Roma" msgstr "ローマ字" @@ -542,8 +542,8 @@ msgstr "連想変換" #: plugins/wnnconversion.cpp:420 plugins/anthyconversion.cpp:169 -#: plugins/simpleprediction.cpp:70 plugins/skkdicconversion.cpp:103 -#: plugins/cannaconversion.cpp:187 +#: plugins/simpleprediction.cpp:70 plugins/primeprediction.cpp:85 +#: plugins/skkdicconversion.cpp:103 plugins/cannaconversion.cpp:198 msgid "lookup result" msgstr "候補一覧" @@ -563,11 +563,15 @@ msgid "SimplePrediction" msgstr "単純予測" +#: plugins/primeprediction.cpp:159 +msgid "PrimePrediction" +msgstr "prime予測" + #: plugins/skkdicconversion.cpp:195 msgid "SKKDic" msgstr "SKK辞書" -#: plugins/cannaconversion.cpp:212 +#: plugins/cannaconversion.cpp:223 msgid "CannaConversion" msgstr "Canna変換"