FST
openfst-1.8.4
OpenFst Library
Main Page
Namespaces
Classes
Files
File List
File Members
src
fst
openfst-1.8.4
src
bin
fstproject-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
// Projects a transduction onto its input or output language.
19
20
#include <cstring>
21
#include <memory>
22
#include <string>
23
24
#include <
fst/flags.h
>
25
#include <
fst/log.h
>
26
#include <
fst/project.h
>
27
#include <
fst/script/fst-class.h
>
28
#include <
fst/script/getters.h
>
29
#include <
fst/script/project.h
>
30
31
DECLARE_string
(project_type);
32
33
int
fstproject_main
(
int
argc,
char
**argv) {
34
namespace
s =
fst::script
;
35
using
fst::ProjectType
;
36
using
fst::script::MutableFstClass
;
37
38
std::string usage =
39
"Projects a transduction onto its input"
40
" or output language.\n\n Usage: "
;
41
usage += argv[0];
42
usage +=
" [in.fst [out.fst]]\n"
;
43
44
SET_FLAGS
(usage.c_str(), &argc, &argv,
true
);
45
if
(argc > 3) {
46
ShowUsage
();
47
return
1;
48
}
49
50
const
std::string in_name =
51
(argc > 1 && strcmp(argv[1],
"-"
) != 0) ? argv[1] :
""
;
52
const
std::string out_name =
53
(argc > 2 && strcmp(argv[2],
"-"
) != 0) ? argv[2] :
""
;
54
55
std::unique_ptr<MutableFstClass>
fst
(MutableFstClass::Read(in_name,
true
));
56
if
(!fst)
return
1;
57
58
ProjectType
project_type;
59
if
(!
s::GetProjectType
(FST_FLAGS_project_type, &project_type)) {
60
LOG
(ERROR) << argv[0] <<
": Unknown or unsupported project type: "
61
<< FST_FLAGS_project_type;
62
return
1;
63
}
64
65
s::Project
(fst.get(), project_type);
66
67
return
!fst->Write(out_name);
68
}
ShowUsage
void ShowUsage(bool long_usage=true)
Definition:
flags.cc:138
project.h
fst-class.h
getters.h
fst
Definition:
compact16_acceptor-fst.cc:24
LOG
#define LOG(type)
Definition:
log.h:53
fst::ProjectType
ProjectType
Definition:
project.h:37
SET_FLAGS
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition:
flags.h:226
fst::script
Definition:
compressscript.cc:26
DECLARE_string
DECLARE_string(project_type)
fst::Project
void Project(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, ProjectType project_type)
Definition:
project.h:89
project.h
fst::script::MutableFstClass
Definition:
fst-class.h:460
flags.h
fstproject_main
int fstproject_main(int argc, char **argv)
Definition:
fstproject-main.cc:33
log.h
fst::script::GetProjectType
bool GetProjectType(std::string_view str, ProjectType *project_type)
Definition:
getters.cc:160
Generated by
1.8.11