Merge "Remove TerminalAttributes."

main
Keisuke Kuroyanagi 2013-08-13 05:58:35 +00:00 committed by Android (Google) Code Review
commit e607e0722a
4 changed files with 62 additions and 88 deletions

View File

@ -0,0 +1,55 @@
/*
* 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_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H
#define LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H
#include "defines.h"
#include "suggest/core/policy/dictionary_shortcuts_structure_policy.h"
namespace latinime {
class BinaryDictionaryShortcutIterator {
public:
BinaryDictionaryShortcutIterator(
const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy,
const int shortcutPos)
: mShortcutStructurePolicy(shortcutStructurePolicy),
mPos(shortcutStructurePolicy->getStartPos(shortcutPos)),
mHasNextShortcutTarget(shortcutPos != NOT_A_DICT_POS) {}
AK_FORCE_INLINE bool hasNextShortcutTarget() const {
return mHasNextShortcutTarget;
}
// Gets the shortcut target itself as an int string and put it to outTarget, put its length
// to outTargetLength, put whether it is whitelist to outIsWhitelist.
AK_FORCE_INLINE void nextShortcutTarget(
const int maxDepth, int *const outTarget, int *const outTargetLength,
bool *const outIsWhitelist) {
mShortcutStructurePolicy->getNextShortcut(maxDepth, outTarget, outTargetLength,
outIsWhitelist, &mHasNextShortcutTarget, &mPos);
}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryShortcutIterator);
const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
int mPos;
bool mHasNextShortcutTarget;
};
} // namespace latinime
#endif // LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H

View File

@ -19,21 +19,20 @@
#include "defines.h"
#include "suggest/core/dicnode/dic_node_utils.h"
#include "suggest/core/dictionary/terminal_attributes.h"
#include "suggest/core/dictionary/binary_dictionary_shortcut_iterator.h"
namespace latinime {
class ShortcutUtils {
public:
static int outputShortcuts(const TerminalAttributes *const terminalAttributes,
static int outputShortcuts(BinaryDictionaryShortcutIterator *const shortcutIt,
int outputWordIndex, const int finalScore, int *const outputCodePoints,
int *const frequencies, int *const outputTypes, const bool sameAsTyped) {
TerminalAttributes::ShortcutIterator iterator = terminalAttributes->getShortcutIterator();
int shortcutTarget[MAX_WORD_LENGTH];
while (iterator.hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
while (shortcutIt->hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
bool isWhilelist;
int shortcutTargetStringLength;
iterator.nextShortcutTarget(MAX_WORD_LENGTH, shortcutTarget,
shortcutIt->nextShortcutTarget(MAX_WORD_LENGTH, shortcutTarget,
&shortcutTargetStringLength, &isWhilelist);
int shortcutScore;
int kind;

View File

@ -1,80 +0,0 @@
/*
* 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 <stdint.h>
#include "suggest/core/policy/dictionary_shortcuts_structure_policy.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 {
public:
ShortcutIterator(const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy,
const int shortcutPos, const bool hasShortcutList)
: mShortcutStructurePolicy(shortcutStructurePolicy), mPos(shortcutPos),
mHasNextShortcutTarget(hasShortcutList) {}
inline bool hasNextShortcutTarget() const {
return mHasNextShortcutTarget;
}
// Gets the shortcut target itself as an int string and put it to outTarget, put its length
// to outTargetLength, put whether it is whitelist to outIsWhitelist.
AK_FORCE_INLINE void nextShortcutTarget(
const int maxDepth, int *const outTarget, int *const outTargetLength,
bool *const outIsWhitelist) {
mShortcutStructurePolicy->getNextShortcut(maxDepth, outTarget, outTargetLength,
outIsWhitelist, &mHasNextShortcutTarget, &mPos);
}
private:
const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
int mPos;
bool mHasNextShortcutTarget;
};
TerminalAttributes(const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy,
const int shortcutPos)
: mShortcutStructurePolicy(shortcutStructurePolicy),
mShortcutListSizePos(shortcutPos) {}
inline ShortcutIterator getShortcutIterator() const {
int shortcutPos = mShortcutListSizePos;
const bool hasShortcutList = shortcutPos != NOT_A_DICT_POS;
if (hasShortcutList) {
shortcutPos = mShortcutStructurePolicy->getStartPos(shortcutPos);
}
// shortcutPos is never used if hasShortcutList is false.
return ShortcutIterator(mShortcutStructurePolicy, shortcutPos, hasShortcutList);
}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalAttributes);
const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
const int mShortcutListSizePos;
};
} // namespace latinime
#endif // LATINIME_TERMINAL_ATTRIBUTES_H

View File

@ -21,10 +21,10 @@
#include "suggest/core/dicnode/dic_node_vector.h"
// TODO: Use DictionaryStructurePolicy instead of BinaryDictionaryInfo.
#include "suggest/core/dictionary/binary_dictionary_info.h"
#include "suggest/core/dictionary/binary_dictionary_shortcut_iterator.h"
#include "suggest/core/dictionary/dictionary.h"
#include "suggest/core/dictionary/digraph_utils.h"
#include "suggest/core/dictionary/shortcut_utils.h"
#include "suggest/core/dictionary/terminal_attributes.h"
#include "suggest/core/layout/proximity_info.h"
#include "suggest/core/policy/scoring.h"
#include "suggest/core/policy/traversal.h"
@ -214,13 +214,13 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
if (!terminalDicNode->hasMultipleWords()) {
const DictionaryStructureWithBufferPolicy *const structurePolicy =
traverseSession->getBinaryDictionaryInfo()->getStructurePolicy();
const TerminalAttributes terminalAttributes(
BinaryDictionaryShortcutIterator shortcutIt(
structurePolicy->getShortcutsStructurePolicy(),
structurePolicy->getShortcutPositionOfNode(terminalDicNode->getPos()));
// Shortcut is not supported for multiple words suggestions.
// TODO: Check shortcuts during traversal for multiple words suggestions.
const bool sameAsTyped = TRAVERSAL->sameAsTyped(traverseSession, terminalDicNode);
outputWordIndex = ShortcutUtils::outputShortcuts(&terminalAttributes, outputWordIndex,
outputWordIndex = ShortcutUtils::outputShortcuts(&shortcutIt, outputWordIndex,
finalScore, outputCodePoints, frequencies, outputTypes, sameAsTyped);
}
DicNode::managedDelete(terminalDicNode);