Merge "Cleanup suggest interface"

main
Satoshi Kataoka 2013-04-08 05:59:41 +00:00 committed by Android (Google) Code Review
commit f5e18e992b
9 changed files with 71 additions and 162 deletions

View File

@ -31,7 +31,7 @@ LOCAL_C_INCLUDES += \
$(LATIN_IME_SRC_FULLPATH_DIR)/suggest \ $(LATIN_IME_SRC_FULLPATH_DIR)/suggest \
$(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core \ $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core \
$(addprefix $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core/, dicnode dictionary policy session) \ $(addprefix $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core/, dicnode dictionary policy session) \
$(LATIN_IME_SRC_FULLPATH_DIR)/suggest/policyimpl/typing $(addprefix $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/policyimpl/, gesture typing)
LOCAL_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \ LOCAL_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \
-Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls -Wno-system-headers -Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls -Wno-system-headers
@ -71,13 +71,12 @@ LATIN_IME_CORE_SRC_FILES := \
suggest/core/policy/weighting.cpp \ suggest/core/policy/weighting.cpp \
suggest/core/session/dic_traverse_session.cpp \ suggest/core/session/dic_traverse_session.cpp \
suggest/core/suggest.cpp \ suggest/core/suggest.cpp \
suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
suggest/policyimpl/typing/scoring_params.cpp \ suggest/policyimpl/typing/scoring_params.cpp \
suggest/policyimpl/typing/typing_scoring.cpp \ suggest/policyimpl/typing/typing_scoring.cpp \
suggest/policyimpl/typing/typing_suggest_policy.cpp \ suggest/policyimpl/typing/typing_suggest_policy.cpp \
suggest/policyimpl/typing/typing_traversal.cpp \ suggest/policyimpl/typing/typing_traversal.cpp \
suggest/policyimpl/typing/typing_weighting.cpp \ suggest/policyimpl/typing/typing_weighting.cpp
suggest/gesture_suggest.cpp \
suggest/typing_suggest.cpp
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
$(LATIN_IME_JNI_SRC_FILES) \ $(LATIN_IME_JNI_SRC_FILES) \

View File

@ -24,8 +24,9 @@
#include "defines.h" #include "defines.h"
#include "dictionary.h" #include "dictionary.h"
#include "dic_traverse_wrapper.h" #include "dic_traverse_wrapper.h"
#include "gesture_suggest.h" #include "gesture_suggest_policy_factory.h"
#include "typing_suggest.h" #include "suggest.h"
#include "typing_suggest_policy_factory.h"
#include "unigram_dictionary.h" #include "unigram_dictionary.h"
namespace latinime { namespace latinime {
@ -36,8 +37,8 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust)
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust), mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
mUnigramDictionary(new UnigramDictionary(mOffsetDict, BinaryFormat::getFlags(mDict))), mUnigramDictionary(new UnigramDictionary(mOffsetDict, BinaryFormat::getFlags(mDict))),
mBigramDictionary(new BigramDictionary(mOffsetDict)), mBigramDictionary(new BigramDictionary(mOffsetDict)),
mGestureSuggest(new GestureSuggest()), mGestureSuggest(new Suggest(GestureSuggestPolicyFactory::getGestureSuggestPolicy())),
mTypingSuggest(new TypingSuggest()) { mTypingSuggest(new Suggest(TypingSuggestPolicyFactory::getTypingSuggestPolicy())) {
} }
Dictionary::~Dictionary() { Dictionary::~Dictionary() {

View File

@ -1,61 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LATINIME_GESTURE_SUGGEST_H
#define LATINIME_GESTURE_SUGGEST_H
#include "defines.h"
#include "suggest_interface.h"
namespace latinime {
class ProximityInfo;
class GestureSuggest : public SuggestInterface {
public:
GestureSuggest() : mSuggestInterface(getGestureSuggestInstance()) {}
virtual ~GestureSuggest();
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
int *outWords, int *frequencies, int *outputIndices, int *outputTypes) const {
if (!mSuggestInterface) {
return 0;
}
return mSuggestInterface->getSuggestions(pInfo, traverseSession, inputXs, inputYs, times,
pointerIds, inputCodePoints, inputSize, commitPoint, outWords, frequencies,
outputIndices, outputTypes);
}
static void setGestureSuggestFactoryMethod(SuggestInterface *(*factoryMethod)()) {
sGestureSuggestFactoryMethod = factoryMethod;
}
private:
DISALLOW_COPY_AND_ASSIGN(GestureSuggest);
static SuggestInterface *getGestureSuggestInstance() {
if (!sGestureSuggestFactoryMethod) {
return 0;
}
return sGestureSuggestFactoryMethod();
}
static SuggestInterface *(*sGestureSuggestFactoryMethod)();
SuggestInterface *mSuggestInterface;
};
} // namespace latinime
#endif // LATINIME_GESTURE_SUGGEST_H

View File

@ -14,12 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "typing_suggest.h" #include "gesture_suggest_policy_factory.h"
namespace latinime { namespace latinime {
SuggestInterface *(*TypingSuggest::sTypingSuggestFactoryMethod)() = 0; const SuggestPolicy *(*GestureSuggestPolicyFactory::sGestureSuggestFactoryMethod)() = 0;
TypingSuggest::~TypingSuggest() {
delete mSuggestInterface;
}
} // namespace latinime } // namespace latinime

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LATINIME_GESTURE_SUGGEST_POLICY_FACTORY_H
#define LATINIME_GESTURE_SUGGEST_POLICY_FACTORY_H
#include "defines.h"
namespace latinime {
class SuggestPolicy;
class GestureSuggestPolicyFactory {
public:
static void setGestureSuggestPolicyFactoryMethod(const SuggestPolicy *(*factoryMethod)()) {
sGestureSuggestFactoryMethod = factoryMethod;
}
static const SuggestPolicy *getGestureSuggestPolicy() {
if (!sGestureSuggestFactoryMethod) {
return 0;
}
return sGestureSuggestFactoryMethod();
}
private:
DISALLOW_COPY_AND_ASSIGN(GestureSuggestPolicyFactory);
static const SuggestPolicy *(*sGestureSuggestFactoryMethod)();
};
} // namespace latinime
#endif // LATINIME_GESTURE_SUGGEST_POLICY_FACTORY_H

View File

@ -14,29 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "suggest.h"
#include "typing_suggest.h"
#include "typing_suggest_policy.h" #include "typing_suggest_policy.h"
namespace latinime { namespace latinime {
const TypingSuggestPolicy TypingSuggestPolicy::sInstance; const TypingSuggestPolicy TypingSuggestPolicy::sInstance;
// A factory method for a "typing" Suggest instance
static SuggestInterface *getTypingSuggestInstance() {
return new Suggest(TypingSuggestPolicy::getInstance());
}
// An ad-hoc internal class to register the factory method getTypingSuggestInstance() defined above
class TypingSuggestFactoryRegisterer {
public:
TypingSuggestFactoryRegisterer() {
TypingSuggest::setTypingSuggestFactoryMethod(getTypingSuggestInstance);
}
private:
DISALLOW_COPY_AND_ASSIGN(TypingSuggestFactoryRegisterer);
};
// To invoke the TypingSuggestFactoryRegisterer's constructor in the global constructor
static TypingSuggestFactoryRegisterer typingSuggestFactoryregisterer;
} // namespace latinime } // namespace latinime

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012 The Android Open Source Project * Copyright (C) 2013 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,12 +14,24 @@
* limitations under the License. * limitations under the License.
*/ */
#include "gesture_suggest.h" #ifndef LATINIME_TYPING_SUGGEST_POLICY_FACTORY_H
#define LATINIME_TYPING_SUGGEST_POLICY_FACTORY_H
#include "defines.h"
#include "typing_suggest_policy.h"
namespace latinime { namespace latinime {
SuggestInterface *(*GestureSuggest::sGestureSuggestFactoryMethod)() = 0;
GestureSuggest::~GestureSuggest() { class SuggestPolicy;
delete mSuggestInterface;
class TypingSuggestPolicyFactory {
public:
static const SuggestPolicy *getTypingSuggestPolicy() {
return TypingSuggestPolicy::getInstance();
} }
private:
DISALLOW_COPY_AND_ASSIGN(TypingSuggestPolicyFactory);
};
} // namespace latinime } // namespace latinime
#endif // LATINIME_TYPING_SUGGEST_POLICY_FACTORY_H

View File

@ -1,61 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LATINIME_TYPING_SUGGEST_H
#define LATINIME_TYPING_SUGGEST_H
#include "defines.h"
#include "suggest_interface.h"
namespace latinime {
class ProximityInfo;
class TypingSuggest : public SuggestInterface {
public:
TypingSuggest() : mSuggestInterface(getTypingSuggestInstance()) {}
virtual ~TypingSuggest();
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
int *outWords, int *frequencies, int *outputIndices, int *outputTypes) const {
if (!mSuggestInterface) {
return 0;
}
return mSuggestInterface->getSuggestions(pInfo, traverseSession, inputXs, inputYs, times,
pointerIds, inputCodePoints, inputSize, commitPoint, outWords, frequencies,
outputIndices, outputTypes);
}
static void setTypingSuggestFactoryMethod(SuggestInterface *(*factoryMethod)()) {
sTypingSuggestFactoryMethod = factoryMethod;
}
private:
DISALLOW_COPY_AND_ASSIGN(TypingSuggest);
static SuggestInterface *getTypingSuggestInstance() {
if (!sTypingSuggestFactoryMethod) {
return 0;
}
return sTypingSuggestFactoryMethod();
}
static SuggestInterface *(*sTypingSuggestFactoryMethod)();
SuggestInterface *mSuggestInterface;
};
} // namespace latinime
#endif // LATINIME_TYPING_SUGGEST_H