2012-08-08 10:40:44 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2014-11-06 11:07:28 +00:00
|
|
|
import com.android.inputmethod.latin.common.NativeSuggestOptions;
|
2015-02-05 21:27:36 +00:00
|
|
|
import com.android.inputmethod.latin.define.DecoderSpecificConstants;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.JniUtils;
|
|
|
|
|
2012-08-08 10:40:44 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class DicTraverseSession {
|
2012-08-08 10:40:44 +00:00
|
|
|
static {
|
|
|
|
JniUtils.loadNativeLibrary();
|
|
|
|
}
|
2014-06-17 08:50:32 +00:00
|
|
|
// Must be equal to MAX_RESULTS in native/jni/src/defines.h
|
|
|
|
private static final int MAX_RESULTS = 18;
|
2015-02-05 21:27:36 +00:00
|
|
|
public final int[] mInputCodePoints =
|
|
|
|
new int[DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH];
|
2014-06-25 05:14:37 +00:00
|
|
|
public final int[][] mPrevWordCodePointArrays =
|
2015-02-05 21:27:36 +00:00
|
|
|
new int[DecoderSpecificConstants.MAX_PREV_WORD_COUNT_FOR_N_GRAM][];
|
2014-06-25 05:14:37 +00:00
|
|
|
public final boolean[] mIsBeginningOfSentenceArray =
|
2015-02-05 21:27:36 +00:00
|
|
|
new boolean[DecoderSpecificConstants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
|
2014-06-17 08:50:32 +00:00
|
|
|
public final int[] mOutputSuggestionCount = new int[1];
|
|
|
|
public final int[] mOutputCodePoints =
|
2015-02-05 21:27:36 +00:00
|
|
|
new int[DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH * MAX_RESULTS];
|
2014-06-17 08:50:32 +00:00
|
|
|
public final int[] mSpaceIndices = new int[MAX_RESULTS];
|
|
|
|
public final int[] mOutputScores = new int[MAX_RESULTS];
|
|
|
|
public final int[] mOutputTypes = new int[MAX_RESULTS];
|
|
|
|
// Only one result is ever used
|
|
|
|
public final int[] mOutputAutoCommitFirstWordConfidence = new int[1];
|
2014-09-12 13:26:09 +00:00
|
|
|
public final float[] mInputOutputWeightOfLangModelVsSpatialModel = new float[1];
|
2014-06-17 08:50:32 +00:00
|
|
|
|
2015-01-29 22:45:24 +00:00
|
|
|
public final NativeSuggestOptions mNativeSuggestOptions = new NativeSuggestOptions();
|
2012-08-14 13:49:59 +00:00
|
|
|
|
2013-09-12 09:47:56 +00:00
|
|
|
private static native long setDicTraverseSessionNative(String locale, long dictSize);
|
2013-01-11 16:18:00 +00:00
|
|
|
private static native void initDicTraverseSessionNative(long nativeDicTraverseSession,
|
2012-08-10 16:10:31 +00:00
|
|
|
long dictionary, int[] previousWord, int previousWordLength);
|
2013-01-11 16:18:00 +00:00
|
|
|
private static native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
|
2012-08-08 10:40:44 +00:00
|
|
|
|
|
|
|
private long mNativeDicTraverseSession;
|
|
|
|
|
2013-09-12 09:47:56 +00:00
|
|
|
public DicTraverseSession(Locale locale, long dictionary, long dictSize) {
|
2012-08-08 10:40:44 +00:00
|
|
|
mNativeDicTraverseSession = createNativeDicTraverseSession(
|
2013-09-12 09:47:56 +00:00
|
|
|
locale != null ? locale.toString() : "", dictSize);
|
2012-08-14 13:49:59 +00:00
|
|
|
initSession(dictionary);
|
2012-08-08 10:40:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 12:23:25 +00:00
|
|
|
public long getSession() {
|
|
|
|
return mNativeDicTraverseSession;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:23:08 +00:00
|
|
|
public void initSession(long dictionary) {
|
|
|
|
initSession(dictionary, null, 0);
|
2012-08-09 03:42:12 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 14:23:08 +00:00
|
|
|
public void initSession(long dictionary, int[] previousWord, int previousWordLength) {
|
2012-08-10 16:10:31 +00:00
|
|
|
initDicTraverseSessionNative(
|
|
|
|
mNativeDicTraverseSession, dictionary, previousWord, previousWordLength);
|
2012-08-09 03:42:12 +00:00
|
|
|
}
|
2012-08-08 10:40:44 +00:00
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
private static long createNativeDicTraverseSession(String locale, long dictSize) {
|
2013-09-12 09:47:56 +00:00
|
|
|
return setDicTraverseSessionNative(locale, dictSize);
|
2012-08-08 10:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void closeInternal() {
|
|
|
|
if (mNativeDicTraverseSession != 0) {
|
|
|
|
releaseDicTraverseSessionNative(mNativeDicTraverseSession);
|
|
|
|
mNativeDicTraverseSession = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
closeInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
try {
|
|
|
|
closeInternal();
|
|
|
|
} finally {
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|