| 1 |
[Lttoolbox](https://wiki.apertium.org/wiki/Lttoolbox) provides a module for reordering |
| 2 |
separable/discontiguous multiwords and processing them in the pipeline. |
| 3 |
Multiwords are manually written in an additional xml-format dictionary. |
| 4 |
|
| 5 |
## Installing |
| 6 |
|
| 7 |
The module is part of the [nightly |
| 8 |
repositories](https://wiki.apertium.org/wiki/Nightly_repositories) as `apt-get install |
| 9 |
apertium-separable`. |
| 10 |
|
| 11 |
If you'd like to compile it manually—e.g., for development purposes—you |
| 12 |
can follow these instructions: |
| 13 |
|
| 14 |
Prerequisites and compilation are the same as lttoolbox and apertium. |
| 15 |
See [Installation](https://wiki.apertium.org/wiki/Installation). |
| 16 |
|
| 17 |
The code can be found at |
| 18 |
<https://github.com/apertium/apertium-separable>, and instructions for |
| 19 |
compiling the module are: |
| 20 |
|
| 21 |
./autogen.sh |
| 22 |
./configure |
| 23 |
make |
| 24 |
make install |
| 25 |
|
| 26 |
You'll need `lttoolbox` from git (or, greater than the current release |
| 27 |
3.5.1) and associated libraries. |
| 28 |
|
| 29 |
## Lexical transfer in the pipeline |
| 30 |
|
| 31 |
lsx-proc runs directly AFTER apertium-tagger and apertium-pretransfer: |
| 32 |
(note: previously this page had said that lsx-proc runs between BETWEEN |
| 33 |
apertium-tagger and apertium-pretransfer. it has now been determined |
| 34 |
that it should run AFTER pretransfer.) |
| 35 |
|
| 36 |
… | apertium-tagger -g en-es.prob | apertium-pretransfer | lsx-proc en-es.autoseq.bin | … |
| 37 |
|
| 38 |
## Usage |
| 39 |
|
| 40 |
### Creating the lsx-dictionary |
| 41 |
|
| 42 |
The lsx dictionary format is largely similar to those of the [ |
| 43 |
morphological](https://wiki.apertium.org/wiki/Morphological_dictionary) and [ |
| 44 |
bilingual](https://wiki.apertium.org/wiki/Bilingual_dictionary) dictionaries. (see also: |
| 45 |
[Apertium_New_Language_Pair_HOWTO](https://wiki.apertium.org/wiki/Apertium_New_Language_Pair_HOWTO) |
| 46 |
|
| 47 |
We begin with a declaration of the dictionary. There is currently |
| 48 |
nothing in it, only a declaration that we want to begin a new |
| 49 |
dictionary. |
| 50 |
|
| 51 |
<dictionary type="separable"> |
| 52 |
</dictionary> |
| 53 |
|
| 54 |
Then add the alphabet entry, this can be empty as the alphabet is only |
| 55 |
used for tokenisation and the lsx module comes after the text is |
| 56 |
tokenised. Now we have: |
| 57 |
|
| 58 |
<dictionary type="separable"> |
| 59 |
<alphabet></alphabet> |
| 60 |
</dictionary> |
| 61 |
|
| 62 |
Next we need to add the symbol definitions, abbreviated to sdefs. These |
| 63 |
are the symbols that your words are tagged with, e.g. noun or verb or |
| 64 |
adj. Again, you should be able to just copy the sdef section from your |
| 65 |
language's monodix, and it should contain many more than in this basic |
| 66 |
example. |
| 67 |
|
| 68 |
<dictionary type="separable"> |
| 69 |
<alphabet></alphabet> |
| 70 |
<sdefs> |
| 71 |
<sdef n="adj"/> |
| 72 |
<sdef n="adv"/> |
| 73 |
<sdef n="n"/> |
| 74 |
<sdef n="sep"/> |
| 75 |
<sdef n="vblex"/> |
| 76 |
</sdefs> |
| 77 |
</dictionary> |
| 78 |
|
| 79 |
Now we need to add the paradigm definitions, abbreviated to pardefs. |
| 80 |
These represent patterns of word orders. The following example |
| 81 |
represents words tagged as adjective, noun, noun phrase, and frequency |
| 82 |
adjectives. See the note below about the tags , , . The lemma can be |
| 83 |
represented as anychars (, such as in adj and n below; or by typing out |
| 84 |
the word itself, such as in freq-adv below. Pardefs can be used to |
| 85 |
create other pardefs, such as in SN below. Adding paradigms into the |
| 86 |
dictionary, we get: |
| 87 |
|
| 88 |
<dictionary type="separable"> |
| 89 |
<alphabet></alphabet> |
| 90 |
<sdefs> |
| 91 |
... |
| 92 |
</sdefs> |
| 93 |
<pardefs> |
| 94 |
<pardef n="adj"> <!-- to represent all adjectives --> |
| 95 |
<e><i><w/><s n="adj"/><j/></i></e> <!-- word only has the adj tag --> |
| 96 |
<e><i><w/><s n="adj"/><t/><j/></i></e> <!-- word has the adj tag followed by one or more other tags --> |
| 97 |
</pardef> |
| 98 |
<pardef n="n"> #to represent all nouns |
| 99 |
<e><i><w/><s n="n"/><t/><j/></i></e> <!-- word has the n tag followed by one or more other tags --> |
| 100 |
</pardef> |
| 101 |
<pardef n="SN"> #to represent all noun phrases |
| 102 |
<e><par n="n"/></e> |
| 103 |
<e><par n="adj"/><par n="n"/></e> <!-- word phrase is comprised of an adjective word followed by a noun word --> |
| 104 |
<e><par n="adj"/><par n="adj"/><par n="n"/></e> <!-- word phrase is comprised of two adjectives followed by a noun --> |
| 105 |
</pardef> |
| 106 |
<pardef n="freq-adv"> |
| 107 |
<e><i>always<s n="adv"/><j/></i></e> <!-- i.e. ^always<adv>$ --> |
| 108 |
<e><i>anually<s n="adv"/><j/></i></e> |
| 109 |
<e><i>bianually<s n="adv"/><j/></i></e> |
| 110 |
</pardef> |
| 111 |
</pardefs> |
| 112 |
</dictionary> |
| 113 |
|
| 114 |
Finally, we add the main entries. Here is the final result of our small |
| 115 |
example dictionary: |
| 116 |
|
| 117 |
<dictionary type="separable"> |
| 118 |
<alphabet></alphabet> |
| 119 |
<sdefs> |
| 120 |
<sdef n="adj"/> |
| 121 |
<sdef n="adv"/> |
| 122 |
<sdef n="n"/> |
| 123 |
<sdef n="sep"/> |
| 124 |
<sdef n="vblex"/> |
| 125 |
</sdefs> |
| 126 |
<pardefs> |
| 127 |
<pardef n="adj"> |
| 128 |
<e><i><w/><s n="adj"/><j/></i></e> |
| 129 |
<e><i><w/><s n="adj"/><t/><j/></i></e> |
| 130 |
</pardef> |
| 131 |
<pardef n="n"> |
| 132 |
<e><i><w/><s n="n"/><t/><j/></i></e> |
| 133 |
</pardef> |
| 134 |
<pardef n="SN"> |
| 135 |
<e><par n="n"/></e> |
| 136 |
<e><par n="adj"/><par n="n"/></e> |
| 137 |
<e><par n="adj"/><par n="adj"/><par n="n"/></e> |
| 138 |
</pardef> |
| 139 |
<pardef n="freq-adv"> |
| 140 |
<e><i>always<s n="adv"/><j/></i></e> |
| 141 |
<e><i>anually<s n="adv"/><j/></i></e> |
| 142 |
<e><i>bianually<s n="adv"/><j/></i></e> |
| 143 |
</pardef> |
| 144 |
</pardefs> |
| 145 |
<section id="main" type="standard"> |
| 146 |
<e lm="be late" c="llegar tarde"> |
| 147 |
<p><l>be<s n="vbser"/></l><r>be<g><b/>late</g><s n="vbser"/></r></p><i><t/><j/></i> |
| 148 |
<par n="SAdv"/><p><l>late<t/><j/></l><r></r></p> |
| 149 |
</e> |
| 150 |
<e lm="take away" c="sacar, quitar"> |
| 151 |
<p><l>take<s n="vblex"/></l><r>take<g><b/>away</g><s n="vblex"/></r></p><i><t/><j/></i> |
| 152 |
<par n="SN"/><p><l>away<t/><j/></l><r></r></p> |
| 153 |
</e> |
| 154 |
</section> |
| 155 |
</dictionary> |
| 156 |
|
| 157 |
Note: |
| 158 |
|
| 159 |
- stands for one or more alphabetic symbols |
| 160 |
|
| 161 |
- stands for one or more tags (multicharacter symbols). |
| 162 |
|
| 163 |
- stands for the word boundary symbol $ |
| 164 |
|
| 165 |
i.e. |
| 166 |
|
| 167 |
- `<e><i><w/><s n="adj"/><t/><j/></i></e>` is equivalent to |
| 168 |
`any-one-or-more-chars`<adj><required-anytag>`<...optional-anytag...><$>` |
| 169 |
- ^tall<adj><sint><...>$ |
| 170 |
- `<e><i><w/><s n="adj"/><j/></i></e>` is equivalent to |
| 171 |
`any-one-or-more-chars`<adj>`<$>` |
| 172 |
- ^tall<adj>$ |
| 173 |
|
| 174 |
A larger example dictionary can be found at |
| 175 |
<https://github.com/apertium/apertium-separable/blob/master/examples/apertium-eng-spa.eng-spa.lsx>. |
| 176 |
|
| 177 |
The lsx dictionary file names are of the form `apertium-A-B.A-B.lsx`, |
| 178 |
where apertium-A-B is the name of the language pair. For example, file |
| 179 |
`apertium-eng-cat.eng-cat.lsx` is the lsx dictionary for the `eng-cat` |
| 180 |
pair. The names of the compiled binaries are of the form |
| 181 |
`apertium-A-B.autoseq.bin`. For example, `eng-cat.autoseq.bin`. |
| 182 |
|
| 183 |
### Compilation |
| 184 |
|
| 185 |
Compilation into the binary format is achieved by means of the lsx-comp |
| 186 |
program. Specifying lr as the mode will produce an analyser, and rl will |
| 187 |
produce a generator. |
| 188 |
|
| 189 |
$ lsx-comp lr apertium-eng-spa.eng-spa.lsx eng-spa.autoseq.bin |
| 190 |
main@standard 61 73 |
| 191 |
|
| 192 |
### Processing |
| 193 |
|
| 194 |
Processing can be done using the lsx-proc program. |
| 195 |
|
| 196 |
The input to `lsx-proc` is the output of `apertium-tagger` and |
| 197 |
`apertium-pretransfer`, |
| 198 |
|
| 199 |
$ echo '^take<vblex><imp>$ ^prpers<prn><obj><p3><nt><sg>$ ^out of<pr>$ ^there<adv>$^.<sent>$' | lsx-proc eng-spa.autoseq.bin |
| 200 |
^take# out<vblex><sep><imp>$ ^prpers<prn><obj><p3><nt><sg>$ ^of<pr>$ ^there<adv>$^.<sent>$ |
| 201 |
|
| 202 |
### Example usages |
| 203 |
|
| 204 |
Example #1: A sentence in plain text, |
| 205 |
|
| 206 |
The Aragonese took Ramiro out of a monastery and made him king. |
| 207 |
|
| 208 |
This is the output of feeding the sentence through `apertium-tagger` and |
| 209 |
then `apertium-pretransfer`: |
| 210 |
|
| 211 |
^the<det><def><sp>$ ^Aragonese<n><sg>$ ^take<vblex><past>$ ^Ramiro<np><ant><m><sg>$ ^out of<pr>$ ^a<det><ind><sg>$ |
| 212 |
^monastery<n><sg>$ ^and<cnjcoo>$ ^make<vblex><pp>$ ^prpers<prn><obj><p3><m><sg>$ ^king<n><sg>$^.<sent>$ |
| 213 |
|
| 214 |
This is the output of feeding the output above through `lsx-proc` with |
| 215 |
apertium-eng-spa.eng-spa.lsx: |
| 216 |
|
| 217 |
^the<det><def><sp>$ ^Aragonese<n><sg>$ ^take# out<vblex><sep><past>$ ^Ramiro<np><ant><m><sg>$ ^of<pr>$ ^a<det><ind><sg>$ |
| 218 |
^monastery<n><sg>$ ^and<cnjcoo>$ ^make<vblex><pp>$ ^prpers<prn><obj><p3><m><sg>$ ^king<n><sg>$^.<sent>$ |
| 219 |
|
| 220 |
## Troubleshooting |
| 221 |
|
| 222 |
### Segmentation fault |
| 223 |
|
| 224 |
Segmentation fault upon compilation or usage |
| 225 |
The lsx-dictionary compiles fine with zero entries but gives a seg fault |
| 226 |
once entries are added |
| 227 |
...no solution found yet |
| 228 |
something is not updated or something in the makefile (?) |
| 229 |
|
| 230 |
make sure that the makefile ... |
| 231 |
|
| 232 |
### Complaints about step_override() |
| 233 |
|
| 234 |
git pull in lttoolbox (and do make, make install) |
| 235 |
You'll need an up-to-date version of lttoolbox and associated libraries, |
| 236 |
and zlib (debian: zlib1g-dev). |
| 237 |
|
| 238 |
### Undefined symbol |
| 239 |
|
| 240 |
In your dictionary you are probably using a symbol that you didn't |
| 241 |
define in the sdefs. Add the symbol to the sdefs. |
| 242 |
|
| 243 |
## Future work |
| 244 |
|
| 245 |
### Offloading multiwords from transducers to lsx |
| 246 |
|
| 247 |
In theory we're offloading multiwords from the transducers to lsx. This |
| 248 |
leaves open some questions: |
| 249 |
|
| 250 |
- how do we do N N compounds with lsx? |
| 251 |
- how does translation *to* a multiword work? In theory it's possible |
| 252 |
to invert the transducer, but an attempt to try this results in a |
| 253 |
transducer that looks right but silently fails to apply to input. |
| 254 |
Also, it will need to be able to handle the output of transfer. |
| 255 |
—[Firespeaker](https://wiki.apertium.org/wiki/User:Firespeaker) |
| 256 |
([talk](Uhttps://wiki.apertium.org/wiki/User_talk:Firespeaker)) 00:02, 1 September 2017 |
| 257 |
(CEST) |
| 258 |
|
| 259 |
### Recycling dictionaries and/or paradigms |
| 260 |
|
| 261 |
lsx-dictionaries are packaged in language pairs. the eng-spa |
| 262 |
lsx-dictionary can mostly be reaped by eng-cat. could we make use of the |
| 263 |
similarity? |
| 264 |
|
| 265 |
### Beta testing |
| 266 |
|
| 267 |
Support for language pairs: we haven't gotten much extensive beta |
| 268 |
testing. The following are language pairs that have packaged the |
| 269 |
lsx-module: |
| 270 |
|
| 271 |
- - eng-cat |
| 272 |
- eng-deu (?) |
| 273 |
- kaz-kir |
| 274 |
|
| 275 |
Beta test with more language pairs |
| 276 |
|
| 277 |
### Transfer-like super powers |
| 278 |
|
| 279 |
- Transfer-like capabilities for the lexicon (super powers). E.g., |
| 280 |
gustar / |
| 281 |
|
| 282 |
### The one-to-many bug |
| 283 |
|
| 284 |
Given the following lsx file: |
| 285 |
|
| 286 |
<dictionary type="sequential"> |
| 287 |
<alphabet>АӘБВГҒДЕЁЖЗИІЙКҚЛМНҢОӨПРСТУҰҮФХҺЦЧШЩЬЫЪЭЮЯаәбвгғдеёжзиійкқлмнңоөпрстуұүфхһцчшщьыъэюя</alphabet> |
| 288 |
<sdefs> |
| 289 |
<sdef n="adj"/> |
| 290 |
<sdef n="adv"/> |
| 291 |
<sdef n="n"/> |
| 292 |
<sdef n="nom"/> |
| 293 |
<sdef n="dat"/> |
| 294 |
<sdef n="v"/> |
| 295 |
</sdefs> |
| 296 |
<pardefs> |
| 297 |
<pardef n="adj"> |
| 298 |
<e><i><w/><s n="adj"/><j/></i></e> |
| 299 |
<e><i><w/><s n="adj"/><t/><j/></i></e> |
| 300 |
</pardef> |
| 301 |
<pardef n="n"> |
| 302 |
<e><i><w/><s n="n"/><t/><j/></i></e> |
| 303 |
</pardef> |
| 304 |
<pardef n="SN"> |
| 305 |
<e><par n="n"/></e> |
| 306 |
<e><par n="adj"/><par n="n"/></e> |
| 307 |
<e><par n="adj"/><par n="adj"/><par n="n"/></e> |
| 308 |
</pardef> |
| 309 |
</pardefs> |
| 310 |
<section id="main" type="standard"> |
| 311 |
<e lm="кабарда" c="хабар ет"> |
| 312 |
<p><l>хабар<b/>ет<s n="v"/></l> |
| 313 |
<r>хабар<s n="n"/><s n="nom"/><j/>ет<s n="v"/></r></p><i><t/><j/></i> |
| 314 |
</e> |
| 315 |
<e lm="абайла" c="абай бол"> |
| 316 |
<p><l>абай<b/>бол<s n="v"/></l> |
| 317 |
<r>абай<s n="adj"/><j/>бол<s n="v"/></r></p><i><t/><j/></i> |
| 318 |
</e> |
| 319 |
<e lm="абайла" c="абай бол"> |
| 320 |
<p><l>абай<b/>бол<s n="v"/></l> |
| 321 |
<r>абай<s n="adj"/><j/>бол<s n="v"/></r></p><i><t/>+ма<t/><j/></i> |
| 322 |
<!-- p><l>абай<s n="adj"/><j/>бол<s n="v"/><t/></l> |
| 323 |
<r>абай<b/>бол<s n="v"/><t/></r></p --> |
| 324 |
</e> |
| 325 |
<e lm="сууга түш" c="шомылда"> |
| 326 |
<p><l>сууга<b/>түш<s n="v"/></l> |
| 327 |
<r>суу<s n="n"/><s n="dat"/><j/>түш<s n="v"/></r></p><i><t/><j/></i> |
| 328 |
</e> |
| 329 |
|
| 330 |
</section> |
| 331 |
</dictionary> |
| 332 |
|
| 333 |
and the following code to compile it (where `$(PREFIX1)` is kaz-kir and |
| 334 |
`$(PREFIX2)` is kir-kaz and `$(BASENAME)` is apertium-kaz-kir; the above |
| 335 |
file is apertium-kaz-kir.kir-kaz.lsx): |
| 336 |
|
| 337 |
$(PREFIX1).autoseq.bin: $(BASENAME).$(PREFIX1).lsx |
| 338 |
lsx-comp $< $@ |
| 339 |
|
| 340 |
$(PREFIX2).autoseq.bin: $(BASENAME).$(PREFIX2).lsx |
| 341 |
lsx-comp $< $@ |
| 342 |
|
| 343 |
$(PREFIX1).revautoseq.bin: $(BASENAME).$(PREFIX1).lsx |
| 344 |
lt-print $(PREFIX1).autoseq.bin | sed 's/ /@_SPACE_@/g' > $(PREFIX1).autoseq.att |
| 345 |
hfst-txt2fst -e ε < $(PREFIX1).autoseq.att > $(PREFIX1).autoseq.hfst |
| 346 |
hfst-invert $(PREFIX1).autoseq.hfst | hfst-minimise > $(PREFIX1).revautoseq.hfst |
| 347 |
hfst-fst2txt $(PREFIX1).revautoseq.hfst | gzip -9 -c -n > $(PREFIX1).revautoseq.att.gz |
| 348 |
zcat < $(PREFIX1).revautoseq.att.gz > $(PREFIX1).revautoseq.att |
| 349 |
sed 's/@0@/ε/g' $(PREFIX1).revautoseq.att > $(PREFIX1).revautoseq.1.att |
| 350 |
lt-comp lr $(PREFIX1).revautoseq.1.att $@ |
| 351 |
|
| 352 |
|
| 353 |
$(PREFIX2).revautoseq.bin: $(BASENAME).$(PREFIX2).lsx |
| 354 |
lt-print $(PREFIX2).autoseq.bin | sed 's/ /@_SPACE_@/g' > $(PREFIX2).autoseq.att |
| 355 |
hfst-txt2fst -e ε < $(PREFIX2).autoseq.att > $(PREFIX2).autoseq.hfst |
| 356 |
hfst-invert $(PREFIX2).autoseq.hfst | hfst-minimise > $(PREFIX2).revautoseq.hfst |
| 357 |
hfst-fst2txt $(PREFIX2).revautoseq.hfst | gzip -9 -c -n > $(PREFIX2).revautoseq.att.gz |
| 358 |
zcat < $(PREFIX2).revautoseq.att.gz > $(PREFIX2).revautoseq.att |
| 359 |
sed 's/@0@/ε/g' $(PREFIX2).revautoseq.att > $(PREFIX2).revautoseq.1.att |
| 360 |
lt-comp lr $(PREFIX2).revautoseq.1.att $@ |
| 361 |
|
| 362 |
EXPECTED OUTPUT: |
| 363 |
|
| 364 |
we expect lr compilation to give the following behaviour: |
| 365 |
|
| 366 |
$ echo "^хабар ет<v><iv><ifi><p1><sg>$" | lsx-proc kaz-kir.autoseq.bin |
| 367 |
^хабар<n><nom>$ ^ет<v><iv><ifi><p1><sg>$ |
| 368 |
|
| 369 |
and |
| 370 |
|
| 371 |
$ echo "^хабар<n><nom>$ ^ет<v><iv><ifi><p1><sg>$" | lsx-proc kaz-kir.autoseq.bin |
| 372 |
^хабар<n><nom>$ ^ет<v><iv><ifi><p1><sg>$ |
| 373 |
|
| 374 |
WHEREAS with rl compilation (outputting with name revautoseq), we expect |
| 375 |
the following behaviour: |
| 376 |
|
| 377 |
$ echo "^хабар<n><nom>$ ^ет<v><iv><ifi><p1><sg>$" | lsx-proc kaz-kir.revautoseq.bin |
| 378 |
^хабар ет<v><iv><ifi><p1><sg>$ |
| 379 |
|
| 380 |
and |
| 381 |
|
| 382 |
$ echo "^хабар ет<v><iv><ifi><p1><sg>$" | lsx-proc kaz-kir.revautoseq.bin |
| 383 |
^хабар ет<v><iv><ifi><p1><sg>$ |
| 384 |
|
| 385 |
## See also |
| 386 |
|
| 387 |
- [Apertium system |
| 388 |
architecture](https://wiki.apertium.org/wiki/Apertium_system_architecture) |
| 389 |
- GSOC project [ proposal](https://wiki.apertium.org/wiki/User:Irene/proposal), [ |
| 390 |
workplan](https://wiki.apertium.org/wiki/User:Irene/workplan), [ |
| 391 |
report](https://wiki.apertium.org/wiki/Lsx_module/report) |
| 392 |
- [/GCI_2017](https://wiki.apertium.org/wiki/Apertium_separable/GCI_2017) |
| 393 |
|