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
d4952c8f
Commit
d4952c8f
authored
14 years ago
by
satok
Browse files
Options
Downloads
Patches
Plain Diff
Move a logic for finding words with a missing character to the native code.
Change-Id: I58338643830ff4f9708f78a9c26f75c8bf2ebf45
parent
bd20db25
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
java/src/com/android/inputmethod/latin/BinaryDictionary.java
+2
-19
2 additions, 19 deletions
java/src/com/android/inputmethod/latin/BinaryDictionary.java
native/src/dictionary.cpp
+66
-35
66 additions, 35 deletions
native/src/dictionary.cpp
native/src/dictionary.h
+6
-6
6 additions, 6 deletions
native/src/dictionary.h
with
74 additions
and
60 deletions
java/src/com/android/inputmethod/latin/BinaryDictionary.java
+
2
−
19
View file @
d4952c8f
...
...
@@ -45,7 +45,6 @@ public class BinaryDictionary extends Dictionary {
private
static
final
int
MAX_BIGRAMS
=
60
;
private
static
final
int
TYPED_LETTER_MULTIPLIER
=
2
;
private
static
final
boolean
ENABLE_MISSED_CHARACTERS
=
true
;
private
int
mDicTypeId
;
private
int
mNativeDict
;
...
...
@@ -199,27 +198,11 @@ public class BinaryDictionary extends Dictionary {
Arrays
.
fill
(
mOutputChars
,
(
char
)
0
);
Arrays
.
fill
(
mFrequencies
,
0
);
int
count
=
getSuggestionsNative
(
mNativeDict
,
mInputCodes
,
codesSize
,
mOutputChars
,
mFrequencies
,
MAX_WORD_LENGTH
,
MAX_WORDS
,
MAX_ALTERNATIVES
,
-
1
,
int
count
=
getSuggestionsNative
(
mNativeDict
,
mInputCodes
,
codesSize
,
mOutputChars
,
mFrequencies
,
MAX_WORD_LENGTH
,
MAX_WORDS
,
MAX_ALTERNATIVES
,
-
1
,
nextLettersFrequencies
,
nextLettersFrequencies
!=
null
?
nextLettersFrequencies
.
length
:
0
);
// If there aren't sufficient suggestions, search for words by allowing wild cards at
// the different character positions. This feature is not ready for prime-time as we need
// to figure out the best ranking for such words compared to proximity corrections and
// completions.
if
(
ENABLE_MISSED_CHARACTERS
&&
count
<
5
)
{
for
(
int
skip
=
0
;
skip
<
codesSize
;
skip
++)
{
int
tempCount
=
getSuggestionsNative
(
mNativeDict
,
mInputCodes
,
codesSize
,
mOutputChars
,
mFrequencies
,
MAX_WORD_LENGTH
,
MAX_WORDS
,
MAX_ALTERNATIVES
,
skip
,
null
,
0
);
count
=
Math
.
max
(
count
,
tempCount
);
if
(
tempCount
>
0
)
break
;
}
}
for
(
int
j
=
0
;
j
<
count
;
j
++)
{
if
(
mFrequencies
[
j
]
<
1
)
break
;
int
start
=
j
*
MAX_WORD_LENGTH
;
...
...
This diff is collapsed.
Click to expand it.
native/src/dictionary.cpp
+
66
−
35
View file @
d4952c8f
...
...
@@ -37,6 +37,10 @@
#define DICTIONARY_HEADER_SIZE 2
#define NOT_VALID_WORD -99
#define SUGGEST_MISSING_CHARACTERS true
#define SUGGEST_MISSING_CHARACTERS_THRESHOLD 5
namespace
latinime
{
Dictionary
::
Dictionary
(
void
*
dict
,
int
typedLetterMultiplier
,
int
fullWordMultiplier
)
...
...
@@ -56,7 +60,42 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
int
maxWordLength
,
int
maxWords
,
int
maxAlternatives
,
int
skipPos
,
int
*
nextLetters
,
int
nextLettersSize
)
{
int
suggWords
;
initSuggestions
(
codes
,
codesSize
,
outWords
,
frequencies
,
maxWordLength
,
maxWords
,
maxAlternatives
);
int
suggestedWordsCount
=
getSuggestionCandidates
(
codesSize
,
maxWords
,
skipPos
,
nextLetters
,
nextLettersSize
);
// If there aren't sufficient suggestions, search for words by allowing wild cards at
// the different character positions. This feature is not ready for prime-time as we need
// to figure out the best ranking for such words compared to proximity corrections and
// completions.
if
(
SUGGEST_MISSING_CHARACTERS
&&
suggestedWordsCount
<
SUGGEST_MISSING_CHARACTERS_THRESHOLD
)
{
for
(
int
i
=
0
;
i
<
codesSize
;
++
i
)
{
int
tempCount
=
getSuggestionCandidates
(
codesSize
,
maxWords
,
i
,
NULL
,
0
);
if
(
tempCount
>
suggestedWordsCount
)
{
suggestedWordsCount
=
tempCount
;
break
;
}
}
}
if
(
DEBUG_DICT
)
{
LOGI
(
"Returning %d words"
,
suggestedWordsCount
);
LOGI
(
"Next letters: "
);
for
(
int
k
=
0
;
k
<
nextLettersSize
;
k
++
)
{
if
(
nextLetters
[
k
]
>
0
)
{
LOGI
(
"%c = %d,"
,
k
,
nextLetters
[
k
]);
}
}
LOGI
(
"
\n
"
);
}
return
suggestedWordsCount
;
}
void
Dictionary
::
initSuggestions
(
int
*
codes
,
int
codesSize
,
unsigned
short
*
outWords
,
int
*
frequencies
,
int
maxWordLength
,
int
maxWords
,
int
maxAlternatives
)
{
mFrequencies
=
frequencies
;
mOutputChars
=
outWords
;
mInputCodes
=
codes
;
...
...
@@ -64,39 +103,29 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
mMaxAlternatives
=
maxAlternatives
;
mMaxWordLength
=
maxWordLength
;
mMaxWords
=
maxWords
;
mSkipPos
=
skipPos
;
mMaxEditDistance
=
mInputLength
<
5
?
2
:
mInputLength
/
2
;
mNextLettersFrequencies
=
nextLetters
;
mNextLettersSize
=
nextLettersSize
;
}
int
Dictionary
::
getSuggestionCandidates
(
int
inputLength
,
int
maxWords
,
int
skipPos
,
int
*
nextLetters
,
int
nextLettersSize
)
{
if
(
checkIfDictVersionIsLatest
())
{
getWordsRec
(
DICTIONARY_HEADER_SIZE
,
0
,
mInputLength
*
3
,
false
,
1
,
0
,
0
);
getWordsRec
(
DICTIONARY_HEADER_SIZE
,
0
,
inputLength
*
3
,
false
,
1
,
0
,
0
,
skipPos
,
nextLetters
,
nextLettersSize
);
}
else
{
getWordsRec
(
0
,
0
,
mI
nputLength
*
3
,
false
,
1
,
0
,
0
);
getWordsRec
(
0
,
0
,
i
nputLength
*
3
,
false
,
1
,
0
,
0
,
skipPos
,
nextLetters
,
nextLettersSize
);
}
// Get the word count
suggWords
=
0
;
while
(
suggWords
<
mMaxWords
&&
mFrequencies
[
suggWords
]
>
0
)
suggWords
++
;
if
(
DEBUG_DICT
)
LOGI
(
"Returning %d words"
,
suggWords
);
if
(
DEBUG_DICT
)
{
LOGI
(
"Next letters: "
);
for
(
int
k
=
0
;
k
<
nextLettersSize
;
k
++
)
{
if
(
mNextLettersFrequencies
[
k
]
>
0
)
{
LOGI
(
"%c = %d,"
,
k
,
mNextLettersFrequencies
[
k
]);
}
}
LOGI
(
"
\n
"
);
int
suggestedWordsCount
=
0
;
while
(
suggestedWordsCount
<
maxWords
&&
mFrequencies
[
suggestedWordsCount
]
>
0
)
{
suggestedWordsCount
++
;
}
return
sugg
Words
;
return
sugg
estedWordsCount
;
}
void
Dictionary
::
registerNextLetter
(
unsigned
short
c
)
{
if
(
c
<
mNextLettersSize
)
{
mNextLettersFrequencies
[
c
]
++
;
void
Dictionary
::
registerNextLetter
(
unsigned
short
c
,
int
*
nextLetters
,
int
nextLettersSize
)
{
if
(
c
<
nextLettersSize
)
{
nextLetters
[
c
]
++
;
}
}
...
...
@@ -287,7 +316,7 @@ static char QUOTE = '\'';
void
Dictionary
::
getWordsRec
(
int
pos
,
int
depth
,
int
maxDepth
,
bool
completion
,
int
snr
,
int
inputIndex
,
int
diffs
)
int
diffs
,
int
skipPos
,
int
*
nextLetters
,
int
nextLettersSize
)
{
// Optimization: Prune out words that are too long compared to how much was typed.
if
(
depth
>
maxDepth
)
{
...
...
@@ -321,19 +350,20 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s
mWord
[
depth
]
=
c
;
if
(
terminal
)
{
addWord
(
mWord
,
depth
+
1
,
freq
*
snr
);
if
(
depth
>=
mInputLength
&&
mS
kipPos
<
0
)
{
registerNextLetter
(
mWord
[
mInputLength
]);
if
(
depth
>=
mInputLength
&&
s
kipPos
<
0
)
{
registerNextLetter
(
mWord
[
mInputLength
]
,
nextLetters
,
nextLettersSize
);
}
}
if
(
childrenAddress
!=
0
)
{
getWordsRec
(
childrenAddress
,
depth
+
1
,
maxDepth
,
completion
,
snr
,
inputIndex
,
diffs
);
getWordsRec
(
childrenAddress
,
depth
+
1
,
maxDepth
,
completion
,
snr
,
inputIndex
,
diffs
,
skipPos
,
nextLetters
,
nextLettersSize
);
}
}
else
if
((
c
==
QUOTE
&&
currentChars
[
0
]
!=
QUOTE
)
||
mS
kipPos
==
depth
)
{
}
else
if
((
c
==
QUOTE
&&
currentChars
[
0
]
!=
QUOTE
)
||
s
kipPos
==
depth
)
{
// Skip the ' or other letter and continue deeper
mWord
[
depth
]
=
c
;
if
(
childrenAddress
!=
0
)
{
getWordsRec
(
childrenAddress
,
depth
+
1
,
maxDepth
,
false
,
snr
,
inputIndex
,
diffs
);
getWordsRec
(
childrenAddress
,
depth
+
1
,
maxDepth
,
false
,
snr
,
inputIndex
,
diffs
,
skipPos
,
nextLetters
,
nextLettersSize
);
}
}
else
{
int
j
=
0
;
...
...
@@ -346,22 +376,23 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s
if
(
//INCLUDE_TYPED_WORD_IF_VALID ||
!
sameAsTyped
(
mWord
,
depth
+
1
))
{
int
finalFreq
=
freq
*
snr
*
addedWeight
;
if
(
mS
kipPos
<
0
)
finalFreq
*=
mFullWordMultiplier
;
if
(
s
kipPos
<
0
)
finalFreq
*=
mFullWordMultiplier
;
addWord
(
mWord
,
depth
+
1
,
finalFreq
);
}
}
if
(
childrenAddress
!=
0
)
{
getWordsRec
(
childrenAddress
,
depth
+
1
,
maxDepth
,
true
,
snr
*
addedWeight
,
inputIndex
+
1
,
diffs
+
(
j
>
0
));
diffs
+
(
j
>
0
)
,
skipPos
,
nextLetters
,
nextLettersSize
);
}
}
else
if
(
childrenAddress
!=
0
)
{
getWordsRec
(
childrenAddress
,
depth
+
1
,
maxDepth
,
false
,
snr
*
addedWeight
,
inputIndex
+
1
,
diffs
+
(
j
>
0
));
false
,
snr
*
addedWeight
,
inputIndex
+
1
,
diffs
+
(
j
>
0
),
skipPos
,
nextLetters
,
nextLettersSize
);
}
}
j
++
;
if
(
mS
kipPos
>=
0
)
break
;
if
(
s
kipPos
>=
0
)
break
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
native/src/dictionary.h
+
6
−
6
View file @
d4952c8f
...
...
@@ -48,7 +48,10 @@ public:
~
Dictionary
();
private
:
void
initSuggestions
(
int
*
codes
,
int
codesSize
,
unsigned
short
*
outWords
,
int
*
frequencies
,
int
maxWordLength
,
int
maxWords
,
int
maxAlternatives
);
int
getSuggestionCandidates
(
int
inputLength
,
int
maxWords
,
int
skipPos
,
int
*
nextLetters
,
int
nextLettersSize
);
void
getVersionNumber
();
bool
checkIfDictVersionIsLatest
();
int
getAddress
(
int
*
pos
);
...
...
@@ -70,9 +73,9 @@ private:
bool
addWordBigram
(
unsigned
short
*
word
,
int
length
,
int
frequency
);
unsigned
short
toLowerCase
(
unsigned
short
c
);
void
getWordsRec
(
int
pos
,
int
depth
,
int
maxDepth
,
bool
completion
,
int
frequency
,
int
inputIndex
,
int
diffs
);
int
inputIndex
,
int
diffs
,
int
skipPos
,
int
*
nextLetters
,
int
nextLettersSize
);
int
isValidWordRec
(
int
pos
,
unsigned
short
*
word
,
int
offset
,
int
length
);
void
registerNextLetter
(
unsigned
short
c
);
void
registerNextLetter
(
unsigned
short
c
,
int
*
nextLetters
,
int
nextLettersSize
);
unsigned
char
*
mDict
;
void
*
mAsset
;
...
...
@@ -88,13 +91,10 @@ private:
int
mInputLength
;
int
mMaxAlternatives
;
unsigned
short
mWord
[
128
];
int
mSkipPos
;
int
mMaxEditDistance
;
int
mFullWordMultiplier
;
int
mTypedLetterMultiplier
;
int
*
mNextLettersFrequencies
;
int
mNextLettersSize
;
int
mVersion
;
int
mBigram
;
};
...
...
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