FST
openfst-1.8.4
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.4
src
extensions
compress
fstcompress-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
// Compresses/decompresses 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/extensions/compress/compressscript.h
>
27
#include <
fst/util.h
>
28
#include <
fst/script/fst-class.h
>
29
30
DECLARE_string
(arc_type);
31
DECLARE_bool
(decode);
32
33
int
fstcompress_main
(
int
argc,
char
**argv) {
34
namespace
s =
fst::script
;
35
using
fst::script::FstClass
;
36
using
fst::script::VectorFstClass
;
37
38
std::string usage =
"Compresses/decompresses an FST.\n\n Usage: "
;
39
usage += argv[0];
40
usage +=
" [in.fst [out.fstz]]\n"
;
41
usage +=
" --decode [in.fstz [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
if
(FST_FLAGS_decode) {
55
VectorFstClass
fst
(FST_FLAGS_arc_type);
56
if
(!
s::Decompress
(in_name, &fst)) {
57
FSTERROR
() <<
"Decompression failed"
;
58
return
1;
59
}
60
return
!fst.Write(out_name);
61
}
else
{
62
std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
63
if
(!ifst)
return
1;
64
if
(!
s::Compress
(*ifst, out_name)) {
65
FSTERROR
() <<
"Compression failed"
;
66
return
1;
67
}
68
return
0;
69
}
70
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
fst-class.h
fst
Definition:
compact16_acceptor-fst.cc:24
DECLARE_string
DECLARE_string(arc_type)
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
FSTERROR
#define FSTERROR()
Definition:
util.h:57
fst::script
Definition:
compressscript.cc:26
util.h
fst::script::Compress
bool Compress(const FstClass &fst, const std::string &source)
Definition:
compressscript.cc:28
compressscript.h
DECLARE_bool
DECLARE_bool(decode)
flags.h
fst::script::VectorFstClass
Definition:
fst-class.h:562
fst::script::FstClass
Definition:
fst-class.h:313
fst::script::Decompress
bool Decompress(const std::string &source, MutableFstClass *fst)
Definition:
compressscript.cc:37
log.h
fstcompress_main
int fstcompress_main(int argc, char **argv)
Definition:
fstcompress-main.cc:33
Generated by
1.8.11