Merge "Separate ProbabilityInfo form WordProperty."
commit
e42380a471
|
@ -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.latin.BinaryDictionary;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
||||
import com.android.inputmethod.latin.makedict.ProbabilityInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -37,28 +38,12 @@ public class WordProperty {
|
|||
public final ArrayList<ProbabilityInfo> mBigramProbabilityInfo = CollectionUtils.newArrayList();
|
||||
public final ArrayList<WeightedString> mShortcutTargets = CollectionUtils.newArrayList();
|
||||
|
||||
// TODO: Use this kind of Probability class for dictionary read/write code under the makedict
|
||||
// package.
|
||||
public static 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[] 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;
|
||||
}
|
||||
private static ProbabilityInfo createProbabilityInfoFromArray(final int[] probabilityInfo) {
|
||||
return new ProbabilityInfo(
|
||||
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_PROBABILITY_INDEX],
|
||||
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_TIMESTAMP_INDEX],
|
||||
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_LEVEL_INDEX],
|
||||
probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_COUNT_INDEX]);
|
||||
}
|
||||
|
||||
// This represents invalid word when the probability is BinaryDictionary.NOT_A_PROBABILITY.
|
||||
|
@ -73,14 +58,14 @@ public class WordProperty {
|
|||
mIsBlacklisted = isBlacklisted;
|
||||
mHasBigrams = hasBigram;
|
||||
mHasShortcuts = hasShortcuts;
|
||||
mProbabilityInfo = new ProbabilityInfo(probabilityInfo);
|
||||
mProbabilityInfo = createProbabilityInfoFromArray(probabilityInfo);
|
||||
|
||||
final int bigramTargetCount = bigramTargets.size();
|
||||
for (int i = 0; i < bigramTargetCount; i++) {
|
||||
final String bigramTargetString =
|
||||
StringUtils.getStringFromNullTerminatedCodePointArray(bigramTargets.get(i));
|
||||
final ProbabilityInfo bigramProbability =
|
||||
new ProbabilityInfo(bigramProbabilityInfo.get(i));
|
||||
createProbabilityInfoFromArray(bigramProbabilityInfo.get(i));
|
||||
mBigramTargets.add(
|
||||
new WeightedString(bigramTargetString, bigramProbability.mProbability));
|
||||
mBigramProbabilityInfo.add(bigramProbability);
|
||||
|
|
Loading…
Reference in New Issue