FST  openfst-1.8.2
OpenFst Library
far-class.cc
Go to the documentation of this file.
1 // Copyright 2005-2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 
19 
20 #include <string>
21 #include <utility>
22 
24 #include <fst/arc.h>
25 #include <fst/script/script-impl.h>
26 
27 namespace fst {
28 namespace script {
29 
30 // FarReaderClass.
31 
32 std::unique_ptr<FarReaderClass> FarReaderClass::Open(
33  const std::string &source) {
34  const std::vector<std::string> sources{source};
35  return FarReaderClass::Open(sources);
36 }
37 
38 std::unique_ptr<FarReaderClass> FarReaderClass::Open(
39  const std::vector<std::string> &sources) {
40  if (sources.empty()) {
41  LOG(ERROR) << "FarReaderClass::Open: No files specified";
42  return nullptr;
43  }
44  auto arc_type = LoadArcTypeFromFar(sources.front());
45  if (arc_type.empty()) {
46  LOG(ERROR) << "FarReaderClass::Open: File could not be opened: "
47  << sources.front();
48  return nullptr;
49  }
50  // TODO(jrosenstock): What if we have an empty FAR for the first one,
51  // then non-empty? We need to check all input FARs.
52  OpenFarReaderClassArgs args(sources);
53  args.retval = nullptr;
54  Apply<Operation<OpenFarReaderClassArgs>>("OpenFarReaderClass", arc_type,
55  &args);
56  return std::move(args.retval);
57 }
58 
63 
64 // FarWriterClass.
65 
66 std::unique_ptr<FarWriterClass> FarWriterClass::Create(
67  const std::string &source, const std::string &arc_type, FarType type) {
68  CreateFarWriterClassInnerArgs iargs(source, type);
69  CreateFarWriterClassArgs args(iargs);
70  args.retval = nullptr;
71  Apply<Operation<CreateFarWriterClassArgs>>("CreateFarWriterClass", arc_type,
72  &args);
73  return std::move(args.retval);
74 }
75 
82 
83 } // namespace script
84 } // namespace fst
#define LOG(type)
Definition: log.h:49
static std::unique_ptr< FarWriterClass > Create(const std::string &source, const std::string &arc_type, FarType type=FarType::DEFAULT)
Definition: far-class.cc:66
std::pair< const std::string &, FarType > CreateFarWriterClassInnerArgs
Definition: far-class.h:217
FarType
Definition: far.h:43
REGISTER_FST_OPERATION(OpenFarReaderClass, StdArc, OpenFarReaderClassArgs)
std::string LoadArcTypeFromFar(const std::string &far_source)
Definition: script-impl.cc:31
void CreateFarWriterClass(CreateFarWriterClassArgs *args)
Definition: far-class.h:272
friend void OpenFarReaderClass(OpenFarReaderClassArgs *args)
Definition: far-class.h:159
static std::unique_ptr< FarReaderClass > Open(const std::string &source)
Definition: far-class.cc:32