FST
openfst-1.8.3
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.3
src
bin
fstprune-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
// Prunes states and arcs of an FST w.r.t. the shortest path weight.
19
20
#include <cstring>
21
#include <memory>
22
#include <string>
23
24
#include <
fst/flags.h
>
25
#include <
fst/script/fst-class.h
>
26
#include <
fst/script/prune.h
>
27
#include <
fst/script/weight-class.h
>
28
29
DECLARE_double
(delta);
30
DECLARE_int64
(nstate);
31
DECLARE_string
(weight);
32
33
int
fstprune_main
(
int
argc,
char
**argv) {
34
namespace
s =
fst::script
;
35
using
fst::script::MutableFstClass
;
36
using
fst::script::WeightClass
;
37
38
std::string usage =
"Prunes states and arcs of an FST.\n\n Usage: "
;
39
usage += argv[0];
40
usage +=
" [in.fst [out.fst]]\n"
;
41
42
SET_FLAGS
(usage.c_str(), &argc, &argv,
true
);
43
if
(argc > 3) {
44
ShowUsage
();
45
return
1;
46
}
47
48
const
std::string in_name =
49
(argc > 1 && strcmp(argv[1],
"-"
) != 0) ? argv[1] :
""
;
50
const
std::string out_name =
51
(argc > 2 && strcmp(argv[2],
"-"
) != 0) ? argv[2] :
""
;
52
53
std::unique_ptr<MutableFstClass>
fst
(MutableFstClass::Read(in_name,
true
));
54
if
(!fst)
return
1;
55
56
const
auto
weight_threshold =
57
FST_FLAGS_weight.empty()
58
? WeightClass::Zero(fst->WeightType())
59
: WeightClass(fst->WeightType(), FST_FLAGS_weight);
60
61
s::Prune
(fst.get(), weight_threshold, FST_FLAGS_nstate,
62
FST_FLAGS_delta);
63
64
return
!fst->Write(out_name);
65
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
fst-class.h
weight-class.h
fst
Definition:
compact16_acceptor-fst.cc:26
prune.h
fstprune_main
int fstprune_main(int argc, char **argv)
Definition:
fstprune-main.cc:33
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
fst::Prune
void Prune(MutableFst< Arc > *fst, const PruneOptions< Arc, ArcFilter > &opts=PruneOptions< Arc, ArcFilter >())
Definition:
prune.h:114
fst::script
Definition:
compressscript.cc:27
fst::script::WeightClass
Definition:
weight-class.h:111
fst::script::MutableFstClass
Definition:
fst-class.h:450
flags.h
DECLARE_int64
DECLARE_int64(nstate)
DECLARE_double
DECLARE_double(delta)
DECLARE_string
DECLARE_string(weight)
Generated by
1.8.11