2011-07-15 05:49:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 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_CORRECTION_STATE_H
|
|
|
|
#define LATINIME_CORRECTION_STATE_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "defines.h"
|
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
|
|
|
|
class ProximityInfo;
|
|
|
|
|
|
|
|
class CorrectionState {
|
2011-08-01 11:35:27 +01:00
|
|
|
|
2011-07-15 05:49:00 +01:00
|
|
|
public:
|
2011-08-03 15:27:32 +01:00
|
|
|
typedef enum {
|
|
|
|
ALLOW_ALL,
|
|
|
|
UNRELATED,
|
|
|
|
RELATED
|
|
|
|
} CorrectionStateType;
|
|
|
|
|
2011-08-01 11:35:27 +01:00
|
|
|
CorrectionState(const int typedLetterMultiplier, const int fullWordMultiplier);
|
|
|
|
void initCorrectionState(const ProximityInfo *pi, const int inputLength);
|
|
|
|
void setCorrectionParams(const int skipPos, const int excessivePos, const int transposedPos,
|
|
|
|
const int spaceProximityPos, const int missingSpacePos);
|
2011-07-15 05:49:00 +01:00
|
|
|
void checkState();
|
2011-08-03 15:27:32 +01:00
|
|
|
void initProcessState(const int matchCount, const int inputIndex, const int outputIndex);
|
|
|
|
void getProcessState(int *matchedCount, int *inputIndex, int *outputIndex);
|
2011-08-02 18:19:44 +01:00
|
|
|
void charMatched();
|
2011-08-03 15:27:32 +01:00
|
|
|
void incrementInputIndex();
|
|
|
|
void incrementOutputIndex();
|
|
|
|
int getOutputIndex();
|
|
|
|
int getInputIndex();
|
|
|
|
|
2011-07-15 05:49:00 +01:00
|
|
|
virtual ~CorrectionState();
|
|
|
|
int getSkipPos() const {
|
|
|
|
return mSkipPos;
|
|
|
|
}
|
|
|
|
int getExcessivePos() const {
|
|
|
|
return mExcessivePos;
|
|
|
|
}
|
|
|
|
int getTransposedPos() const {
|
|
|
|
return mTransposedPos;
|
|
|
|
}
|
2011-08-01 11:35:27 +01:00
|
|
|
int getSpaceProximityPos() const {
|
|
|
|
return mSpaceProximityPos;
|
|
|
|
}
|
|
|
|
int getMissingSpacePos() const {
|
|
|
|
return mMissingSpacePos;
|
|
|
|
}
|
|
|
|
int getFreqForSplitTwoWords(const int firstFreq, const int secondFreq);
|
2011-08-03 15:27:32 +01:00
|
|
|
int getFinalFreq(const unsigned short *word, const int freq);
|
2011-08-01 11:35:27 +01:00
|
|
|
|
2011-07-15 05:49:00 +01:00
|
|
|
private:
|
2011-08-01 11:35:27 +01:00
|
|
|
|
|
|
|
const int TYPED_LETTER_MULTIPLIER;
|
|
|
|
const int FULL_WORD_MULTIPLIER;
|
2011-08-02 18:19:44 +01:00
|
|
|
|
2011-07-15 05:49:00 +01:00
|
|
|
const ProximityInfo *mProximityInfo;
|
|
|
|
int mInputLength;
|
|
|
|
int mSkipPos;
|
|
|
|
int mExcessivePos;
|
|
|
|
int mTransposedPos;
|
2011-08-01 11:35:27 +01:00
|
|
|
int mSpaceProximityPos;
|
|
|
|
int mMissingSpacePos;
|
|
|
|
|
2011-08-02 18:19:44 +01:00
|
|
|
int mMatchedCharCount;
|
2011-08-03 15:27:32 +01:00
|
|
|
int mInputIndex;
|
|
|
|
int mOutputIndex;
|
2011-08-02 18:19:44 +01:00
|
|
|
|
2011-08-01 11:35:27 +01:00
|
|
|
class RankingAlgorithm {
|
|
|
|
public:
|
|
|
|
static int calculateFinalFreq(const int inputIndex, const int depth,
|
|
|
|
const int matchCount, const int freq, const bool sameLength,
|
|
|
|
const CorrectionState* correctionState);
|
|
|
|
static int calcFreqForSplitTwoWords(const int firstFreq, const int secondFreq,
|
|
|
|
const CorrectionState* correctionState);
|
|
|
|
};
|
2011-07-15 05:49:00 +01:00
|
|
|
};
|
|
|
|
} // namespace latinime
|
|
|
|
#endif // LATINIME_CORRECTION_INFO_H
|