Home | History | Annotate | Download | only in fel
      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 #include "lang_id/common/fel/task-context.h"
     18 
     19 #include <string>
     20 
     21 #include "lang_id/common/lite_strings/numbers.h"
     22 
     23 namespace libtextclassifier3 {
     24 namespace mobile {
     25 
     26 string TaskContext::GetInputPath(const string &name) const {
     27   auto it = inputs_.find(name);
     28   if (it != inputs_.end()) {
     29     return it->second;
     30   }
     31   return "";
     32 }
     33 
     34 void TaskContext::SetInputPath(const string &name, const string &path) {
     35   inputs_[name] = path;
     36 }
     37 
     38 string TaskContext::Get(const string &name, const char *defval) const {
     39   auto it = parameters_.find(name);
     40   if (it != parameters_.end()) {
     41     return it->second;
     42   }
     43   return defval;
     44 }
     45 
     46 int TaskContext::Get(const string &name, int defval) const {
     47   const string s = Get(name, "");
     48   int value = defval;
     49   if (LiteAtoi(s, &value)) {
     50     return value;
     51   }
     52   return defval;
     53 }
     54 
     55 float TaskContext::Get(const string &name, float defval) const {
     56   const string s = Get(name, "");
     57   float value = defval;
     58   if (LiteAtof(s, &value)) {
     59     return value;
     60   }
     61   return defval;
     62 }
     63 
     64 bool TaskContext::Get(const string &name, bool defval) const {
     65   string value = Get(name, "");
     66   return value.empty() ? defval : value == "true";
     67 }
     68 
     69 void TaskContext::SetParameter(const string &name, const string &value) {
     70   parameters_[name] = value;
     71 }
     72 
     73 }  // namespace mobile
     74 }  // namespace nlp_saft
     75