FST
openfst-1.8.4
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.4
src
bin
fstconcat-main.cc
Go to the documentation of this file.
1
// Copyright 2005-2024 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
//
18
// Concatenates two FSTs.
19
20
#include <cstring>
21
#include <memory>
22
#include <string>
23
24
#include <
fst/flags.h
>
25
#include <
fst/log.h
>
26
#include <
fst/script/concat.h
>
27
#include <
fst/script/fst-class.h
>
28
29
int
fstconcat_main
(
int
argc,
char
**argv) {
30
namespace
s =
fst::script
;
31
using
fst::script::FstClass
;
32
using
fst::script::MutableFstClass
;
33
34
std::string usage =
"Concatenates two FSTs.\n\n Usage: "
;
35
usage += argv[0];
36
usage +=
" in1.fst in2.fst [out.fst]\n"
;
37
38
SET_FLAGS
(usage.c_str(), &argc, &argv,
true
);
39
if
(argc < 3 || argc > 4) {
40
ShowUsage
();
41
return
1;
42
}
43
44
const
std::string in1_name = strcmp(argv[1],
"-"
) == 0 ?
""
: argv[1];
45
const
std::string in2_name = strcmp(argv[2],
"-"
) == 0 ?
""
: argv[2];
46
const
std::string out_name =
47
argc > 3 && strcmp(argv[3],
"-"
) != 0 ? argv[3] :
""
;
48
49
if
(in1_name.empty() && in2_name.empty()) {
50
LOG
(ERROR) << argv[0] <<
": Can't take both inputs from standard input"
;
51
return
1;
52
}
53
54
std::unique_ptr<MutableFstClass> fst1(MutableFstClass::Read(in1_name,
true
));
55
if
(!fst1)
return
1;
56
57
std::unique_ptr<FstClass> fst2(FstClass::Read(in2_name));
58
if
(!fst2)
return
1;
59
60
s::Concat
(fst1.get(), *fst2);
61
62
return
!fst1->Write(out_name);
63
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
fst-class.h
LOG
#define LOG(type)
Definition:
log.h:53
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
fstconcat_main
int fstconcat_main(int argc, char **argv)
Definition:
fstconcat-main.cc:29
fst::script
Definition:
compressscript.cc:26
fst::Concat
void Concat(MutableFst< Arc > *fst1, const Fst< Arc > &fst2)
Definition:
concat.h:55
fst::script::MutableFstClass
Definition:
fst-class.h:460
flags.h
fst::script::FstClass
Definition:
fst-class.h:313
concat.h
log.h
Generated by
1.8.11