Skip to content

Commit

Permalink
Handle empty Apertium cohort (fixes #149, fixes #151)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinoDidriksen committed Sep 19, 2024
1 parent 0777679 commit 131d4c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
16 changes: 11 additions & 5 deletions src/ApertiumApplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,15 @@ void ApertiumApplicator::runGrammarOnText(std::istream& input, std::ostream& out

blank.append(u"\"<");
UChar* p = &token[1];
for (; *p && *p != '/' && *p != '<'; ++p) {
for (; *p && *p != '/' && *p != '<' && *p != '$'; ++p) {
if (*p == '\\') {
++p;
}
blank += *p;
}
blank.append(u">\"");
cCohort->wordform = addTag(blank);
blank.clear();

// Handle the static reading of ^estació<n><f><sg>/season<n><sg>/station<n><sg>$
// Gobble up all <tags> until the first / or $ and stuff them in the static reading
Expand Down Expand Up @@ -807,10 +808,6 @@ void ApertiumApplicator::printReading(Reading* reading, std::ostream& output, Ap
}

void ApertiumApplicator::printReading(Reading* reading, std::ostream& output) {
if (reading->noprint) {
return;
}

size_t firstlower = 0;
ApertiumCasing casing = ApertiumCasing::Lower;

Expand Down Expand Up @@ -925,6 +922,9 @@ void ApertiumApplicator::printCohort(Cohort* cohort, std::ostream& output, bool
//Tag::printTagRaw(output, grammar->single_tags[cohort->wordform]);
std::sort(cohort->readings.begin(), cohort->readings.end(), Reading::cmp_number);
for (auto reading : cohort->readings) {
if (reading->noprint) {
continue;
}
if (need_slash) {
u_fprintf(output, "/");
}
Expand All @@ -941,6 +941,9 @@ void ApertiumApplicator::printCohort(Cohort* cohort, std::ostream& output, bool
if (trace) {
std::sort(cohort->delayed.begin(), cohort->delayed.end(), Reading::cmp_number);
for (auto reading : cohort->delayed) {
if (reading->noprint) {
continue;
}
if (need_slash) {
u_fprintf(output, "/%C", not_sign);
}
Expand All @@ -952,6 +955,9 @@ void ApertiumApplicator::printCohort(Cohort* cohort, std::ostream& output, bool
}
std::sort(cohort->deleted.begin(), cohort->deleted.end(), Reading::cmp_number);
for (auto reading : cohort->deleted) {
if (reading->noprint) {
continue;
}
if (need_slash) {
u_fprintf(output, "/%C", not_sign);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GrammarApplicator_reflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Tag* GrammarApplicator::makeBaseFromWord(uint32_t tag) {

Tag* GrammarApplicator::makeBaseFromWord(Tag* tag) {
const size_t len = tag->tag.size();
if (len < 5) {
if (len < 4) {
return tag;
}
static thread_local UString n;
Expand Down
2 changes: 1 addition & 1 deletion src/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ constexpr auto CG3_COPYRIGHT_STRING = "Copyright (C) 2007-2024 GrammarSoft ApS.

constexpr uint32_t CG3_VERSION_MAJOR = 1;
constexpr uint32_t CG3_VERSION_MINOR = 4;
constexpr uint32_t CG3_VERSION_PATCH = 17;
constexpr uint32_t CG3_VERSION_PATCH = 18;
constexpr uint32_t CG3_REVISION = 13898;
constexpr uint32_t CG3_FEATURE_REV = 13898;
constexpr uint32_t CG3_TOO_OLD = 10373;
Expand Down
18 changes: 10 additions & 8 deletions test/Apertium/runall.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@

# Search paths for the binary
my @binlist = (
"../../build/VS16/src/Debug/vislcg3",
"../../build/VS16/src/Release/vislcg3",
"../build/src/vislcg3",
"../../build/VS17/src/Debug/vislcg3",
"../../build/VS17/src/Release/vislcg3",
"../src/Debug/vislcg3",
"../src/Release/vislcg3",
"../Debug/vislcg3",
"../Common/vislcg3",
"../Release/vislcg3",
"../src/vislcg3",
"../vislcg3",
);
);
my $binary = "vislcg3";

foreach (@binlist) {
if (-x $_) {
if (-x $_ && int(`$_ --min-binary-revision 2>/dev/null`) >= 10373) {
$binary = $_;
last;
}
elsif (-x $_.".exe") {
elsif (-x $_.".exe" && int(`$_.exe --min-binary-revision 2>/dev/null`) >= 10373) {
$binary = $_.".exe";
last;
}
elsif (-x "../".$_) {
elsif (-x "../".$_ && int(`../$_ --min-binary-revision 2>/dev/null`) >= 10373) {
$binary = "../".$_;
last;
}
elsif (-x "../".$_.".exe") {
elsif (-x "../".$_.".exe" && int(`../$_.exe --min-binary-revision 2>/dev/null`) >= 10373) {
$binary = "../".$_.".exe";
last;
}
Expand Down

0 comments on commit 131d4c0

Please sign in to comment.