New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context opcode does not match when in a capitalized word/passage #1461
Comments
@tibbsa Thanks for the investigation and the test file, and sorry that you got no response to your message to the mailing list. I think this might be related to #818, and the associated test file. Both issues are caused by an inconsistency between how
|
My suggestion is to fix the second step:
Both Making |
I propose the following change: diff --git a/liblouis/compileTranslationTable.c b/liblouis/compileTranslationTable.c
index 0338b3d3..8c98b49d 100644
--- a/liblouis/compileTranslationTable.c
+++ b/liblouis/compileTranslationTable.c
@@ -4461,6 +4461,43 @@ finalizeTable(TranslationTableHeader *table) {
characterOffset = character->next;
}
}
+ // Rearrange rules in `forRules' so that when iterating over candidate rules in
+ // for_selectRule(), both case-sensitive and case-insensitive rules are contained
+ // within the same ordered list
+ for (unsigned long int i = 0; i < HASHNUM; i++) {
+ TranslationTableOffset *rp = &table->forRules[i];
+ while (*rp) {
+ TranslationTableRule *r = (TranslationTableRule *)&table->ruleArea[*rp];
+ // For now only move the rules that we know are case-sensitive, namely
+ // `context' rules. (Note that there may be other case-sensitive rules that
+ // we're currently not aware of.) We don't move case insensitive rules because
+ // the user can/should define them using all lowercases.
+ if (r->opcode == CTO_Context) {
+ unsigned long int hash = _lou_stringHash(&r->charsdots[0], 1, table);
+ if (hash != i) {
+ // compute new position
+ TranslationTableOffset *rrp = &table->forRules[hash];
+ while (*rrp) {
+ TranslationTableRule *rr =
+ (TranslationTableRule *)&table->ruleArea[*rrp];
+ if (r->charslen > rr->charslen)
+ break;
+ else if (r->charslen == rr->charslen && rr->opcode == CTO_Always)
+ break;
+ rrp = &rr->charsnext;
+ }
+ // remove rule from current list and insert it at the correct position
+ // in the new list
+ TranslationTableOffset tmp = r->charsnext;
+ r->charsnext = *rrp;
+ *rrp = *rp;
+ *rp = tmp;
+ continue;
+ }
+ }
+ rp = &r->charsnext;
+ }
+ }
table->finalized = 1;
return 1;
} Note that it can be optimized a bit, but this gives you the idea. |
A multi-pass "context" fails to match if the pattern occurs within a capitalized word (or passage), even though it matches fine in non-capitalized text.
I originally asked about this on the liblouis discussion list, but with no response I'm proceeding on the basis that there is in fact some bug or undocumented behaviour happening here.
Thinking there was perhaps some underlying issue within the UEB tables, I've tried to create a minimally viable example in the YAML file itself. The first 3 tests (around, Around, arOund) work as expected, with the "ound" contraction being applied in the first two cases but not the third. The last 3 examples (where the entire word or passage is capitalized) fail as the "ound" contraction does not get used at all.
See: caps-vs-context.yaml.txt
This is blocking #1451 as I have a mostly working solution for that, but it fails for capitalized words/phrases.
The text was updated successfully, but these errors were encountered: