Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiled extensionless executable files in /src/*/
# This stanza must precede wildcard patterns below!
/src/*/*
!/src/lm/test_data/
!/src/*/?*.*
!/src/doc/*
!/src/*/Makefile
Expand Down
14 changes: 14 additions & 0 deletions src/lm/arpa-lm-compiler-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ bool ScoringTest(bool seps, const string &infile, const string& sentence,
return ok;
}

bool ThrowsExceptionTest(bool seps, const string &infile) {
try {
// Make memory cleanup easy in both cases of try-catch block.
std::unique_ptr<ArpaLmCompiler> compiler(Compile(seps, infile));
return false;
} catch (const std::runtime_error&) {
// Kaldi throws only std::runtime_error in kaldi-error.cc
return true;
}
}

} // namespace kaldi

bool RunAllTests(bool seps) {
Expand All @@ -214,6 +225,9 @@ bool RunAllTests(bool seps) {

ok &= kaldi::ScoringTest(seps, "test_data/input.arpa", "b b b a", 59.2649);
ok &= kaldi::ScoringTest(seps, "test_data/input.arpa", "a b", 4.36082);

ok &= kaldi::ThrowsExceptionTest(seps, "test_data/missing_bos.arpa");

if (!ok) {
KALDI_WARN << "Tests " << (seps ? "with" : "without")
<< " epsilon substitution FAILED";
Expand Down
8 changes: 8 additions & 0 deletions src/lm/arpa-lm-compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,18 @@ void ArpaLmCompiler::RemoveRedundantStates() {
<< fst_.NumStates();
}

void ArpaLmCompiler::Check() const {
if (fst_.Start() == fst::kNoStateId) {
KALDI_ERR << "Arpa file did not contain the beginning-of-sentence symbol "
<< Symbols()->Find(Options().bos_symbol) << ".";
}
}

void ArpaLmCompiler::ReadComplete() {
fst_.SetInputSymbols(Symbols());
fst_.SetOutputSymbols(Symbols());
RemoveRedundantStates();
Check();
}

} // namespace kaldi
1 change: 1 addition & 0 deletions src/lm/arpa-lm-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ArpaLmCompiler : public ArpaFileParser {
// this function removes states that only have a backoff arc coming
// out of them.
void RemoveRedundantStates();
void Check() const;

int sub_eps_;
ArpaLmCompilerImplInterface* impl_; // Owned.
Expand Down
18 changes: 18 additions & 0 deletions src/lm/test_data/missing_bos.arpa
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

\data\
ngram 1=3
ngram 2=1
ngram 3=1

\1-grams:
-5.234679 a -3.3
-3.456783 b -3.0
-4.333333 </s>

\2-grams:
-1.45678 a b -3.23

\3-grams:
-0.23940 a b </s>

\end\