Comments (3)
@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 context
rules are compiled/stored and how they are matched with input. When a particular input segment, say "OUND", is processed:
- the first two letters "OU" are downcased
- then, based on these two letters", the
noback context _$l["ound"] @46-145a
rule is selected as a candidate matching rule - then the
_$l["ound"]
test is actually performed on "OUND", returning in no match found
from liblouis.
My suggestion is to fix the second step:
- then, based on these two letters", the
noback context _$l["ound"] @46-145a
rule is selected as a candidate matching rule
Both context _$l["ound"] @46-145a
and context _$l["OUND"] @46-145a
should be found as candidates. Moreover, they should be in the same ordered list together with other candidates. First looking for a match based on the letters "ou", and then looking for a match based on "OU" would complicate things, as you would have to compare the two to determine which rule should win, which is currently the job of the table compiler.
Making _$l["ound"]
match "OUND", in other words making context rules case insensitive, would be another solution, but would be too drastic. It's not unlikely that some authors rely on the fact that context rules are case sensitive.
from liblouis.
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.
from liblouis.
Related Issues (20)
- Issues with Kannada table kannada.cti HOT 1
- Split tables/ja-kantenji.utb into one for UCS2 and one for UCS4 HOT 4
- Issues when backtranslating Serbian braille HOT 6
- Allow noback as a keyword before include HOT 1
- [SEGV](lou_checkyaml): access `NULL` pointer `table` in `getCharForDots`
- [SEGV](lou_checkyaml): access `NULL` pointer `emph_classes` in `read_typeforms`
- [SEGV; heap-buffer-overflow](lou_checkyaml): index `pos` out of range (`input->chars[pos]`)
- [SEGV](lou_checkyaml): negative index for `passPosMapping[realInlen]` in `_lou_backTranslate` HOT 3
- [stack-buffer-overflow](lou_checkyaml): dangerous `widechar` string copy in `compileString`
- [heap-buffer-overflow](lou_checkyaml): 0-byte malloc results in out-of-bound read in `_lou_extParseChars`
- [heap-buffer-overflow](lou_checkyaml): wild pointer is used in `getCharForDots`
- [heap-buffer-overflow](lou_checkyaml): Out of bounds when accessing array `expected_inputPos`
- [heap-buffer-overflow](lou_checkyaml): Invalid out-of-bound index to access array `outbuf` in `check_base`
- [heap-buffer-overflow](lou_checkyaml): Index `kk` out of bounds when accessing array `input->chars` in `doPassSearch` HOT 4
- [heap-buffer-overflow](lou_translate): Negligence in parameter handling HOT 1
- 'utf-32-le' codec can't decode bytes in position 0-3 running on s390x arch
- Make match fully case insensitive HOT 1
- Prefix opcode for rule case sensitivity
- Document the pre- and post- conditions for all opcodes
- Documentation Enhancements HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liblouis.