Merge "Separate ProbabilityInfo form WordProperty."
This commit is contained in:
commit
e42380a471
2 changed files with 55 additions and 24 deletions
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.inputmethod.latin.makedict;
|
||||||
|
|
||||||
|
import com.android.inputmethod.latin.BinaryDictionary;
|
||||||
|
|
||||||
|
public final class ProbabilityInfo {
|
||||||
|
public final int mProbability;
|
||||||
|
// mTimestamp, mLevel and mCount are historical info. These values are depend on the
|
||||||
|
// implementation in native code; thus, we must not use them and have any assumptions about
|
||||||
|
// them except for tests.
|
||||||
|
public final int mTimestamp;
|
||||||
|
public final int mLevel;
|
||||||
|
public final int mCount;
|
||||||
|
|
||||||
|
public ProbabilityInfo(final int probability) {
|
||||||
|
this(probability, BinaryDictionary.NOT_A_VALID_TIMESTAMP, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProbabilityInfo(final int probability, final int timestamp, final int level,
|
||||||
|
final int count) {
|
||||||
|
mProbability = probability;
|
||||||
|
mTimestamp = timestamp;
|
||||||
|
mLevel = level;
|
||||||
|
mCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return mTimestamp + ":" + mLevel + ":" + mCount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package com.android.inputmethod.latin.utils;
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
import com.android.inputmethod.latin.BinaryDictionary;
|
import com.android.inputmethod.latin.BinaryDictionary;
|
||||||
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
||||||
|
import com.android.inputmethod.latin.makedict.ProbabilityInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -37,28 +38,12 @@ public class WordProperty {
|
||||||
public final ArrayList<ProbabilityInfo> mBigramProbabilityInfo = CollectionUtils.newArrayList();
|
public final ArrayList<ProbabilityInfo> mBigramProbabilityInfo = CollectionUtils.newArrayList();
|
||||||
public final ArrayList<WeightedString> mShortcutTargets = CollectionUtils.newArrayList();
|
public final ArrayList<WeightedString> mShortcutTargets = CollectionUtils.newArrayList();
|
||||||
|
|
||||||
// TODO: Use this kind of Probability class for dictionary read/write code under the makedict
|
private static ProbabilityInfo createProbabilityInfoFromArray(final int[] probabilityInfo) {
|
||||||
// package.
|
return new ProbabilityInfo(
|
||||||
public static final class ProbabilityInfo {
|
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_PROBABILITY_INDEX],
|
||||||
public final int mProbability;
|
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_TIMESTAMP_INDEX],
|
||||||
// mTimestamp, mLevel and mCount are historical info. These values are depend on the
|
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_LEVEL_INDEX],
|
||||||
// implementation in native code; thus, we must not use them and have any assumptions about
|
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_COUNT_INDEX]);
|
||||||
// them except for tests.
|
|
||||||
public final int mTimestamp;
|
|
||||||
public final int mLevel;
|
|
||||||
public final int mCount;
|
|
||||||
|
|
||||||
public ProbabilityInfo(final int[] probabilityInfo) {
|
|
||||||
mProbability = probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_PROBABILITY_INDEX];
|
|
||||||
mTimestamp = probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_TIMESTAMP_INDEX];
|
|
||||||
mLevel = probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_LEVEL_INDEX];
|
|
||||||
mCount = probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_COUNT_INDEX];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return mTimestamp + ":" + mLevel + ":" + mCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This represents invalid word when the probability is BinaryDictionary.NOT_A_PROBABILITY.
|
// This represents invalid word when the probability is BinaryDictionary.NOT_A_PROBABILITY.
|
||||||
|
@ -73,14 +58,14 @@ public class WordProperty {
|
||||||
mIsBlacklisted = isBlacklisted;
|
mIsBlacklisted = isBlacklisted;
|
||||||
mHasBigrams = hasBigram;
|
mHasBigrams = hasBigram;
|
||||||
mHasShortcuts = hasShortcuts;
|
mHasShortcuts = hasShortcuts;
|
||||||
mProbabilityInfo = new ProbabilityInfo(probabilityInfo);
|
mProbabilityInfo = createProbabilityInfoFromArray(probabilityInfo);
|
||||||
|
|
||||||
final int bigramTargetCount = bigramTargets.size();
|
final int bigramTargetCount = bigramTargets.size();
|
||||||
for (int i = 0; i < bigramTargetCount; i++) {
|
for (int i = 0; i < bigramTargetCount; i++) {
|
||||||
final String bigramTargetString =
|
final String bigramTargetString =
|
||||||
StringUtils.getStringFromNullTerminatedCodePointArray(bigramTargets.get(i));
|
StringUtils.getStringFromNullTerminatedCodePointArray(bigramTargets.get(i));
|
||||||
final ProbabilityInfo bigramProbability =
|
final ProbabilityInfo bigramProbability =
|
||||||
new ProbabilityInfo(bigramProbabilityInfo.get(i));
|
createProbabilityInfoFromArray(bigramProbabilityInfo.get(i));
|
||||||
mBigramTargets.add(
|
mBigramTargets.add(
|
||||||
new WeightedString(bigramTargetString, bigramProbability.mProbability));
|
new WeightedString(bigramTargetString, bigramProbability.mProbability));
|
||||||
mBigramProbabilityInfo.add(bigramProbability);
|
mBigramProbabilityInfo.add(bigramProbability);
|
||||||
|
|
Loading…
Reference in a new issue