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

Commit fd9d0ee9 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'smartselect'

* changes:
  Introduce a model file for language detection.
  Change package for LangId and SmartSelection.
parents afcea288 c3e7a4fa
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -13,16 +13,13 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.text;
package android.view.textclassifier;

/**
 *  Java wrapper for LangId native library interface.
 *  This class is used to detect languages in text.
 *  @hide
 */
public final class LangId {
    // TODO: Move this to android.view.textclassifier and make it package-private.
    // We'll have to update the native library code to do this.
final class LangId {

    static {
        System.loadLibrary("smart-selection_jni");
@@ -33,7 +30,7 @@ public final class LangId {
    /**
     * Creates a new instance of LangId predictor, using the provided model image.
     */
    public LangId(int fd) {
    LangId(int fd) {
        mModelPtr = nativeNew(fd);
    }

+3 −6
Original line number Diff line number Diff line
@@ -14,16 +14,13 @@
 * limitations under the License.
 */

package android.text;
package android.view.textclassifier;

/**
 *  Java wrapper for SmartSelection native library interface.
 *  This library is used for detecting entities in text.
 *  @hide
 */
public final class SmartSelection {
    // TODO: Move this to android.view.textclassifier and make it package-private.
    // We'll have to update the native library code to do this.
final class SmartSelection {

    static {
        System.loadLibrary("smart-selection_jni");
@@ -35,7 +32,7 @@ public final class SmartSelection {
     * Creates a new instance of SmartSelect predictor, using the provided model image,
     * given as a file descriptor.
     */
    public SmartSelection(int fd) {
    SmartSelection(int fd) {
        mCtx = nativeNew(fd);
    }

+10 −9
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.view.textclassifier;
import android.annotation.NonNull;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.text.LangId;
import android.util.Log;

import com.android.internal.util.Preconditions;
@@ -45,8 +44,9 @@ public final class TextClassificationManager {
    private final Object mLangIdLock = new Object();

    private final Context mContext;
    // TODO: Implement a way to close the file descriptor.
    private ParcelFileDescriptor mFd;
    // TODO: Implement a way to close the file descriptors.
    private ParcelFileDescriptor mSmartSelectionFd;
    private ParcelFileDescriptor mLangIdFd;
    private TextClassifier mDefault;
    private LangId mLangId;

@@ -62,10 +62,10 @@ public final class TextClassificationManager {
        synchronized (mTextClassifierLock) {
            if (mDefault == null) {
                try {
                    mFd = ParcelFileDescriptor.open(
                    mSmartSelectionFd = ParcelFileDescriptor.open(
                            new File("/etc/assistant/smart-selection.model"),
                            ParcelFileDescriptor.MODE_READ_ONLY);
                    mDefault = new TextClassifierImpl(mContext, mFd);
                    mDefault = new TextClassifierImpl(mContext, mSmartSelectionFd);
                } catch (FileNotFoundException e) {
                    Log.e(LOG_TAG, "Error accessing 'text classifier selection' model file.", e);
                    mDefault = TextClassifier.NO_OP;
@@ -100,12 +100,13 @@ public final class TextClassificationManager {
        return Collections.emptyList();
    }

    private LangId getLanguageDetector() {
    private LangId getLanguageDetector() throws FileNotFoundException {
        synchronized (mLangIdLock) {
            if (mLangId == null) {
                // TODO: Use a file descriptor as soon as we start to depend on a model file
                // for language detection.
                mLangId = new LangId(0);
                mLangIdFd = ParcelFileDescriptor.open(
                        new File("/etc/assistant/lang-id.model"),
                        ParcelFileDescriptor.MODE_READ_ONLY);
                mLangId = new LangId(mLangIdFd.getFd());
            }
            return mLangId;
        }
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.graphics.drawable.Drawable;
import android.icu.text.BreakIterator;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.text.SmartSelection;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.method.WordIterator;