• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TC3_STD_STRING_IMPORT
18 #define TC3_STD_STRING_IMPORT
19 #include <string>
20 
21 namespace libtextclassifier3 {
22 using string = std::string;
23 template <class CharT, class Traits = std::char_traits<CharT>,
24           class Allocator = std::allocator<CharT> >
25 using basic_string = std::basic_string<CharT, Traits, Allocator>;
26 }  // namespace libtextclassifier3
27 #endif
28 #ifndef NLP_SAFT_COMPONENTS_COMMON_MOBILE_FEL_TASK_CONTEXT_H_
29 #define NLP_SAFT_COMPONENTS_COMMON_MOBILE_FEL_TASK_CONTEXT_H_
30 
31 #include <map>
32 #include <string>
33 
34 namespace libtextclassifier3 {
35 namespace mobile {
36 
37 // Class that provides access to model parameter and inputs.
38 //
39 // Note: This class is related to the servers-side nlp_saft::TaskContext, but it
40 // has been simplified to reduce code dependencies.
41 class TaskContext {
42  public:
43   // Returns path for the input named |name|.  Returns empty string ("") if
44   // there is no input with that name.  Note: this can be a standard file path,
45   // or a path in a more special file system.
46   std::string GetInputPath(const std::string &name) const;
47 
48   // Sets path for input |name|.  Previous path, if any, is overwritten.
49   void SetInputPath(const std::string &name, const std::string &path);
50 
51   // Returns parameter value.  If the parameter is not specified in this
52   // context, the default value is returned.
53   std::string Get(const std::string &name, const char *defval) const;
54   int Get(const std::string &name, int defval) const;
55   float Get(const std::string &name, float defval) const;
56   bool Get(const std::string &name, bool defval) const;
57 
58   // Sets value of parameter |name| to |value|.
59   void SetParameter(const std::string &name, const std::string &value);
60 
61  private:
62   // Maps input name -> path.
63   std::map<std::string, std::string> inputs_;
64 
65   // Maps parameter name -> value.
66   std::map<std::string, std::string> parameters_;
67 };
68 
69 }  // namespace mobile
70 }  // namespace nlp_saft
71 
72 #endif  // NLP_SAFT_COMPONENTS_COMMON_MOBILE_FEL_TASK_CONTEXT_H_
73