Skip to content

Commit 57efb6b

Browse files
committed
add support for later openfst versions
1 parent 9a213be commit 57efb6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+246
-112
lines changed

src/base/kaldi-error-test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main() {
7676
kaldi::UnitTestError();
7777
KALDI_ASSERT(0); // should not happen.
7878
exit(1);
79-
} catch (kaldi::KaldiFatalError &e) {
79+
} catch (const kaldi::KaldiFatalError &e) {
8080
std::cout << "The error we generated was: '" << e.KaldiMessage() << "'\n";
8181
}
8282
}

src/base/kaldi-types.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef float BaseFloat;
3939
// we find in the future lacks stdint.h
4040
#include <stdint.h>
4141

42+
#if OPENFST_VER >= 10800
4243
typedef int8_t int8;
4344
typedef int16_t int16;
4445
typedef int32_t int32;
@@ -50,5 +51,18 @@ typedef uint32_t uint32;
5051
typedef uint64_t uint64;
5152
typedef float float32;
5253
typedef double double64;
54+
#else
55+
#include <fst/types.h>
56+
#endif
5357

58+
namespace kaldi {
59+
using ::int16;
60+
using ::int32;
61+
using ::int64;
62+
using ::uint16;
63+
using ::uint32;
64+
using ::uint64;
65+
typedef float float32;
66+
typedef double double64;
67+
} // end namespace kaldi
5468
#endif // KALDI_BASE_KALDI_TYPES_H_

src/bin/phones-to-prons.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ int main(int argc, char *argv[]) {
172172
if (g_kaldi_verbose_level >= 2) {
173173
KALDI_LOG << "phn2word FST is below:";
174174
fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, false, true, "\t");
175-
fstprinter.Print(&std::cerr, "standard error");
175+
printer_print(std::cerr, fstprinter, "standard error");
176+
//fstprinter.Print(&std::cerr, "standard error");
176177
KALDI_LOG << "phone sequence is: ";
177178
for (size_t i = 0; i < phones.size(); i++)
178179
std::cerr << phones[i] << ' ';

src/configure

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# This should be incremented after any significant change to the configure
4141
# script, i.e. any change affecting kaldi.mk or the build system as a whole.
42-
CONFIGURE_VERSION=14
42+
CONFIGURE_VERSION=15
4343

4444
# We support bash version 3.2 (Macs still ship with this version as of 2019)
4545
# and above.
@@ -1024,6 +1024,14 @@ OPENFST_VER_NUM=$(echo $OPENFST_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d"
10241024
if [ $OPENFST_VER_NUM -lt 10600 ]; then
10251025
failure "OpenFst-$OPENFST_VER is not supported. You need OpenFst >= 1.6.0.)"
10261026
fi
1027+
1028+
if [ $OPENFST_VER_NUM -lt 10800 ]; then
1029+
echo "CXXLANGVERSION = c++14"
1030+
else
1031+
echo "CXXLANGVERSION = c++17"
1032+
fi >> kaldi.mk
1033+
1034+
echo "OPENFSTVER = $OPENFST_VER_NUM" >> kaldi.mk
10271035
echo "OPENFSTINC = $FSTROOT/include" >> kaldi.mk
10281036
if $static_fst ; then
10291037
OPENFSTLIBS="$FSTROOT/lib/libfst.a"

src/fstext/context-fst-test.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "util/kaldi-io.h"
2424
#include "base/kaldi-math.h"
2525

26+
#include "fstext/openfst_compat.h"
27+
2628
namespace fst
2729
{
2830
using std::vector;
@@ -196,7 +198,7 @@ static void TestContextFst(bool verbose, bool use_matcher) {
196198
std::cout << "Sequence FST is:\n";
197199
{ // Try to print the fst.
198200
FstPrinter<Arc> fstprinter(*f, NULL, NULL, NULL, false, true, "\t");
199-
fstprinter.Print(&std::cout, "standard output");
201+
printer_print(std::cout, fstprinter, "standard output");
200202
}
201203
}
202204

@@ -224,7 +226,7 @@ static void TestContextFst(bool verbose, bool use_matcher) {
224226
std::cout << "Composed FST is:\n";
225227
{ // Try to print the fst.
226228
FstPrinter<Arc> fstprinter(fst_composed, NULL, NULL, NULL, false, true, "\t");
227-
fstprinter.Print(&std::cout, "standard output");
229+
printer_print(std::cout, fstprinter, "standard output");
228230
}
229231
}
230232

src/fstext/determinize-lattice-test.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "fstext/fst-test-utils.h"
2323
#include "base/kaldi-math.h"
2424

25+
#include "fstext/openfst_compat.h"
26+
2527
namespace fst {
2628
using std::vector;
2729
using std::cout;
@@ -94,7 +96,7 @@ template<class Arc> void TestDeterminizeLattice() {
9496
std::cout << "FST before lattice-determinizing is:\n";
9597
{
9698
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
97-
fstprinter.Print(&std::cout, "standard output");
99+
printer_print(std::cout, fstprinter, "standard output");
98100
}
99101
VectorFst<Arc> det_fst;
100102
try {
@@ -106,7 +108,7 @@ template<class Arc> void TestDeterminizeLattice() {
106108
std::cout << "FST after lattice-determinizing is:\n";
107109
{
108110
FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true, "\t");
109-
fstprinter.Print(&std::cout, "standard output");
111+
printer_print(std::cout, fstprinter, "standard output");
110112
}
111113
assert(det_fst.Properties(kIDeterministic, true) & kIDeterministic);
112114
// OK, now determinize it a different way and check equivalence.
@@ -117,7 +119,7 @@ template<class Arc> void TestDeterminizeLattice() {
117119
std::cout << "Compact FST is:\n";
118120
{
119121
FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL, false, true, "\t");
120-
fstprinter.Print(&std::cout, "standard output");
122+
printer_print(std::cout, fstprinter, "standard output");
121123
}
122124
if (kaldi::Rand() % 2 == 1)
123125
ConvertLattice<Weight, Int>(det_fst, &compact_det_fst, false);
@@ -128,7 +130,7 @@ template<class Arc> void TestDeterminizeLattice() {
128130
std::cout << "Compact version of determinized FST is:\n";
129131
{
130132
FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL, false, true, "\t");
131-
fstprinter.Print(&std::cout, "standard output");
133+
printer_print(std::cout, fstprinter, "standard output");
132134
}
133135

134136
assert(RandEquivalent(compact_det_fst, compact_fst, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length, max*/));
@@ -149,14 +151,14 @@ template<class Arc> void TestDeterminizeLattice2() {
149151
std::cout << "FST before lattice-determinizing is:\n";
150152
{
151153
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
152-
fstprinter.Print(&std::cout, "standard output");
154+
printer_print(std::cout, fstprinter, "standard output");
153155
}
154156
VectorFst<Arc> ofst;
155157
DeterminizeLattice<TropicalWeight, int32>(*fst, &ofst);
156158
std::cout << "FST after lattice-determinizing is:\n";
157159
{
158160
FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
159-
fstprinter.Print(&std::cout, "standard output");
161+
printer_print(std::cout, fstprinter, "standard output");
160162
}
161163
delete fst;
162164
}

src/fstext/determinize-star-test.cc

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "fstext/trivial-factor-weight.h"
2525
#include "fstext/fst-test-utils.h"
2626

27+
#include "fstext/openfst_compat.h"
2728

2829
namespace fst
2930
{
@@ -38,15 +39,15 @@ template<class Arc> void TestDeterminizeGeneral() {
3839
std::cout << "FST before determinizing is:\n";
3940
{
4041
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
41-
fstprinter.Print(&std::cout, "standard output");
42+
printer_print(std::cout, fstprinter, "standard output");
4243
}
4344
VectorFst<Arc> ofst;
4445
try {
4546
DeterminizeStar<Fst<Arc> >(*fst, &ofst, kDelta, NULL, max_states);
4647
std::cout << "FST after determinizing is:\n";
4748
{
4849
FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
49-
fstprinter.Print(&std::cout, "standard output");
50+
printer_print(std::cout, fstprinter, "standard output");
5051
}
5152
assert(RandEquivalent(*fst, ofst, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length, max*/));
5253
} catch (...) {
@@ -101,15 +102,15 @@ template<class Arc> void TestDeterminize() {
101102
std::cout <<" printing before trimming\n";
102103
{
103104
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
104-
fstprinter.Print(&std::cout, "standard output");
105+
printer_print(std::cout, fstprinter, "standard output");
105106
}
106107
// Trim resulting FST.
107108
Connect(fst);
108109

109110
std::cout <<" printing after trimming\n";
110111
{
111112
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
112-
fstprinter.Print(&std::cout, "standard output");
113+
printer_print(std::cout, fstprinter, "standard output");
113114
}
114115

115116
VectorFst<Arc> *fst_copy_orig = new VectorFst<Arc>(*fst);
@@ -122,7 +123,7 @@ template<class Arc> void TestDeterminize() {
122123
std::cout <<" printing after predeterminization\n";
123124
{
124125
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
125-
fstprinter.Print(&std::cout, "standard output");
126+
printer_print(std::cout, fstprinter, "standard output");
126127
}
127128

128129

@@ -138,7 +139,7 @@ template<class Arc> void TestDeterminize() {
138139
std::cout <<" printing after epsilon removal\n";
139140
{
140141
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
141-
fstprinter.Print(&std::cout, "standard output");
142+
printer_print(std::cout, fstprinter, "standard output");
142143
}
143144
VectorFst<Arc> ofst_orig;
144145
VectorFst<Arc> ofst_star;
@@ -157,14 +158,14 @@ template<class Arc> void TestDeterminize() {
157158
{
158159
std::cout <<" printing after determinization [baseline]\n";
159160
FstPrinter<Arc> fstprinter(ofst_orig, sptr, sptr, NULL, false, true, "\t");
160-
fstprinter.Print(&std::cout, "standard output");
161+
printer_print(std::cout, fstprinter, "standard output");
161162
assert(ofst_orig.Properties(kIDeterministic, true) == kIDeterministic);
162163
}
163164

164165
{
165166
std::cout <<" printing after determinization [star]\n";
166167
FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
167-
fstprinter.Print(&std::cout, "standard output");
168+
printer_print(std::cout, fstprinter, "standard output");
168169
assert(ofst_star.Properties(kIDeterministic, true) == kIDeterministic);
169170
}
170171

@@ -174,7 +175,7 @@ template<class Arc> void TestDeterminize() {
174175
std::cout <<" printing after removing "<<num_removed<<" instances of extra symbols\n";
175176
{
176177
FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
177-
fstprinter.Print(&std::cout, "standard output");
178+
printer_print(std::cout, fstprinter, "standard output");
178179
}
179180

180181
std::cout <<" Checking equivalent to original FST.\n";
@@ -242,15 +243,15 @@ template<class Arc> void TestPush() {
242243
std::cout <<" printing before trimming\n";
243244
{
244245
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
245-
fstprinter.Print(&std::cout, "standard output");
246+
printer_print(std::cout, fstprinter, "standard output");
246247
}
247248
// Trim resulting FST.
248249
Connect(fst);
249250

250251
std::cout <<" printing after trimming\n";
251252
{
252253
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
253-
fstprinter.Print(&std::cout, "standard output");
254+
printer_print(std::cout, fstprinter, "standard output");
254255
}
255256

256257
VectorFst<Arc> *fst_copy_orig = new VectorFst<Arc>(*fst);
@@ -267,7 +268,7 @@ template<class Arc> void TestPush() {
267268
std::cout <<" printing after pushing\n";
268269
{
269270
FstPrinter<Arc> fstprinter(fst_pushed, sptr, sptr, NULL, false, true, "\t");
270-
fstprinter.Print(&std::cout, "standard output");
271+
printer_print(std::cout, fstprinter, "standard output");
271272
}
272273

273274
assert(RandEquivalent(*fst, fst_pushed, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));
@@ -320,15 +321,15 @@ template<class Arc> void TestMinimize() {
320321
std::cout <<" printing before trimming\n";
321322
{
322323
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
323-
fstprinter.Print(&std::cout, "standard output");
324+
printer_print(std::cout, fstprinter, "standard output");
324325
}
325326
// Trim resulting FST.
326327
Connect(fst);
327328

328329
std::cout <<" printing after trimming\n";
329330
{
330331
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
331-
fstprinter.Print(&std::cout, "standard output");
332+
printer_print(std::cout, fstprinter, "standard output");
332333
}
333334

334335
VectorFst<Arc> *fst_copy_orig = new VectorFst<Arc>(*fst);
@@ -341,7 +342,7 @@ template<class Arc> void TestMinimize() {
341342
std::cout <<" printing after predeterminization\n";
342343
{
343344
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
344-
fstprinter.Print(&std::cout, "standard output");
345+
printer_print(std::cout, fstprinter, "standard output");
345346
}
346347

347348

@@ -357,7 +358,7 @@ template<class Arc> void TestMinimize() {
357358
std::cout <<" printing after epsilon removal\n";
358359
{
359360
FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
360-
fstprinter.Print(&std::cout, "standard output");
361+
printer_print(std::cout, fstprinter, "standard output");
361362
}
362363
VectorFst<Arc> ofst_orig;
363364
VectorFst<Arc> ofst_star;
@@ -370,7 +371,7 @@ template<class Arc> void TestMinimize() {
370371
{
371372
std::cout <<" printing after determinization [baseline]\n";
372373
FstPrinter<Arc> fstprinter(ofst_orig, sptr, sptr, NULL, false, true, "\t");
373-
fstprinter.Print(&std::cout, "standard output");
374+
printer_print(std::cout, fstprinter, "standard output");
374375
}
375376

376377

@@ -382,7 +383,7 @@ template<class Arc> void TestMinimize() {
382383
{
383384
std::cout <<" printing after determinization by DeterminizeStar [in gallic]\n";
384385
FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
385-
fstprinter.Print(&std::cout, "standard output");
386+
printer_print(std::cout, fstprinter, "standard output");
386387
}
387388

388389

@@ -392,7 +393,7 @@ template<class Arc> void TestMinimize() {
392393
{
393394
std::cout <<" printing after pushing weights [in gallic]\n";
394395
FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
395-
fstprinter.Print(&std::cout, "standard output");
396+
printer_print(std::cout, fstprinter, "standard output");
396397
}
397398

398399

@@ -401,7 +402,7 @@ template<class Arc> void TestMinimize() {
401402
{
402403
std::cout <<" printing after minimization [in gallic]\n";
403404
FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
404-
fstprinter.Print(&std::cout, "standard output");
405+
printer_print(std::cout, fstprinter, "standard output");
405406
}
406407

407408
printf("Converting gallic back to regular [my approach]\n");
@@ -410,15 +411,15 @@ template<class Arc> void TestMinimize() {
410411
{
411412
std::cout <<" printing factor-weight FST\n";
412413
FstPrinter<GallicArc< Arc> > fstprinter(fwfst, sptr, sptr, NULL, false, true, "\t");
413-
fstprinter.Print(&std::cout, "standard output");
414+
printer_print(std::cout, fstprinter, "standard output");
414415
}
415416

416417
Map(fwfst, &ofst_star, FromGallicMapper<Arc, GALLIC_LEFT>());
417418

418419
{
419420
std::cout <<" printing after converting back to regular FST\n";
420421
FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
421-
fstprinter.Print(&std::cout, "standard output");
422+
printer_print(std::cout, fstprinter, "standard output");
422423
}
423424

424425
}
@@ -431,7 +432,7 @@ template<class Arc> void TestMinimize() {
431432
std::cout <<" printing after removing "<<num_removed<<" instances of extra symbols\n";
432433
{
433434
FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
434-
fstprinter.Print(&std::cout, "standard output");
435+
printer_print(std::cout, fstprinter, "standard output");
435436
}
436437

437438
std::cout <<" Checking equivalent to original FST.\n";

src/fstext/factor-test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "fstext/fst-test-utils.h"
2424
#include "base/kaldi-math.h"
2525

26+
#include "fstext/openfst_compat.h"
2627

2728
namespace fst
2829
{
@@ -79,15 +80,15 @@ template<class Arc> static void TestFactor() {
7980
std::cout <<" printing before trimming\n";
8081
{
8182
FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true, "\t");
82-
fstprinter.Print(&std::cout, "standard output");
83+
printer_print(std::cout, fstprinter, "standard output");
8384
}
8485
// Trim resulting FST.
8586
Connect(&fst);
8687

8788
std::cout <<" printing after trimming\n";
8889
{
8990
FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true, "\t");
90-
fstprinter.Print(&std::cout, "standard output");
91+
printer_print(std::cout, fstprinter, "standard output");
9192
}
9293

9394
if (fst.Start() == kNoStateId) return; // "Connect" made it empty.

0 commit comments

Comments
 (0)