Add methods to read shortcuts from the binary dict (A2)
This contains stubs only, it does not work yet, however it doesn't break anything. Change-Id: If912ae84ff3ccd7a2d6588ffd6fbb9974f87ef3dmain
parent
3b161b2526
commit
cf9dbbdd1a
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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_TERMINAL_ATTRIBUTES_H
|
||||||
|
#define LATINIME_TERMINAL_ATTRIBUTES_H
|
||||||
|
|
||||||
|
#include "unigram_dictionary.h"
|
||||||
|
|
||||||
|
namespace latinime {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class encapsulates information about a terminal that allows to
|
||||||
|
* retrieve local node attributes like the list of shortcuts without
|
||||||
|
* exposing the format structure to the client.
|
||||||
|
*/
|
||||||
|
class TerminalAttributes {
|
||||||
|
public:
|
||||||
|
class ShortcutIterator {
|
||||||
|
const uint8_t* const mDict;
|
||||||
|
int mPos;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ShortcutIterator(const uint8_t* const dict, const int pos) : mDict(dict), mPos(pos) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool hasNextShortcutTarget() const {
|
||||||
|
// TODO: stub method. Fill this in.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int getNextShortcutTarget(const int maxDepth, uint16_t* outWord) {
|
||||||
|
// TODO: stub method. Fill this in.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
const uint8_t* const mDict;
|
||||||
|
const uint8_t mFlags;
|
||||||
|
const int mStartPos;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TerminalAttributes(const uint8_t* const dict, const uint8_t flags, const int pos) :
|
||||||
|
mDict(dict), mFlags(flags), mStartPos(pos) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isShortcutOnly() const {
|
||||||
|
// TODO: stub method. Fill this in.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ShortcutIterator getShortcutIterator() const {
|
||||||
|
return ShortcutIterator(mDict, mStartPos);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace latinime
|
||||||
|
|
||||||
|
#endif // LATINIME_TERMINAL_ATTRIBUTES_H
|
|
@ -25,6 +25,7 @@
|
||||||
#include "unigram_dictionary.h"
|
#include "unigram_dictionary.h"
|
||||||
|
|
||||||
#include "binary_format.h"
|
#include "binary_format.h"
|
||||||
|
#include "terminal_attributes.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -324,14 +325,22 @@ void UnigramDictionary::getMistypedSpaceWords(ProximityInfo *proximityInfo, cons
|
||||||
correction, queuePool);
|
correction, queuePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void UnigramDictionary::onTerminal(
|
inline void UnigramDictionary::onTerminal(const int freq,
|
||||||
const int freq, Correction *correction, WordsPriorityQueue *queue) {
|
const TerminalAttributes& terminalAttributes, Correction *correction,
|
||||||
|
WordsPriorityQueue *queue) {
|
||||||
int wordLength;
|
int wordLength;
|
||||||
unsigned short* wordPointer;
|
unsigned short* wordPointer;
|
||||||
const int finalFreq = correction->getFinalFreq(freq, &wordPointer, &wordLength);
|
const int finalFreq = correction->getFinalFreq(freq, &wordPointer, &wordLength);
|
||||||
if (finalFreq >= 0) {
|
if (finalFreq >= 0) {
|
||||||
|
if (!terminalAttributes.isShortcutOnly()) {
|
||||||
addWord(wordPointer, wordLength, finalFreq, queue);
|
addWord(wordPointer, wordLength, finalFreq, queue);
|
||||||
}
|
}
|
||||||
|
TerminalAttributes::ShortcutIterator iterator = terminalAttributes.getShortcutIterator();
|
||||||
|
while (iterator.hasNextShortcutTarget()) {
|
||||||
|
// TODO: add the shortcut to the list of suggestions using the
|
||||||
|
// iterator.getNextShortcutTarget(int, uint16_t*) method
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo,
|
void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo,
|
||||||
|
@ -646,7 +655,9 @@ inline bool UnigramDictionary::processCurrentNode(const int initialPos,
|
||||||
// The frequency should be here, because we come here only if this is actually
|
// The frequency should be here, because we come here only if this is actually
|
||||||
// a terminal node, and we are on its last char.
|
// a terminal node, and we are on its last char.
|
||||||
const int freq = BinaryFormat::readFrequencyWithoutMovingPointer(DICT_ROOT, pos);
|
const int freq = BinaryFormat::readFrequencyWithoutMovingPointer(DICT_ROOT, pos);
|
||||||
onTerminal(freq, correction, queue);
|
TerminalAttributes terminalAttributes(DICT_ROOT, flags,
|
||||||
|
BinaryFormat::skipFrequency(flags, pos));
|
||||||
|
onTerminal(freq, terminalAttributes, correction, queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are more chars in this node, then this virtual node has children.
|
// If there are more chars in this node, then this virtual node has children.
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
class TerminalAttributes;
|
||||||
class UnigramDictionary {
|
class UnigramDictionary {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -115,7 +116,8 @@ private:
|
||||||
const int *ycoordinates, const int *codes, const bool useFullEditDistance,
|
const int *ycoordinates, const int *codes, const bool useFullEditDistance,
|
||||||
const int inputLength, const int spaceProximityPos, Correction *correction,
|
const int inputLength, const int spaceProximityPos, Correction *correction,
|
||||||
WordsPriorityQueuePool* queuePool);
|
WordsPriorityQueuePool* queuePool);
|
||||||
void onTerminal(const int freq, Correction *correction, WordsPriorityQueue *queue);
|
void onTerminal(const int freq, const TerminalAttributes& terminalAttributes,
|
||||||
|
Correction *correction, WordsPriorityQueue *queue);
|
||||||
bool needsToSkipCurrentNode(const unsigned short c,
|
bool needsToSkipCurrentNode(const unsigned short c,
|
||||||
const int inputIndex, const int skipPos, const int depth);
|
const int inputIndex, const int skipPos, const int depth);
|
||||||
// Process a node by considering proximity, missing and excessive character
|
// Process a node by considering proximity, missing and excessive character
|
||||||
|
|
Loading…
Reference in New Issue