FST
openfst-1.8.4
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.4
src
extensions
pdt
pdtinfo-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
// Prints out various information about a PDT such as number of states, arcs,
19
// and parentheses.
20
21
#include <cstdint>
22
#include <cstring>
23
#include <memory>
24
#include <string>
25
#include <utility>
26
#include <vector>
27
28
#include <
fst/flags.h
>
29
#include <
fst/log.h
>
30
#include <
fst/extensions/pdt/pdtscript.h
>
31
#include <
fst/util.h
>
32
#include <
fst/script/fst-class.h
>
33
34
DECLARE_string
(pdt_parentheses);
35
36
int
pdtinfo_main
(
int
argc,
char
**argv) {
37
namespace
s =
fst::script
;
38
using
fst::ReadLabelPairs
;
39
using
fst::script::FstClass
;
40
41
std::string usage =
"Prints out information about a PDT.\n\n Usage: "
;
42
usage += argv[0];
43
usage +=
" in.pdt\n"
;
44
45
SET_FLAGS
(usage.c_str(), &argc, &argv,
true
);
46
if
(argc > 2) {
47
ShowUsage
();
48
return
1;
49
}
50
51
const
std::string in_name =
52
(argc > 1 && (strcmp(argv[1],
"-"
) != 0)) ? argv[1] :
""
;
53
54
std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
55
if
(!ifst)
return
1;
56
57
if
(FST_FLAGS_pdt_parentheses.empty()) {
58
LOG
(ERROR) << argv[0] <<
": No PDT parenthesis label pairs provided"
;
59
return
1;
60
}
61
62
std::vector<std::pair<int64_t, int64_t>> parens;
63
if
(!
ReadLabelPairs
(FST_FLAGS_pdt_parentheses, &parens))
return
1;
64
65
s::Info
(*ifst, parens);
66
67
return
0;
68
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
fst-class.h
DECLARE_string
DECLARE_string(pdt_parentheses)
LOG
#define LOG(type)
Definition:
log.h:53
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
fst::script::Info
void Info(const std::vector< std::string > &sources, const std::string &arc_type, const std::string &begin_key, const std::string &end_key, bool list_fsts)
Definition:
farscript.cc:145
fst::script
Definition:
compressscript.cc:26
util.h
flags.h
fst::ReadLabelPairs
bool ReadLabelPairs(std::string_view source, std::vector< std::pair< Label, Label >> *pairs)
Definition:
util.h:423
pdtinfo_main
int pdtinfo_main(int argc, char **argv)
Definition:
pdtinfo-main.cc:36
pdtscript.h
fst::script::FstClass
Definition:
fst-class.h:313
log.h
Generated by
1.8.11