FST
openfst-1.8.4
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.4
src
bin
fstepsnormalize-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
// Epsilon-normalizes an FST.
19
20
#include <cstring>
21
#include <memory>
22
#include <string>
23
24
#include <
fst/flags.h
>
25
#include <
fst/log.h
>
26
#include <
fst/epsnormalize.h
>
27
#include <
fst/script/epsnormalize.h
>
28
#include <
fst/script/fst-class.h
>
29
#include <
fst/script/getters.h
>
30
31
DECLARE_string
(eps_norm_type);
32
33
int
fstepsnormalize_main
(
int
argc,
char
**argv) {
34
namespace
s =
fst::script
;
35
using
fst::EpsNormalizeType
;
36
using
fst::script::FstClass
;
37
using
fst::script::VectorFstClass
;
38
39
std::string usage =
"Epsilon normalizes an FST.\n\n Usage: "
;
40
usage += argv[0];
41
usage +=
" [in.fst [out.fst]]\n"
;
42
43
SET_FLAGS
(usage.c_str(), &argc, &argv,
true
);
44
if
(argc > 3) {
45
ShowUsage
();
46
return
1;
47
}
48
49
const
std::string in_name =
50
(argc > 1 && strcmp(argv[1],
"-"
) != 0) ? argv[1] :
""
;
51
const
std::string out_name =
52
(argc > 2 && strcmp(argv[2],
"-"
) != 0) ? argv[2] :
""
;
53
54
std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
55
if
(!ifst)
return
1;
56
57
VectorFstClass ofst(ifst->ArcType());
58
59
EpsNormalizeType
eps_norm_type;
60
if
(!
s::GetEpsNormalizeType
(FST_FLAGS_eps_norm_type,
61
&eps_norm_type)) {
62
LOG
(ERROR) << argv[0]
63
<<
": Unknown or unsupported epsilon normalization type: "
64
<< FST_FLAGS_eps_norm_type;
65
return
1;
66
}
67
68
s::EpsNormalize
(*ifst, &ofst, eps_norm_type);
69
70
return
!ofst.Write(out_name);
71
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
fst-class.h
getters.h
LOG
#define LOG(type)
Definition:
log.h:53
DECLARE_string
DECLARE_string(eps_norm_type)
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
fst::EpsNormalizeType
EpsNormalizeType
Definition:
epsnormalize.h:38
fstepsnormalize_main
int fstepsnormalize_main(int argc, char **argv)
Definition:
fstepsnormalize-main.cc:33
fst::script
Definition:
compressscript.cc:26
fst::EpsNormalize
void EpsNormalize(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, EpsNormalizeType type=EPS_NORM_INPUT)
Definition:
epsnormalize.h:52
fst::script::GetEpsNormalizeType
bool GetEpsNormalizeType(std::string_view str, EpsNormalizeType *eps_norm_type)
Definition:
getters.cc:111
epsnormalize.h
flags.h
epsnormalize.h
fst::script::VectorFstClass
Definition:
fst-class.h:562
fst::script::FstClass
Definition:
fst-class.h:313
log.h
Generated by
1.8.11