Refactor a method
Rename it, rename parameters, and add a parameter that will be necessary soon. Also, rescale the bigram frequency as necessary. Bug: 6313806 Change-Id: I192543cfb6ab6bccda4a1a53c8e67fbf50a257b0main
parent
176354466e
commit
4455fe2c89
|
@ -722,15 +722,16 @@ public class BinaryDictInputOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the flag value for an attribute.
|
* Makes the flag value for a bigram.
|
||||||
*
|
*
|
||||||
* @param more whether there are more attributes after this one.
|
* @param more whether there are more bigrams after this one.
|
||||||
* @param offset the offset of the attribute.
|
* @param offset the offset of the bigram.
|
||||||
* @param frequency the frequency of the attribute, 0..15
|
* @param bigramFrequency the frequency of the bigram, 0..15.
|
||||||
|
* @param unigramFrequency the unigram frequency of the same word.
|
||||||
* @return the flags
|
* @return the flags
|
||||||
*/
|
*/
|
||||||
private static final int makeAttributeFlags(final boolean more, final int offset,
|
private static final int makeBigramFlags(final boolean more, final int offset,
|
||||||
final int frequency) {
|
final int bigramFrequency, final int unigramFrequency) {
|
||||||
int bigramFlags = (more ? FLAG_ATTRIBUTE_HAS_NEXT : 0)
|
int bigramFlags = (more ? FLAG_ATTRIBUTE_HAS_NEXT : 0)
|
||||||
+ (offset < 0 ? FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0);
|
+ (offset < 0 ? FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0);
|
||||||
switch (getByteSize(offset)) {
|
switch (getByteSize(offset)) {
|
||||||
|
@ -746,7 +747,7 @@ public class BinaryDictInputOutput {
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Strange offset size");
|
throw new RuntimeException("Strange offset size");
|
||||||
}
|
}
|
||||||
bigramFlags += frequency & FLAG_ATTRIBUTE_FREQUENCY;
|
bigramFlags += bigramFrequency & FLAG_ATTRIBUTE_FREQUENCY;
|
||||||
return bigramFlags;
|
return bigramFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,11 +855,14 @@ public class BinaryDictInputOutput {
|
||||||
final Iterator bigramIterator = group.mBigrams.iterator();
|
final Iterator bigramIterator = group.mBigrams.iterator();
|
||||||
while (bigramIterator.hasNext()) {
|
while (bigramIterator.hasNext()) {
|
||||||
final WeightedString bigram = (WeightedString)bigramIterator.next();
|
final WeightedString bigram = (WeightedString)bigramIterator.next();
|
||||||
final int addressOfBigram = findAddressOfWord(dict, bigram.mWord);
|
final CharGroup target =
|
||||||
|
FusionDictionary.findWordInTree(dict.mRoot, bigram.mWord);
|
||||||
|
final int addressOfBigram = target.mCachedAddress;
|
||||||
|
final int unigramFrequencyForThisWord = target.mFrequency;
|
||||||
++groupAddress;
|
++groupAddress;
|
||||||
final int offset = addressOfBigram - groupAddress;
|
final int offset = addressOfBigram - groupAddress;
|
||||||
int bigramFlags = makeAttributeFlags(bigramIterator.hasNext(), offset,
|
int bigramFlags = makeBigramFlags(bigramIterator.hasNext(), offset,
|
||||||
bigram.mFrequency);
|
bigram.mFrequency, unigramFrequencyForThisWord);
|
||||||
buffer[index++] = (byte)bigramFlags;
|
buffer[index++] = (byte)bigramFlags;
|
||||||
final int bigramShift = writeVariableAddress(buffer, index, Math.abs(offset));
|
final int bigramShift = writeVariableAddress(buffer, index, Math.abs(offset));
|
||||||
index += bigramShift;
|
index += bigramShift;
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class XmlDictInputOutput {
|
||||||
// In this version of the XML file, the bigram frequency is given as an int 0..XML_MAX
|
// In this version of the XML file, the bigram frequency is given as an int 0..XML_MAX
|
||||||
private final static int XML_MAX = 256;
|
private final static int XML_MAX = 256;
|
||||||
// In memory and in the binary dictionary the bigram frequency is 0..MEMORY_MAX
|
// In memory and in the binary dictionary the bigram frequency is 0..MEMORY_MAX
|
||||||
private final static int MEMORY_MAX = 16;
|
private final static int MEMORY_MAX = 256;
|
||||||
private final static int XML_TO_MEMORY_RATIO = XML_MAX / MEMORY_MAX;
|
private final static int XML_TO_MEMORY_RATIO = XML_MAX / MEMORY_MAX;
|
||||||
|
|
||||||
private String mSrc;
|
private String mSrc;
|
||||||
|
|
Loading…
Reference in New Issue