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
c79493a1
Commit
c79493a1
authored
12 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
Adjust the used frequency of the user dictionary words.
Bug: 7656666 Change-Id: I4b271af636f6103cb5287336229581365841d778
parent
28de7223
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+20
-5
20 additions, 5 deletions
...c/com/android/inputmethod/latin/UserBinaryDictionary.java
with
20 additions
and
5 deletions
java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+
20
−
5
View file @
c79493a1
...
@@ -31,14 +31,15 @@ import android.text.TextUtils;
...
@@ -31,14 +31,15 @@ import android.text.TextUtils;
import
java.util.Arrays
;
import
java.util.Arrays
;
/**
/**
* An expandable dictionary that stores the words in the user unigram dictionary.
* An expandable dictionary that stores the words in the user dictionary provider into a binary
*
* dictionary file to use it from native code.
* Largely a copy of UserDictionary, will replace that class in the future.
*/
*/
public
class
UserBinaryDictionary
extends
ExpandableBinaryDictionary
{
public
class
UserBinaryDictionary
extends
ExpandableBinaryDictionary
{
// The user dictionary provider uses an empty string to mean "all languages".
// The user dictionary provider uses an empty string to mean "all languages".
private
static
final
String
USER_DICTIONARY_ALL_LANGUAGES
=
""
;
private
static
final
String
USER_DICTIONARY_ALL_LANGUAGES
=
""
;
private
static
final
int
HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY
=
250
;
private
static
final
int
LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY
=
160
;
// TODO: use Words.SHORTCUT when we target JellyBean or above
// TODO: use Words.SHORTCUT when we target JellyBean or above
final
static
String
SHORTCUT
=
"shortcut"
;
final
static
String
SHORTCUT
=
"shortcut"
;
...
@@ -233,6 +234,19 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
...
@@ -233,6 +234,19 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
mContext
.
startActivity
(
intent
);
mContext
.
startActivity
(
intent
);
}
}
private
int
scaleFrequencyFromDefaultToLatinIme
(
final
int
defaultFrequency
)
{
// The default frequency for the user dictionary is 250 for historical reasons.
// Latin IME considers a good value for the default user dictionary frequency
// is about 160 considering the scale we use. So we are scaling down the values.
if
(
defaultFrequency
>
Integer
.
MAX_VALUE
/
LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY
)
{
return
(
defaultFrequency
/
HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY
)
*
LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY
;
}
else
{
return
(
defaultFrequency
*
LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY
)
/
HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY
;
}
}
private
void
addWords
(
final
Cursor
cursor
)
{
private
void
addWords
(
final
Cursor
cursor
)
{
final
boolean
hasShortcutColumn
=
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN
;
final
boolean
hasShortcutColumn
=
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN
;
clearFusionDictionary
();
clearFusionDictionary
();
...
@@ -245,12 +259,13 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
...
@@ -245,12 +259,13 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
final
String
word
=
cursor
.
getString
(
indexWord
);
final
String
word
=
cursor
.
getString
(
indexWord
);
final
String
shortcut
=
hasShortcutColumn
?
cursor
.
getString
(
indexShortcut
)
:
null
;
final
String
shortcut
=
hasShortcutColumn
?
cursor
.
getString
(
indexShortcut
)
:
null
;
final
int
frequency
=
cursor
.
getInt
(
indexFrequency
);
final
int
frequency
=
cursor
.
getInt
(
indexFrequency
);
final
int
adjustedFrequency
=
scaleFrequencyFromDefaultToLatinIme
(
frequency
);
// Safeguard against adding really long words.
// Safeguard against adding really long words.
if
(
word
.
length
()
<
MAX_WORD_LENGTH
)
{
if
(
word
.
length
()
<
MAX_WORD_LENGTH
)
{
super
.
addWord
(
word
,
null
,
f
requency
);
super
.
addWord
(
word
,
null
,
adjustedF
requency
);
}
}
if
(
null
!=
shortcut
&&
shortcut
.
length
()
<
MAX_WORD_LENGTH
)
{
if
(
null
!=
shortcut
&&
shortcut
.
length
()
<
MAX_WORD_LENGTH
)
{
super
.
addWord
(
shortcut
,
word
,
f
requency
);
super
.
addWord
(
shortcut
,
word
,
adjustedF
requency
);
}
}
cursor
.
moveToNext
();
cursor
.
moveToNext
();
}
}
...
...
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