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