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
eb6a7c82
Commit
eb6a7c82
authored
11 years ago
by
Satoshi Kataoka
Committed by
Android (Google) Code Review
11 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Migrate used functions in UnigramDicitonary"
parents
2a529b85
6c4ad527
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
native/jni/src/suggest/core/dictionary/dictionary.cpp
+33
-26
33 additions, 26 deletions
native/jni/src/suggest/core/dictionary/dictionary.cpp
native/jni/src/suggest/core/dictionary/dictionary.h
+1
-2
1 addition, 2 deletions
native/jni/src/suggest/core/dictionary/dictionary.h
with
34 additions
and
28 deletions
native/jni/src/suggest/core/dictionary/dictionary.cpp
+
33
−
26
View file @
eb6a7c82
...
...
@@ -22,7 +22,6 @@
#include
<stdint.h>
#include
"defines.h"
#include
"obsolete/unigram_dictionary.h"
#include
"suggest/core/dictionary/bigram_dictionary.h"
#include
"suggest/core/dictionary/binary_format.h"
#include
"suggest/core/session/dic_traverse_session.h"
...
...
@@ -35,16 +34,15 @@ namespace latinime {
Dictionary
::
Dictionary
(
void
*
dict
,
int
dictSize
,
int
mmapFd
,
int
dictBufAdjust
)
:
mBinaryDicitonaryInfo
(
static_cast
<
const
uint8_t
*>
(
dict
),
dictSize
),
mDictSize
(
dictSize
),
mMmapFd
(
mmapFd
),
mDictBufAdjust
(
dictBufAdjust
),
m
UnigramDictionary
(
new
UnigramDictionary
(
&
mBinaryDicitonaryInfo
,
BinaryFormat
::
getFlags
(
mBinaryDicitonaryInfo
.
getDictBuf
(),
dictSize
))
),
mDictSize
(
dictSize
),
m
DictFlags
(
BinaryFormat
::
getFlags
(
mBinaryDicitonaryInfo
.
getDictBuf
(),
dictSize
))
,
mMmapFd
(
mmapFd
),
mDictBufAdjust
(
dictBufAdjust
),
mBigramDictionary
(
new
BigramDictionary
(
&
mBinaryDicitonaryInfo
)),
mGestureSuggest
(
new
Suggest
(
GestureSuggestPolicyFactory
::
getGestureSuggestPolicy
())),
mTypingSuggest
(
new
Suggest
(
TypingSuggestPolicyFactory
::
getTypingSuggestPolicy
()))
{
}
Dictionary
::~
Dictionary
()
{
delete
mUnigramDictionary
;
delete
mBigramDictionary
;
delete
mGestureSuggest
;
delete
mTypingSuggest
;
...
...
@@ -67,26 +65,15 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
}
return
result
;
}
else
{
if
(
USE_SUGGEST_INTERFACE_FOR_TYPING
)
{
DicTraverseSession
::
initSessionInstance
(
traverseSession
,
this
,
prevWordCodePoints
,
prevWordLength
,
suggestOptions
);
result
=
mTypingSuggest
->
getSuggestions
(
proximityInfo
,
traverseSession
,
xcoordinates
,
ycoordinates
,
times
,
pointerIds
,
inputCodePoints
,
inputSize
,
commitPoint
,
outWords
,
frequencies
,
spaceIndices
,
outputTypes
);
if
(
DEBUG_DICT
)
{
DUMP_RESULT
(
outWords
,
frequencies
);
}
return
result
;
}
else
{
std
::
map
<
int
,
int
>
bigramMap
;
uint8_t
bigramFilter
[
BIGRAM_FILTER_BYTE_SIZE
];
mBigramDictionary
->
fillBigramAddressToProbabilityMapAndFilter
(
prevWordCodePoints
,
prevWordLength
,
&
bigramMap
,
bigramFilter
);
result
=
mUnigramDictionary
->
getSuggestions
(
proximityInfo
,
xcoordinates
,
ycoordinates
,
inputCodePoints
,
inputSize
,
&
bigramMap
,
bigramFilter
,
suggestOptions
->
useFullEditDistance
(),
outWords
,
frequencies
,
outputTypes
);
return
result
;
DicTraverseSession
::
initSessionInstance
(
traverseSession
,
this
,
prevWordCodePoints
,
prevWordLength
,
suggestOptions
);
result
=
mTypingSuggest
->
getSuggestions
(
proximityInfo
,
traverseSession
,
xcoordinates
,
ycoordinates
,
times
,
pointerIds
,
inputCodePoints
,
inputSize
,
commitPoint
,
outWords
,
frequencies
,
spaceIndices
,
outputTypes
);
if
(
DEBUG_DICT
)
{
DUMP_RESULT
(
outWords
,
frequencies
);
}
return
result
;
}
}
...
...
@@ -98,7 +85,27 @@ int Dictionary::getBigrams(const int *word, int length, int *inputCodePoints, in
}
int
Dictionary
::
getProbability
(
const
int
*
word
,
int
length
)
const
{
return
mUnigramDictionary
->
getProbability
(
word
,
length
);
const
uint8_t
*
const
root
=
mBinaryDicitonaryInfo
.
getDictRoot
();
int
pos
=
BinaryFormat
::
getTerminalPosition
(
root
,
word
,
length
,
false
/* forceLowerCaseSearch */
);
if
(
NOT_VALID_WORD
==
pos
)
{
return
NOT_A_PROBABILITY
;
}
const
uint8_t
flags
=
BinaryFormat
::
getFlagsAndForwardPointer
(
root
,
&
pos
);
if
(
flags
&
(
BinaryFormat
::
FLAG_IS_BLACKLISTED
|
BinaryFormat
::
FLAG_IS_NOT_A_WORD
))
{
// If this is not a word, or if it's a blacklisted entry, it should behave as
// having no probability outside of the suggestion process (where it should be used
// for shortcuts).
return
NOT_A_PROBABILITY
;
}
const
bool
hasMultipleChars
=
(
0
!=
(
BinaryFormat
::
FLAG_HAS_MULTIPLE_CHARS
&
flags
));
if
(
hasMultipleChars
)
{
pos
=
BinaryFormat
::
skipOtherCharacters
(
root
,
pos
);
}
else
{
BinaryFormat
::
getCodePointAndForwardPointer
(
root
,
&
pos
);
}
const
int
unigramProbability
=
BinaryFormat
::
readProbabilityWithoutMovingPointer
(
root
,
pos
);
return
unigramProbability
;
}
bool
Dictionary
::
isValidBigram
(
const
int
*
word1
,
int
length1
,
const
int
*
word2
,
int
length2
)
const
{
...
...
@@ -106,7 +113,7 @@ bool Dictionary::isValidBigram(const int *word1, int length1, const int *word2,
}
int
Dictionary
::
getDictFlags
()
const
{
return
m
UnigramDictionary
->
get
DictFlags
()
;
return
mDictFlags
;
}
}
// namespace latinime
This diff is collapsed.
Click to expand it.
native/jni/src/suggest/core/dictionary/dictionary.h
+
1
−
2
View file @
eb6a7c82
...
...
@@ -29,7 +29,6 @@ class DicTraverseSession;
class
ProximityInfo
;
class
SuggestInterface
;
class
SuggestOptions
;
class
UnigramDictionary
;
class
Dictionary
{
public:
...
...
@@ -82,10 +81,10 @@ class Dictionary {
// Used only for the mmap version of dictionary loading, but we use these as dummy variables
// also for the malloc version.
const
int
mDictSize
;
const
int
mDictFlags
;
const
int
mMmapFd
;
const
int
mDictBufAdjust
;
const
UnigramDictionary
*
mUnigramDictionary
;
const
BigramDictionary
*
mBigramDictionary
;
SuggestInterface
*
mGestureSuggest
;
SuggestInterface
*
mTypingSuggest
;
...
...
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