Constraint-based lexical selection module
Lexical transfer
This is the output of lt-proc -b
on an ambiguous bilingual dictionary.
[74306] ^El<det><def><f><sg>/The<det><def><f><sg>$ ^estació<n><f><sg>/season<n><sg>/station<n><sg>$ ^més<preadv>/more<preadv>$ ^plujós<adj><f><sg>/rainy<adj><sint><f><sg>$ ^ser<vbser><pri><p3><sg>/be<vbser><pri><p3><sg>$ ^el<det><def><f><sg>/the<det><def><f><sg>$ ^tardor<n><f><sg>/autumn<n><sg>/fall<n><sg>$^,<cm>/,<cm>$ ^i<cnjcoo>/and<cnjcoo>$ ^el<det><def><f><sg>/the<det><def><f><sg>$ ^més<preadv>/more<preadv>$ ^sec<adj><f><sg>/dry<adj><sint><f><sg>$ ^el<det><def><m><sg>/the<det><def><m><sg>$ ^estiu<n><m><sg>/summer<n><sg>$^.<sent>/.<sent>$
I.e.
L'estació més plujós és el tardor, i la més sec el estiu
Goes to:
The season/station more rainy is the autumn/fall, and the more dry the summer.
The module requires VM for transfer, or another apertium transfer implementation without lexical transfer in order to work.
Compilation
Check out the code from
$ svn co https://apertium.svn.sourceforge.net/svnroot/apertium/branches/apertium-lex-tools
you can make it using:
$ make PREFIX=/path/to/where/you/installed/apertium
Make a simple rule file,
<rules> <rule> <match lemma="criminal" tags="adj"/> <match lemma="court" tags="n.*"><select lemma="juzgado" tags="n.*"/></match> </rule> </rules>
Then compile it:
$ ./apertium-lrx-comp rules.xml rules.fst Rule 1 (line 7): Match[1]: <criminal<adj> Match[2]: <court<n>[0-9A-Za-z <>]*> Select[1]: <select(juzgado<n>[0-9A-Za-z <>]*)> Len: 2 rule 1 (line 7) (len 2) (ops 1): 0 1 [1] sl: <criminal<adj>, tl: skip(*) [2] sl: <court<n>[0-9A-Za-z <>]*>, tl: <select(juzgado<n>[0-9A-Za-z <>]*)> Written 1 rules, 3 patterns.
$ echo "^There<adv>/Allí<adv>$ ^be<vbser><pri><p3><sg>/ser<vbser><pri><p3><sg>$ ^a<det><ind><sg>/uno<det><ind><GD><sg>$ ^criminal<adj>/criminal<adj><mf>/delictivo<adj>$ ^court<n><sg>/corte<n><f><sg>/cancha<n><f><sg>/juzgado<n><m><sg>/tribunal<n><m><sg>$^.<sent>/.<sent>$" | ./apertium-lrx-proc -t rules2.fst ^There<adv>/Allí<adv>$ ^be<vbser><pri><p3><sg>/ser<vbser><pri><p3><sg>$ ^a<det><ind><sg>/uno<det><ind><GD><sg>$ ^criminal<adj>/criminal<adj><mf>/delictivo<adj>$ ^court<n><sg>/juzgado<n><m><sg>$^.<sent>/.<sent>$^.<sent>/.<sent>$
Rule format
A rule is made up of an ordered list of:
- Matches
- Operations (select, remove)
<rule> <match lemma="el"/> <match lemma="dona" tags="n.*"> <select lemma="wife"/> </match> <match lemma="de"/> </rule> <pre> <rule> <match lemma="estació" tags="n.*"> <select lemma="season"/> </match> <match lemma="més"/> <match lemma="plujós"/> </rule> <rule> <match lemma="guanyador"/> <match lemma="de"/> <match/> <match lemma="prova" tags="n.*"> <select lemma="event"/> </match> </rule>
Rule application process
- Optimal application
We're interested in the longest match, but not left to right, so what we do is make an automata of the rule contexts (one rule is one transducer, then we compose them), and we read through them, each state is an LU, It needs to be non-deterministic, and you keep a log of alive paths/states, but also their "weight" (how many transitions have been made) -- the longest for each of the ambiguous words is the winner when we get to the end of the sentence.
Writing and generating rules
Writing
A good way to start writing lexical selection rules is to take a corpus, and search for the problem word, you can then look at how the word should be translated, and the contexts it appears in.
Generating
Compiled
The general structure is as follows:
LSSRECORD = id, len, weight; <ALPHABET> <NUM_TRANSDUCERS> <TRANSDUCER> <TRANSDUCER> <TRANSDUCER> ... "main" <TRANSDUCER> <LSRRECORD> <LSRRECORD> <LSRRECORD>
Todo
xml compilercompile rule operation patterns, as well as matching patternsmake rules with gaps workoptimal coveragefix bug with processing multiple sentencesinstead of having regex OR, insert separate paths/states.- testing
- optimise the bestPath function (don't use strings to store the paths)
- edit
transfer.cc
to allow input fromlt-proc -b
- null flush
- default to case insensitive ? (perhaps case insensitive for lower case, case sensitive for uppercase)
- add option to compiler and processor to spit out ATT transducers
- Rendimiento
- 2011-12-12: 10,000 words / 97 seconds = 103 words/sec