• 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 #include "lang_id/fb_model/lang-id-from-fb.h"
18 
19 #include <string>
20 
21 #include "lang_id/fb_model/model-provider-from-fb.h"
22 
23 namespace libtextclassifier3 {
24 namespace mobile {
25 namespace lang_id {
26 
GetLangIdFromFlatbufferFile(const std::string & filename)27 std::unique_ptr<LangId> GetLangIdFromFlatbufferFile(
28     const std::string &filename) {
29   std::unique_ptr<ModelProvider> model_provider(
30       new ModelProviderFromFlatbuffer(filename));
31 
32   // NOTE: we avoid absl (including absl::make_unique), due to b/113350902
33   return std::unique_ptr<LangId>(  // NOLINT
34       new LangId(std::move(model_provider)));
35 }
36 
GetLangIdFromFlatbufferFileDescriptor(FileDescriptorOrHandle fd)37 std::unique_ptr<LangId> GetLangIdFromFlatbufferFileDescriptor(
38     FileDescriptorOrHandle fd) {
39   std::unique_ptr<ModelProvider> model_provider(
40       new ModelProviderFromFlatbuffer(fd));
41 
42   // NOTE: we avoid absl (including absl::make_unique), due to b/113350902
43   return std::unique_ptr<LangId>(  // NOLINT
44       new LangId(std::move(model_provider)));
45 }
46 
GetLangIdFromFlatbufferFileDescriptor(FileDescriptorOrHandle fd,size_t offset,size_t num_bytes)47 std::unique_ptr<LangId> GetLangIdFromFlatbufferFileDescriptor(
48     FileDescriptorOrHandle fd, size_t offset, size_t num_bytes) {
49   std::unique_ptr<ModelProvider> model_provider(
50       new ModelProviderFromFlatbuffer(fd, offset, num_bytes));
51 
52   // NOTE: we avoid absl (including absl::make_unique), due to b/113350902
53   return std::unique_ptr<LangId>(  // NOLINT
54       new LangId(std::move(model_provider)));
55 }
56 
GetLangIdFromFlatbufferBytes(const char * data,size_t num_bytes)57 std::unique_ptr<LangId> GetLangIdFromFlatbufferBytes(const char *data,
58                                                      size_t num_bytes) {
59   std::unique_ptr<ModelProvider> model_provider(
60       new ModelProviderFromFlatbuffer(data, num_bytes));
61 
62   // NOTE: we avoid absl (including absl::make_unique), due to b/113350902
63   return std::unique_ptr<LangId>(  // NOLINT
64       new LangId(std::move(model_provider)));
65 }
66 
67 }  // namespace lang_id
68 }  // namespace mobile
69 }  // namespace nlp_saft
70