FST
openfst-1.8.4
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.4
src
bin
fsttopsort-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
// Topologically sorts 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/script/fst-class.h
>
27
#include <
fst/script/topsort.h
>
28
29
int
fsttopsort_main
(
int
argc,
char
**argv) {
30
namespace
s =
fst::script
;
31
using
fst::script::MutableFstClass
;
32
33
std::string usage =
"Topologically sorts an FST.\n\n Usage: "
;
34
usage += argv[0];
35
usage +=
" [in.fst [out.fst]]\n"
;
36
37
SET_FLAGS
(usage.c_str(), &argc, &argv,
true
);
38
if
(argc > 3) {
39
ShowUsage
();
40
return
1;
41
}
42
43
const
std::string in_name =
44
argc > 1 && strcmp(argv[1],
"-"
) != 0 ? argv[1] :
""
;
45
const
std::string out_name =
46
argc > 2 && strcmp(argv[2],
"-"
) != 0 ? argv[2] :
""
;
47
48
std::unique_ptr<MutableFstClass>
fst
(MutableFstClass::Read(in_name,
true
));
49
if
(!fst)
return
1;
50
51
bool
acyclic =
s::TopSort
(fst.get());
52
53
if
(!acyclic)
LOG
(WARNING) << argv[0] <<
": Input FST is cyclic"
;
54
55
return
!fst->Write(out_name);
56
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
fst-class.h
fst
Definition:
compact16_acceptor-fst.cc:24
LOG
#define LOG(type)
Definition:
log.h:53
fst::script::TopSort
void TopSort(FstTopSortArgs *args)
Definition:
topsort.h:31
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
fst::script
Definition:
compressscript.cc:26
fsttopsort_main
int fsttopsort_main(int argc, char **argv)
Definition:
fsttopsort-main.cc:29
fst::script::MutableFstClass
Definition:
fst-class.h:460
flags.h
topsort.h
log.h
Generated by
1.8.11