Cleanup suggest interface

Change-Id: Ibe334a1d3ab3af69acfa64412c80f0ea24cd2c46
This commit is contained in:
Satoshi Kataoka 2013-04-04 17:58:10 +09:00
parent e9f69e1661
commit e67ede12ec
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/core \
$(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 \
-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/session/dic_traverse_session.cpp \
suggest/core/suggest.cpp \
suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
suggest/policyimpl/typing/scoring_params.cpp \
suggest/policyimpl/typing/typing_scoring.cpp \
suggest/policyimpl/typing/typing_suggest_policy.cpp \
suggest/policyimpl/typing/typing_traversal.cpp \
suggest/policyimpl/typing/typing_weighting.cpp \
suggest/gesture_suggest.cpp \
suggest/typing_suggest.cpp
suggest/policyimpl/typing/typing_weighting.cpp
LOCAL_SRC_FILES := \
$(LATIN_IME_JNI_SRC_FILES) \

View file

@ -24,8 +24,9 @@
#include "defines.h"
#include "dictionary.h"
#include "dic_traverse_wrapper.h"
#include "gesture_suggest.h"
#include "typing_suggest.h"
#include "gesture_suggest_policy_factory.h"
#include "suggest.h"
#include "typing_suggest_policy_factory.h"
#include "unigram_dictionary.h"
namespace latinime {
@ -36,8 +37,8 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust)
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
mUnigramDictionary(new UnigramDictionary(mOffsetDict, BinaryFormat::getFlags(mDict))),
mBigramDictionary(new BigramDictionary(mOffsetDict)),
mGestureSuggest(new GestureSuggest()),
mTypingSuggest(new TypingSuggest()) {
mGestureSuggest(new Suggest(GestureSuggestPolicyFactory::getGestureSuggestPolicy())),
mTypingSuggest(new Suggest(TypingSuggestPolicyFactory::getTypingSuggestPolicy())) {
}
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.
*/
#include "typing_suggest.h"
#include "gesture_suggest_policy_factory.h"
namespace latinime {
SuggestInterface *(*TypingSuggest::sTypingSuggestFactoryMethod)() = 0;
TypingSuggest::~TypingSuggest() {
delete mSuggestInterface;
}
const SuggestPolicy *(*GestureSuggestPolicyFactory::sGestureSuggestFactoryMethod)() = 0;
} // 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.
*/
#include "suggest.h"
#include "typing_suggest.h"
#include "typing_suggest_policy.h"
namespace latinime {
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

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");
* you may not use this file except in compliance with the License.
@ -14,12 +14,24 @@
* 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 {
SuggestInterface *(*GestureSuggest::sGestureSuggestFactoryMethod)() = 0;
GestureSuggest::~GestureSuggest() {
delete mSuggestInterface;
class SuggestPolicy;
class TypingSuggestPolicyFactory {
public:
static const SuggestPolicy *getTypingSuggestPolicy() {
return TypingSuggestPolicy::getInstance();
}
private:
DISALLOW_COPY_AND_ASSIGN(TypingSuggestPolicyFactory);
};
} // 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