Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a347723 authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Move FormatOptions and FileHeader to FormatSpec.

Change-Id: I232e35598635113bf2c81825669c744aadc79efe
parent 81d97eec
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.util.Log;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -90,8 +91,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
    private final DictionaryController mLocalDictionaryController = new DictionaryController();

    private static final int BINARY_DICT_VERSION = 1;
    private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
            new BinaryDictInputOutput.FormatOptions(BINARY_DICT_VERSION);
    private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
            new FormatSpec.FormatOptions(BINARY_DICT_VERSION);

    /**
     * Abstract method for loading the unigrams and bigrams of a given dictionary in a background
+1 −1
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ package com.android.inputmethod.latin;
import android.util.Log;

import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FormatOptions;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.PendingAttribute;
+2 −34
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
@@ -107,40 +109,6 @@ public class BinaryDictInputOutput {
        }
    }

    /**
     * Options about file format.
     */
    public static class FormatOptions {
        public final int mVersion;
        public final boolean mHasParentAddress;
        public FormatOptions(final int version) {
            this(version, false);
        }
        public FormatOptions(final int version, final boolean hasParentAddress) {
            mVersion = version;
            if (version < FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
                throw new RuntimeException("Parent addresses are only supported with versions "
                        + FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
            }
            mHasParentAddress = hasParentAddress;
        }
    }

    /**
     * Class representing file header.
     */
    private static final class FileHeader {
        public final int mHeaderSize;
        public final DictionaryOptions mDictionaryOptions;
        public final FormatOptions mFormatOptions;
        public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
                final FormatOptions formatOptions) {
            mHeaderSize = headerSize;
            mDictionaryOptions = dictionaryOptions;
            mFormatOptions = formatOptions;
        }
    }

    /**
     * A class grouping utility function for our specific character encoding.
     */
+35 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;

/**
 * Dictionary File Format Specification.
@@ -194,6 +195,40 @@ public final class FormatSpec {
    static final int MAX_TERMINAL_FREQUENCY = 255;
    static final int MAX_BIGRAM_FREQUENCY = 15;

    /**
     * Options about file format.
     */
    public static class FormatOptions {
        public final int mVersion;
        public final boolean mHasParentAddress;
        public FormatOptions(final int version) {
            this(version, false);
        }
        public FormatOptions(final int version, final boolean hasParentAddress) {
            mVersion = version;
            if (version < FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
                throw new RuntimeException("Parent addresses are only supported with versions "
                        + FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
            }
            mHasParentAddress = hasParentAddress;
        }
    }

    /**
     * Class representing file header.
     */
    static final class FileHeader {
        public final int mHeaderSize;
        public final DictionaryOptions mDictionaryOptions;
        public final FormatOptions mFormatOptions;
        public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
                final FormatOptions formatOptions) {
            mHeaderSize = headerSize;
            mDictionaryOptions = dictionaryOptions;
            mFormatOptions = formatOptions;
        }
    }

    private FormatSpec() {
        // This utility class is not publicly instantiable.
    }
+2 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.latin.UserHistoryDictIOUtils.BigramDictionaryInterface;
import com.android.inputmethod.latin.UserHistoryDictIOUtils.OnAddWordListener;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;

@@ -45,8 +46,7 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
    private static final int UNIGRAM_FREQUENCY = 50;
    private static final int BIGRAM_FREQUENCY = 100;
    private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>();
    private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
            new BinaryDictInputOutput.FormatOptions(2);
    private static final FormatSpec.FormatOptions FORMAT_OPTIONS = new FormatSpec.FormatOptions(2);

    /**
     * Return same frequency for all words and bigrams
Loading