Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
f7c449b6
Commit
f7c449b6
authored
13 years ago
by
satok
Committed by
Android (Google) Code Review
13 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Removed matchedChar count"
parents
4ef448ac
466ed22f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
native/src/correction.cpp
+22
-32
22 additions, 32 deletions
native/src/correction.cpp
native/src/correction.h
+4
-13
4 additions, 13 deletions
native/src/correction.h
native/src/correction_state.h
+2
-4
2 additions, 4 deletions
native/src/correction_state.h
with
28 additions
and
49 deletions
native/src/correction.cpp
+
22
−
32
View file @
f7c449b6
...
...
@@ -102,7 +102,7 @@ int Correction::getFinalFreq(const int freq, unsigned short **word, int *wordLen
const
bool
sameLength
=
(
mExcessivePos
==
mInputLength
-
1
)
?
(
mInputLength
==
inputIndex
+
2
)
:
(
mInputLength
==
inputIndex
+
1
);
return
Correction
::
RankingAlgorithm
::
calculateFinalFreq
(
inputIndex
,
outputIndex
,
mMatchedCharCount
,
freq
,
sameLength
,
this
);
inputIndex
,
outputIndex
,
freq
,
sameLength
,
this
);
}
bool
Correction
::
initProcessState
(
const
int
outputIndex
)
{
...
...
@@ -111,10 +111,9 @@ bool Correction::initProcessState(const int outputIndex) {
}
mOutputIndex
=
outputIndex
;
--
(
mCorrectionStates
[
outputIndex
].
mChildCount
);
mMatchedCharCount
=
mCorrectionStates
[
outputIndex
].
mMatchedCount
;
mInputIndex
=
mCorrectionStates
[
outputIndex
].
mInputIndex
;
mNeedsToTraverseAllNodes
=
mCorrectionStates
[
outputIndex
].
mNeedsToTraverseAllNodes
;
m
Diffs
=
mCorrectionStates
[
outputIndex
].
m
Diffs
;
m
ProximityCount
=
mCorrectionStates
[
outputIndex
].
m
ProximityCount
;
mSkippedCount
=
mCorrectionStates
[
outputIndex
].
mSkippedCount
;
mSkipPos
=
mCorrectionStates
[
outputIndex
].
mSkipPos
;
mSkipping
=
false
;
...
...
@@ -130,10 +129,6 @@ int Correction::goDownTree(
return
mOutputIndex
;
}
void
Correction
::
charMatched
()
{
++
mMatchedCharCount
;
}
// TODO: remove
int
Correction
::
getOutputIndex
()
{
return
mOutputIndex
;
...
...
@@ -158,10 +153,9 @@ void Correction::incrementOutputIndex() {
mCorrectionStates
[
mOutputIndex
].
mParentIndex
=
mCorrectionStates
[
mOutputIndex
-
1
].
mParentIndex
;
mCorrectionStates
[
mOutputIndex
].
mChildCount
=
mCorrectionStates
[
mOutputIndex
-
1
].
mChildCount
;
mCorrectionStates
[
mOutputIndex
].
mSiblingPos
=
mCorrectionStates
[
mOutputIndex
-
1
].
mSiblingPos
;
mCorrectionStates
[
mOutputIndex
].
mMatchedCount
=
mMatchedCharCount
;
mCorrectionStates
[
mOutputIndex
].
mInputIndex
=
mInputIndex
;
mCorrectionStates
[
mOutputIndex
].
mNeedsToTraverseAllNodes
=
mNeedsToTraverseAllNodes
;
mCorrectionStates
[
mOutputIndex
].
m
Diffs
=
mDiffs
;
mCorrectionStates
[
mOutputIndex
].
m
ProximityCount
=
mProximityCount
;
mCorrectionStates
[
mOutputIndex
].
mSkippedCount
=
mSkippedCount
;
mCorrectionStates
[
mOutputIndex
].
mSkipping
=
mSkipping
;
mCorrectionStates
[
mOutputIndex
].
mSkipPos
=
mSkipPos
;
...
...
@@ -174,7 +168,7 @@ void Correction::startToTraverseAllNodes() {
bool
Correction
::
needsToPrune
()
const
{
return
(
mOutputIndex
-
1
>=
(
mTransposedPos
>=
0
?
mInputLength
-
1
:
mMaxDepth
)
||
m
Diffs
>
mMaxEditDistance
);
||
m
ProximityCount
>
mMaxEditDistance
);
}
Correction
::
CorrectionType
Correction
::
processSkipChar
(
...
...
@@ -231,8 +225,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
int
matchedProximityCharId
=
mProximityInfo
->
getMatchedProximityId
(
inputIndexForProximity
,
c
,
checkProximityChars
);
const
bool
unrelated
=
ProximityInfo
::
UNRELATED_CHAR
==
matchedProximityCharId
;
if
(
unrelated
)
{
if
(
ProximityInfo
::
UNRELATED_CHAR
==
matchedProximityCharId
)
{
if
(
skip
)
{
// Skip this letter and continue deeper
++
mSkippedCount
;
...
...
@@ -240,19 +233,15 @@ Correction::CorrectionType Correction::processCharAndCalcState(
}
else
{
return
UNRELATED
;
}
}
mWord
[
mOutputIndex
]
=
c
;
// If inputIndex is greater than mInputLength, that means there is no
// proximity chars. So, we don't need to check proximity.
if
(
ProximityInfo
::
SAME_OR_ACCENTED_OR_CAPITALIZED_CHAR
==
matchedProximityCharId
)
{
}
else
if
(
ProximityInfo
::
SAME_OR_ACCENTED_OR_CAPITALIZED_CHAR
==
matchedProximityCharId
)
{
// If inputIndex is greater than mInputLength, that means there is no
// proximity chars. So, we don't need to check proximity.
mMatching
=
true
;
charMatched
();
}
else
if
(
ProximityInfo
::
NEAR_PROXIMITY_CHAR
==
matchedProximityCharId
)
{
incrementProximityCount
();
}
if
(
ProximityInfo
::
NEAR_PROXIMITY_CHAR
==
matchedProximityCharId
)
{
incrementDiffs
();
}
mWord
[
mOutputIndex
]
=
c
;
const
bool
isSameAsUserTypedLength
=
mInputLength
==
getInputIndex
()
+
1
...
...
@@ -336,24 +325,25 @@ inline static void multiplyRate(const int rate, int *freq) {
//////////////////////
/* static */
int
Correction
::
RankingAlgorithm
::
calculateFinalFreq
(
const
int
inputIndex
,
const
int
outputIndex
,
const
int
matchCount
,
const
int
freq
,
const
bool
sameLength
,
const
Correction
*
correction
)
{
const
int
skipPos
=
correction
->
getSkipPos
();
int
Correction
::
RankingAlgorithm
::
calculateFinalFreq
(
const
int
inputIndex
,
const
int
outputIndex
,
const
int
freq
,
const
bool
sameLength
,
const
Correction
*
correction
)
{
const
int
excessivePos
=
correction
->
getExcessivePos
();
const
int
transposedPos
=
correction
->
getTransposedPos
();
const
int
inputLength
=
correction
->
mInputLength
;
const
int
typedLetterMultiplier
=
correction
->
TYPED_LETTER_MULTIPLIER
;
const
int
fullWordMultiplier
=
correction
->
FULL_WORD_MULTIPLIER
;
const
ProximityInfo
*
proximityInfo
=
correction
->
mProximityInfo
;
// TODO: use mExcessiveCount
const
int
matchCount
=
inputLength
-
correction
->
mProximityCount
-
(
excessivePos
>=
0
?
1
:
0
);
const
int
matchWeight
=
powerIntCapped
(
typedLetterMultiplier
,
matchCount
);
const
unsigned
short
*
word
=
correction
->
mWord
;
const
int
skipped
Count
=
correction
->
mSkippedCount
;
const
bool
skipped
=
correction
->
mSkippedCount
>
0
;
// TODO: Demote by edit distance
int
finalFreq
=
freq
*
matchWeight
;
if
(
skip
Pos
>=
0
)
{
if
(
skip
ped
)
{
if
(
inputLength
>=
2
)
{
const
int
demotionRate
=
WORDS_WITH_MISSING_CHARACTER_DEMOTION_RATE
*
(
10
*
inputLength
-
WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X
)
...
...
@@ -387,10 +377,10 @@ int Correction::RankingAlgorithm::calculateFinalFreq(
}
multiplyRate
(
FULL_MATCHED_WORDS_PROMOTION_RATE
,
&
finalFreq
);
}
if
(
sameLength
&&
transposedPos
<
0
&&
skip
Pos
<
0
&&
excessivePos
<
0
)
{
if
(
sameLength
&&
transposedPos
<
0
&&
!
skip
ped
&&
excessivePos
<
0
)
{
finalFreq
=
capped255MultForFullMatchAccentsOrCapitalizationDifference
(
finalFreq
);
}
}
else
if
(
sameLength
&&
transposedPos
<
0
&&
skip
Pos
<
0
&&
excessivePos
<
0
}
else
if
(
sameLength
&&
transposedPos
<
0
&&
!
skip
ped
&&
excessivePos
<
0
&&
outputIndex
>
0
)
{
// A word with proximity corrections
if
(
DEBUG_DICT
)
{
...
...
@@ -418,7 +408,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(
s ... skipping
a ... traversing all
*/
if
(
matchCount
==
inputLength
&&
matchCount
>=
2
&&
skipped
Count
==
0
if
(
matchCount
==
inputLength
&&
matchCount
>=
2
&&
!
skipped
&&
word
[
matchCount
]
==
word
[
matchCount
-
1
])
{
multiplyRate
(
WORDS_WITH_MATCH_SKIP_PROMOTION_RATE
,
&
finalFreq
);
}
...
...
This diff is collapsed.
Click to expand it.
native/src/correction.h
+
4
−
13
View file @
f7c449b6
...
...
@@ -48,8 +48,6 @@ public:
void
checkState
();
bool
initProcessState
(
const
int
index
);
void
getProcessState
(
int
*
matchedCount
,
int
*
inputIndex
,
int
*
outputIndex
,
bool
*
traverseAllNodes
,
int
*
diffs
);
int
getOutputIndex
();
int
getInputIndex
();
...
...
@@ -80,10 +78,6 @@ public:
CorrectionType
processCharAndCalcState
(
const
int32_t
c
,
const
bool
isTerminal
);
int
getDiffs
()
const
{
return
mDiffs
;
}
/////////////////////////
// Tree helper methods
int
goDownTree
(
const
int
parentIndex
,
const
int
childCount
,
const
int
firstChildPos
);
...
...
@@ -100,7 +94,6 @@ public:
return
mCorrectionStates
[
index
].
mParentIndex
;
}
private
:
inline
void
charMatched
();
inline
void
incrementInputIndex
();
inline
void
incrementOutputIndex
();
inline
bool
needsToTraverseAllNodes
();
...
...
@@ -109,8 +102,8 @@ private:
inline
CorrectionType
processSkipChar
(
const
int32_t
c
,
const
bool
isTerminal
);
// TODO: remove
inline
void
increment
Diffs
()
{
++
m
Diffs
;
inline
void
increment
ProximityCount
()
{
++
m
ProximityCount
;
}
const
int
TYPED_LETTER_MULTIPLIER
;
...
...
@@ -133,8 +126,7 @@ private:
// The following member variables are being used as cache values of the correction state.
int
mOutputIndex
;
int
mInputIndex
;
int
mDiffs
;
int
mMatchedCharCount
;
int
mProximityCount
;
int
mSkippedCount
;
int
mSkipPos
;
bool
mNeedsToTraverseAllNodes
;
...
...
@@ -144,8 +136,7 @@ private:
class
RankingAlgorithm
{
public:
static
int
calculateFinalFreq
(
const
int
inputIndex
,
const
int
depth
,
const
int
matchCount
,
const
int
freq
,
const
bool
sameLength
,
const
Correction
*
correction
);
const
int
freq
,
const
bool
sameLength
,
const
Correction
*
correction
);
static
int
calcFreqForSplitTwoWords
(
const
int
firstFreq
,
const
int
secondFreq
,
const
Correction
*
correction
);
};
...
...
This diff is collapsed.
Click to expand it.
native/src/correction_state.h
+
2
−
4
View file @
f7c449b6
...
...
@@ -28,8 +28,7 @@ struct CorrectionState {
int
mSiblingPos
;
uint16_t
mChildCount
;
uint8_t
mInputIndex
;
uint8_t
mDiffs
;
uint8_t
mMatchedCount
;
uint8_t
mProximityCount
;
uint8_t
mSkippedCount
;
int8_t
mSkipPos
;
// should be signed
bool
mMatching
;
...
...
@@ -43,9 +42,8 @@ inline static void initCorrectionState(CorrectionState *state, const int rootPos
state
->
mParentIndex
=
-
1
;
state
->
mChildCount
=
childCount
;
state
->
mInputIndex
=
0
;
state
->
m
Diffs
=
0
;
state
->
m
ProximityCount
=
0
;
state
->
mSiblingPos
=
rootPos
;
state
->
mMatchedCount
=
0
;
state
->
mSkippedCount
=
0
;
state
->
mMatching
=
false
;
state
->
mSkipping
=
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment