[aquaskk-changes 414] CVS update: AquaSKK/src/backend

Back to archive index

t-suw****@users***** t-suw****@users*****
2007年 10月 14日 (日) 14:52:05 JST


Index: AquaSKK/src/backend/SKKBackEnd.cpp
diff -u /dev/null AquaSKK/src/backend/SKKBackEnd.cpp:1.1.2.1
--- /dev/null	Sun Oct 14 14:52:05 2007
+++ AquaSKK/src/backend/SKKBackEnd.cpp	Sun Oct 14 14:52:05 2007
@@ -0,0 +1,58 @@
+/* -*- C++ -*-
+   MacOS X implementation of the SKK input method.
+
+   Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****>
+
+   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
+   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 "SKKBackEnd.h"
+#include "SKKBackEndImpl.h"
+
+// 補完
+bool SKKBackEnd::Complete(const std::string& entry, std::vector<std::string>& result) {
+    return SKKBackEndImpl::Complete(entry, result);
+}
+
+// 検索
+bool SKKBackEnd::FindOkuriAri(const std::string& entry, const std::string& okuri, SKK::CandidateContainer& result) {
+    return SKKBackEndImpl::FindOkuriAri(entry, okuri, result);
+}
+
+bool SKKBackEnd::FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result) {
+    return SKKBackEndImpl::FindOkuriNasi(entry, result);
+}
+
+// 登録
+bool SKKBackEnd::RegisterOkuriAri(const std::string& entry, const std::string& okuri, const SKK::Candidate& candidate) {
+    return SKKBackEndImpl::RegisterOkuriAri(entry, okuri, candidate);
+}
+
+bool SKKBackEnd::RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) {
+    return SKKBackEndImpl::RegisterOkuriNasi(entry, candidate);
+}
+
+bool SKKBackEnd::RegisterToggleEntry(const std::string& entry) {
+    return SKKBackEndImpl::RegisterToggleEntry(entry);
+}
+
+// 削除
+bool SKKBackEnd::RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate) {
+    return SKKBackEndImpl::RemoveOkuriAri(entry, candidate);
+}
+
+bool SKKBackEnd::RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) {
+    return SKKBackEndImpl::RemoveOkuriNasi(entry, candidate);
+}
Index: AquaSKK/src/backend/SKKBackEnd.h
diff -u /dev/null AquaSKK/src/backend/SKKBackEnd.h:1.1.2.1
--- /dev/null	Sun Oct 14 14:52:05 2007
+++ AquaSKK/src/backend/SKKBackEnd.h	Sun Oct 14 14:52:05 2007
@@ -0,0 +1,46 @@
+/* -*- C++ -*-
+   MacOS X implementation of the SKK input method.
+
+   Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****>
+
+   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
+   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	INC__SKKBackEnd__
+#define INC__SKKBackEnd__
+
+#include "SKK.h"
+
+// 辞書関連の操作
+class SKKBackEnd {
+public:
+    // 補完
+    static bool Complete(const std::string& entry, std::vector<std::string>& result);
+
+    // 検索
+    static bool FindOkuriAri(const std::string& entry, const std::string& okuri, SKK::CandidateContainer& result);
+    static bool FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result);
+
+    // 登録
+    static bool RegisterOkuriAri(const std::string& entry, const std::string& okuri, const SKK::Candidate& candidate);
+    static bool RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate);
+    static bool RegisterToggleEntry(const std::string& entry);
+
+    // 削除
+    static bool RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate);
+    static bool RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate);
+};
+
+#endif
Index: AquaSKK/src/backend/SKKBackEndImpl.h
diff -u /dev/null AquaSKK/src/backend/SKKBackEndImpl.h:1.1.2.1
--- /dev/null	Sun Oct 14 14:52:05 2007
+++ AquaSKK/src/backend/SKKBackEndImpl.h	Sun Oct 14 14:52:05 2007
@@ -0,0 +1,50 @@
+/* -*- C++ -*-
+   MacOS X implementation of the SKK input method.
+
+   Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****>
+
+   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
+   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	INC__SKKBackEndImpl__
+#define INC__SKKBackEndImpl__
+
+#include "SKK.h"
+
+// 実装
+class SKKBackEndImpl {
+public:
+    // 補完
+    static bool Complete(const std::string& entry, std::vector<std::string>& result);
+
+    // 検索
+    static bool FindOkuriAri(const std::string& entry, const std::string& kana, SKK::CandidateContainer& result);
+    static bool FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result);
+
+    // 登録
+    static bool RegisterOkuriAri(const std::string& entry, const std::string& okuri, const SKK::Candidate& candidate);
+    static bool RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate);
+    static bool RegisterToggleEntry(const std::string& entry);
+
+    // 削除
+    static bool RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate);
+    static bool RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate);
+};
+
+#ifdef __APPLE__
+#include "SKKCarbonBackEnd.cpp"
+#endif
+
+#endif
Index: AquaSKK/src/backend/SKKCarbonBackEnd.cpp
diff -u /dev/null AquaSKK/src/backend/SKKCarbonBackEnd.cpp:1.1.2.1
--- /dev/null	Sun Oct 14 14:52:05 2007
+++ AquaSKK/src/backend/SKKCarbonBackEnd.cpp	Sun Oct 14 14:52:05 2007
@@ -0,0 +1,222 @@
+/* -*- C++ -*-
+   $Id: SKKCarbonBackEnd.cpp,v 1.1.2.1 2007/10/14 05:52:05 t-suwa Exp $
+
+   MacOS X implementation of the SKK input method.
+
+   Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****>
+
+   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
+   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 <set>
+#include <sstream>
+#include <algorithm>
+
+#include "CppCFString.h"
+#include "CppCFData.h"
+#include "ServerConnection.h"
+#include "ServerConnectionFactory.h"
+#include "BIMClientServer.h"
+#include "ClientConfiguration.h"
+#include "NumericConverter.h"
+
+// ======================================================================
+// ユーティリティ
+// ======================================================================
+
+static CppCFString CppCFStringFromUTF8(const std::string& utf8) {
+    return CppCFString(utf8.c_str(), kCFStringEncodingUTF8);
+}
+
+// 変換サーバーを呼び出す
+static CppCFString ServerCall(int cmd, const CppCFString& query) {
+    CppCFData data(query.toCFData());
+    ServerConnection connection = ServerConnectionFactory::theInstance().newConnection();
+
+    CppCFString result(connection.send(cmd, data, kAquaSKKServerRunLoopMode).getData());
+
+    return result;
+}
+
+// 検索結果 → SKK::CandidateContainer 変換
+static void ExpandCandidate(const CppCFString& str, SKK::CandidateContainer& result, NumericConverter* conv = 0) {
+    std::vector<CppCFString> tmp = str.split(SKK_MSG_DELIMITER);
+    SKK::Candidate candidate;
+
+    result.clear();
+
+    for(unsigned i = 0; i < tmp.size(); ++ i) {
+	tmp[i].decode();
+
+	// 数値変換が有効か?
+	if(conv) {
+	    // オリジナルの変換候補と、表示用の変換候補を用意しておく(OAOO の原則)
+	    candidate.SetBody(tmp[i].toStdString(kCFStringEncodingUTF8));
+	    candidate.SetFace(conv->Apply(candidate.Body()));
+
+	    result.push_back(candidate);
+	} else {
+	    result.push_back(tmp[i].toStdString(kCFStringEncodingUTF8));
+	}
+    }
+}
+
+// マージ
+static void MergeCandidate(const std::string& entry, SKK::CandidateContainer& ret1, SKK::CandidateContainer& ret2) {
+    SKK::CandidateContainer result;
+
+    typedef std::set<std::string> Check;
+    Check check;
+
+    struct local {
+	static void unique(SKK::CandidateContainer& src, SKK::CandidateContainer& result, Check& check) {
+	    for(SKK::CandidateIterator iter = src.begin(); iter != src.end(); ++ iter) {
+		if(check.find(iter->Face()) != check.end()) continue;
+
+		check.insert(check.lower_bound(iter->Face()), iter->Face());
+		result.push_back(iter->Face());
+	    }
+	}
+    };
+
+    check.insert(entry);
+
+    local::unique(ret1, result, check);
+    local::unique(ret2, result, check);
+
+    result.swap(ret1);
+}
+
+// ======================================================================
+// SKKBackEndImpl インタフェース
+// ======================================================================
+
+// 補完
+bool SKKBackEndImpl::Complete(const std::string& entry, std::vector<std::string>& result) {
+    CppCFString str(entry.c_str(), kCFStringEncodingUTF8);
+    str = ServerCall(kSKKFetchCompletions, str);
+
+    std::string tmp = str.toStdString(kCFStringEncodingUTF8);
+    std::replace(tmp.begin(), tmp.end(), (char)SKK_MSG_DELIMITER, ' ');
+    std::istringstream buf(tmp);
+
+    result.clear();
+    while(buf >> tmp) {
+	result.push_back(tmp);
+    }
+
+    return !result.empty();
+}
+
+// 検索
+bool SKKBackEndImpl::FindOkuriAri(const std::string& entry, const std::string& okuri, SKK::CandidateContainer& result) {
+    CppCFString query('+');
+
+    query.append(CppCFStringFromUTF8(entry));
+    query.append(SKK_MSG_DELIMITER);
+    query.append(CppCFStringFromUTF8(okuri));
+
+    ExpandCandidate(ServerCall(kSKKMessageSearch, query), result);
+
+    return !result.empty();
+}
+
+bool SKKBackEndImpl::FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result) {
+    CppCFString query('-');
+
+    query.append(CppCFStringFromUTF8(entry));
+
+    ExpandCandidate(ServerCall(kSKKMessageSearch, query), result);
+
+    // 数値変換が有効?
+    if(ClientConfiguration::theInstance().useNumericConversion()) {
+	NumericConverter conv;
+
+	// 正規化できなければ終了
+	if(!conv.Setup(entry)) {
+	    return !result.empty();
+	}
+
+	// 正規化した文字列で再検索する
+	query.clear();
+	query.append('-');
+	query.append(CppCFStringFromUTF8(conv.NormalizedKey()));
+
+	SKK::CandidateContainer tmp;
+	ExpandCandidate(ServerCall(kSKKMessageSearch, query), tmp, &conv);
+	MergeCandidate(entry, result, tmp);
+    }
+
+    return !result.empty();
+}
+
+// 登録
+bool SKKBackEndImpl::RegisterOkuriAri(const std::string& entry, const std::string& okuri,
+				      const SKK::Candidate& candidate) {
+    CppCFString query('+');
+
+    query.append(CppCFStringFromUTF8(entry));
+    query.append(SKK_MSG_DELIMITER);
+    query.append(CppCFStringFromUTF8(okuri));
+    query.append(SKK_MSG_DELIMITER);
+    query.append(CppCFStringFromUTF8(candidate.Body()));
+
+    ServerCall(kSKKRegisterThisToUserDic, query);
+
+    return true;
+}
+
+bool SKKBackEndImpl::RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) {
+    CppCFString query('-');
+
+    query.append(CppCFStringFromUTF8(entry));
+    query.append(SKK_MSG_DELIMITER);
+    query.append(CppCFStringFromUTF8(candidate.Body()));
+
+    ServerCall(kSKKRegisterThisToUserDic, query);
+
+    return true;
+}
+
+bool SKKBackEndImpl::RegisterToggleEntry(const std::string& entry) {
+    ServerCall(kSKKRegisterToggleEntry, CppCFStringFromUTF8(entry));
+
+    return true;
+}
+
+// 削除
+bool SKKBackEndImpl::RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate) {
+    CppCFString query('+');
+
+    query.append(CppCFStringFromUTF8(entry));
+    query.append(SKK_MSG_DELIMITER);
+    query.append(CppCFStringFromUTF8(candidate.Body()));
+
+    ServerCall(kSKKRemoveThisFromUserDic, query);
+
+    return true;
+}
+
+bool SKKBackEndImpl::RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) {
+    CppCFString query('-');
+
+    query.append(CppCFStringFromUTF8(entry));
+    query.append(SKK_MSG_DELIMITER);
+    query.append(CppCFStringFromUTF8(candidate.Body()));
+
+    ServerCall(kSKKRemoveThisFromUserDic, query);
+
+    return true;
+}


aquaskk-changes メーリングリストの案内
Back to archive index