1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.textclassifier; 18 19 import com.android.textclassifier.common.ModelFile; 20 import com.android.textclassifier.common.ModelType; 21 import java.io.File; 22 import java.io.IOException; 23 24 /** Utils to access test data files. */ 25 public final class TestDataUtils { 26 private static final String TEST_ANNOTATOR_MODEL_PATH = "testdata/annotator.model"; 27 private static final String TEST_ACTIONS_MODEL_PATH = "testdata/actions.model"; 28 private static final String TEST_LANGID_MODEL_PATH = "testdata/langid.model"; 29 30 /** Returns the root folder that contains the test data. */ getTestDataFolder()31 private static File getTestDataFolder() { 32 return new File("/data/local/tmp/TextClassifierServiceTest/"); 33 } 34 getTestAnnotatorModelFile()35 public static File getTestAnnotatorModelFile() { 36 return new File(getTestDataFolder(), TEST_ANNOTATOR_MODEL_PATH); 37 } 38 getTestAnnotatorModelFileWrapped()39 public static ModelFile getTestAnnotatorModelFileWrapped() throws IOException { 40 return ModelFile.createFromRegularFile(getTestAnnotatorModelFile(), ModelType.ANNOTATOR); 41 } 42 getTestActionsModelFile()43 public static File getTestActionsModelFile() { 44 return new File(getTestDataFolder(), TEST_ACTIONS_MODEL_PATH); 45 } 46 getTestActionsModelFileWrapped()47 public static ModelFile getTestActionsModelFileWrapped() throws IOException { 48 return ModelFile.createFromRegularFile( 49 getTestActionsModelFile(), ModelType.ACTIONS_SUGGESTIONS); 50 } 51 getLangIdModelFile()52 public static File getLangIdModelFile() { 53 return new File(getTestDataFolder(), TEST_LANGID_MODEL_PATH); 54 } 55 getLangIdModelFileWrapped()56 public static ModelFile getLangIdModelFileWrapped() throws IOException { 57 return ModelFile.createFromRegularFile(getLangIdModelFile(), ModelType.LANG_ID); 58 } 59 TestDataUtils()60 private TestDataUtils() {} 61 } 62