-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMANUAL.html
1038 lines (920 loc) · 37.5 KB
/
MANUAL.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta name="generator" content="http://txt2tags.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Korektor</title>
</head>
<body>
<div class="header" id="header">
<h1>Korektor</h1>
<h2>Version 2.0.1-devel</h2>
</div>
<div class="toc">
<ol>
<li><a href="#introduction">Introduction</a>
</li>
<li><a href="#online">Online Services</a>
<ul>
<li><a href="#plugin">2.1. Korektor Spellchecker Browser Plugin</a>
</li>
<li><a href="#online_demo">2.2. Korektor Web Application</a>
</li>
<li><a href="#web_service">2.3. Korektor Web Service</a>
</li>
</ul>
</li>
<li><a href="#release">Release</a>
<ul>
<li><a href="#download">3.1. Download</a>
<ul>
<li><a href="#spellchecker_models">3.1.1. Spellchecker Models</a>
</li>
<li><a href="#original_michal_richters_version">3.1.2. Original Michal Richter's version</a>
</li>
</ul>
</li>
<li><a href="#license">3.2. License</a>
</li>
</ul>
</li>
<li><a href="#instalation">Installation</a>
<ul>
<li><a href="#requirements">4.1. Requirements</a>
</li>
<li><a href="#compilation">4.2. Compilation</a>
<ul>
<li><a href="#compilation_platforms">4.2.1. Platforms</a>
</li>
<li><a href="#compilation_further_details">4.2.2. Further Details</a>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#users_manual">User's Manual</a>
<ul>
<li><a href="#korektor-czech">5.1. Czech Korektor Models</a>
<ul>
<li><a href="#korektor-czech_download">5.1.1. Download</a>
</li>
<li><a href="#korektor-czech_acknowledgements">5.1.2. Acknowledgements</a>
</li>
<li><a href="#korektor-czech_variants">5.1.3. Czech Model Variants</a>
</li>
</ul>
</li>
<li><a href="#run_korektor">5.2. Running the Korektor</a>
<ul>
<li><a href="#korektor_input_formats">5.2.1. Input Formats</a>
</li>
<li><a href="#korektor_corrections">5.2.2. Number of Corrections</a>
</li>
<li><a href="#korektor_output_formats">5.2.3. Output Formats</a>
</li>
<li><a href="#korektor_context_free">5.2.4. Context Free Corrections</a>
</li>
<li><a href="#korektor_viterbi_decoding_options">5.2.5. Viterbi Decoding Options</a>
</li>
</ul>
</li>
<li><a href="#run_tokenizer">5.3. Running the tokenizer</a>
<ul>
<li><a href="#tokenizer_input_formats">5.3.1. Input Formats</a>
</li>
<li><a href="#tokenizer_output_formats">5.3.2. Output Formats</a>
</li>
</ul>
</li>
<li><a href="#run_korektor_server">5.4. Running the REST Server</a>
</li>
</ul>
</li>
<li><a href="#model_creation">Model Creation</a>
<ul>
<li><a href="#model_create_morphology">6.1. Creating a Morphology Model</a>
<ul>
<li><a href="#model_create_morphology_format">6.1.1. Morphology Lexicon Input Format</a>
</li>
<li><a href="#model_create_morphology_run">6.1.2. Running create_morphology</a>
</li>
</ul>
</li>
<li><a href="#model_create_lm">6.2. Creating a Language Model for Each Morphological Factor</a>
</li>
<li><a href="#model_create_error">6.3. Creating an Error Model</a>
<ul>
<li><a href="#model_create_error_format">6.3.1. Error Model Input Format</a>
</li>
<li><a href="#model_create_error_run">6.3.2. Running create_error_model</a>
</li>
</ul>
</li>
<li><a href="#model_create_conf">6.4. Configuration File</a>
</li>
</ul>
</li>
<li><a href="#contact">Contact</a>
</li>
<li><a href="#korektor_acknowledgements">Acknowledgements</a>
<ul>
<li><a href="#publications">8.1. Publications</a>
</li>
<li><a href="#bibtex_for_referencing">8.2. Bibtex for Referencing</a>
</li>
<li><a href="#persistent_identifier">8.3. Persistent Identifier</a>
</li>
</ul>
</li>
</ol>
</div>
<div class="body" ID="body">
<a id="introduction" name="introduction"></a>
<h1>1. Introduction</h1>
<p>
Korektor is a statistical spellchecker and (occasional) grammar checker
released under <a href="http://opensource.org/licenses/BSD-2-Clause">2-Clause BSD license</a>
and versioned using <a href="http://semver.org/">Semantic Versioning</a>.
</p>
<p>
Korektor started with Michal Richter's diploma thesis
<a href="https://redmine.ms.mff.cuni.cz/documents/1">Advanced Czech Spellchecker</a>,
but it is being developed further. There are two versions: a
<i>command line utility</i> (tested on Linux, Windows and OS X) and
a <i>REST service</i> with <a href="https://lindat.mff.cuni.cz/services/korektor/api-reference.php">publicly available API</a>
and <a href="https://lindat.mff.cuni.cz/services/korektor/">HTML front end</a>.
</p>
<p>
The original <i>OS X SpellServer</i> providing System Service integrating
Korektor with native OS X GUI applications is no longer developed, but do not
hesitate to contact us if you are interested in it.
</p>
<p>
Copyright 2015 by Institute of Formal and Applied Linguistics, Faculty of
Mathematics and Physics, Charles University in Prague, Czech Republic.
</p>
<a id="online" name="online"></a>
<h1>2. Online Services</h1>
<a id="plugin" name="plugin"></a>
<h2>2.1. Korektor Spellchecker Browser Plugin</h2>
<p>
Korektor Spellchecker is a browser plugin which allows using the Korektor
Spellchecker for most editable input fields. The plugin allows either
directly correcting the content, or showing a dialog with suggested corrections.
</p>
<p>
Note that the dialog with suggestions is injected directly into the original
page, so there can be various problems on untested sites. However, the plugin
seem to work fine on many sites.
</p>
<p>
Although the sources of Korektor service and this plugin are available
under BSD-3-Clause license, please respect the CC BY-SA-NC licence
of the spellchecking models.
</p>
<p style="margin-bottom:0">
The plugin is available for the following browers:
</p>
<ul style="margin-top:0">
<li>Chrome: available as <a href="https://chrome.google.com/webstore/detail/korektor-spellchecker/clbjpfehpgcfakbadjendaebmhooiecl">Korektor Spellchecker plugin</a>
in the Google Web Store
</li>
<li>Firefox: available as <a href="https://addons.mozilla.org/en/firefox/addon/korektor-spellchecker/">Korektor Spellchecker plugin</a>
in the AMO (Mozilla Add-ons repository)
</li>
</ul>
<a id="online_demo" name="online_demo"></a>
<h2>2.2. Korektor Web Application</h2>
<p>
Korektor Web Application is available at <a href="https://lindat.mff.cuni.cz/services/korektor/">https://lindat.mff.cuni.cz/services/korektor/</a>
using <a href="http://lindat.cz">LINDAT/CLARIN infrastructure</a>.
</p>
<a id="web_service" name="web_service"></a>
<h2>2.3. Korektor Web Service</h2>
<p>
Korektor REST Web Service is also available, with the API documentation available
at <a href="https://lindat.mff.cuni.cz/services/korektor/api-reference.php">https://lindat.mff.cuni.cz/services/korektor/api-reference.php</a>.
</p>
<a id="release" name="release"></a>
<h1>3. Release</h1>
<a id="download" name="download"></a>
<h2>3.1. Download</h2>
<p>
Korektor releases are available on <a href="http://github.com/ufal/korektor">GitHub</a>, either as
a pre-compiled binary package, or source code packages only.
</p>
<ul>
<li><a href="http://github.com/ufal/korektor/releases/latest">Latest release</a>
</li>
<li><a href="http://github.com/ufal/korektor/releases">All releases</a>, <a href="https://github.com/ufal/korektor/blob/master/CHANGES">Changelog</a>
</li>
</ul>
<a id="spellchecker_models" name="spellchecker_models"></a>
<h3>3.1.1. Spellchecker Models</h3>
<p>
To use Korektor, a spellchecker model is needed. The language models are available
from <a href="http://www.lindat.cz">LINDAT/CLARIN</a> infrastructure and described further
in the
<a href="#users_manual">Korektor User's Manual</a>.
Currently the following language models are available:
</p>
<ul>
<li>Czech: <a href="http://hdl.handle.net/11234/1-1460">korektor-czech-130202</a> (<a href="http://ufal.mff.cuni.cz/korektor/users-manual#korektor-czech-130202">documentation</a>)
</li>
</ul>
<a id="original_michal_richters_version" name="original_michal_richters_version"></a>
<h3>3.1.2. Original Michal Richter's version</h3>
<p>
The original Michal Richter's version can be downloaded
<a href="http://hdl.handle.net/11858/00-097C-0000-000D-F67C-5">here</a>.
</p>
<a id="license" name="license"></a>
<h2>3.2. License</h2>
<p>
Korektor is an open-source project and is freely available for non-commercial
purposes. The library is distributed under <a href="http://opensource.org/licenses/BSD-2-Clause">2-Clause BSD license</a>
and the associated models and data under <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">CC BY-NC-SA</a>,
although for some models the original data used to create the model may impose
additional licensing conditions.
</p>
<p>
If you use this tool for scientific work, please give credit to us by
referencing <a href="http://ufal.mff.cuni.cz/korektor">Korektor website</a> and
<a href="#publications">Richter et al. 2012</a>.
</p>
<a id="instalation" name="instalation"></a>
<h1>4. Installation</h1>
<p>
Korektor releases are available on <a href="http://github.com/ufal/korektor">GitHub</a>, either as
a pre-compiled binary package, or source code only. The binary package contains Linux,
Windows and OS X binaries.
</p>
<p>
To use Korektor, a language model is needed.
<a href="http://ufal.mff.cuni.cz/korektor#spellchecker_models">Here is a list of available language models</a>.
</p>
<p>
If you want to compile Korektor manually, sources are available on on
<a href="http://github.com/ufal/korektor">GitHub</a>, both in the
<a href="http://github.com/ufal/korektor/releases">pre-compiled binary package releases</a>
and in the repository itself.
</p>
<a id="requirements" name="requirements"></a>
<h2>4.1. Requirements</h2>
<ul>
<li><code>G++ 4.7</code> or newer, <code>clang 3.2</code> or newer, <code>Visual C++ 2015</code> or newer
</li>
<li><code>make</code>: on Windows, you can use <a href="http://sourceforge.net/projects/mingw/files/MinGW/Extension/make/make-3.82-mingw32/"><code>mingw32-make</code></a>
</li>
</ul>
<a id="compilation" name="compilation"></a>
<h2>4.2. Compilation</h2>
<p>
To compile Korektor, run <code>make</code> in the <code>src</code> directory.
</p>
<p style="margin-bottom:0">
Make targets and options:
</p>
<ul style="margin-top:0">
<li><code>exe</code>: compile the binaries (default)
</li>
<li><code>lib</code>: compile the static library
</li>
<li><code>BITS=32</code> or <code>BITS=64</code>: compile for specified 32-bit or 64-bit architecture instead of the default one
</li>
<li><code>MODE=release</code>: create release build which statically links the C++ runtime and uses LTO
</li>
<li><code>MODE=debug</code>: create debug build
</li>
<li><code>MODE=profile</code>: create profile build
</li>
</ul>
<a id="compilation_platforms" name="compilation_platforms"></a>
<h3>4.2.1. Platforms</h3>
<p style="margin-bottom:0">
Platform can be selected using one of the following options:
</p>
<ul style="margin-top:0">
<li><code>PLATFORM=linux</code>, <code>PLATFORM=linux-gcc</code>: gcc compiler on Linux operating system, default on Linux
</li>
<li><code>PLATFORM=linux-clang</code>: clang compiler on Linux, must be selected manually
</li>
<li><code>PLATFORM=osx</code>, <code>PLATFORM=osx-clang</code>: clang compiler on OS X, default on OS X; <code>BITS=32+64</code> enables multiarch build
</li>
<li><code>PLATFORM=win</code>, <code>PLATFORM=win-gcc</code>: gcc compiler on Windows (TDM-GCC is well tested), default on Windows
</li>
<li><code>PLATFORM=win-vs</code>: Visual C++ 2015 compiler on Windows, must be selected manually; note that the
<code>cl.exe</code> compiler must be already present in <code>PATH</code> and corresponding <code>BITS=32</code> or <code>BITS=64</code>
must be specified
</li>
</ul>
<p>
Either POSIX shell or Windows CMD can be used as shell, it is detected automatically.
</p>
<a id="compilation_further_details" name="compilation_further_details"></a>
<h3>4.2.2. Further Details</h3>
<p>
Korektor uses <a href="http://github.com/ufal/cpp_builtem">C++ BuilTem system</a>,
please refer to its manual if interested in all supported options.
</p>
<a id="users_manual" name="users_manual"></a>
<h1>5. User's Manual</h1>
<p>
Korektor is a statistical spellchecker and (occasional) grammar checker.
Like any supervised machine learning tool, Korektor needs a trained linguistic model.
We now describe the available language models, and then the command line tools
<code>korektor</code> and <code>tokenizer</code>.
</p>
<a id="korektor-czech" name="korektor-czech"></a>
<h2>5.1. Czech Korektor Models</h2>
<p>
Czech models are distributed under the
<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">CC BY-NC-SA</a> licence.
The Czech morphology used by the model is based on
<a href="http://hdl.handle.net/11858/00-097C-0000-0015-A780-9">MorfFlex CZ</a>
Czech models work in Korektor version 2 or later.
</p>
<p>
Czech models are versioned according to the release date in format
<code>YYMMDD</code>, where <code>YY</code>, <code>MM</code> and <code>DD</code> are two-digit representation of
year, month and day, respectively. The latest version is 130202.
</p>
<a id="korektor-czech_download" name="korektor-czech_download"></a>
<h3>5.1.1. Download</h3>
<p>
The latest version 130202 of the Czech Korektor models can be downloaded
from <a href="http://hdl.handle.net/11234/1-1460">LINDAT/CLARIN repository</a>.
</p>
<a id="korektor-czech_acknowledgements" name="korektor-czech_acknowledgements"></a>
<h3>5.1.2. Acknowledgements</h3>
<p>
This work has been using language resources developed and/or stored and/or
distributed by the LINDAT/CLARIN project of the Ministry of Education of the
Czech Republic (project <i>LM2010013</i>).
</p>
<p>
The latest Czech models were created by Michal Richter as part of his
Master thesis and are described in (Richter et al. 2012).
</p>
<p>
The MorfFlex CZ dictionary was created by Jan Hajič and Jaroslava Hlaváčová.
</p>
<a id="korektor-czech_publications" name="korektor-czech_publications"></a>
<h4>5.1.2.1. Publications</h4>
<ul>
<li>(Richter et al. 2012) Richter Michal, Straňák Pavel and Rosen Alexandr. <i>Korektor – A System for Contextual Spell-checking and Diacritics Completion</i> In Proceedings of the 24th International Conference on Computational Linguistics (Coling 2012), pages 1-12, Mumbai, India, 2012.
</li>
</ul>
<a id="korektor-czech_variants" name="korektor-czech_variants"></a>
<h3>5.1.3. Czech Model Variants</h3>
<p>
The Czech model contains the following variants:
</p>
<dl>
<dt><code>korektok-czech-130202/diacritics_h2mor.conf</code></dt><dd>
Spellchecker model which only _adds_ diacritical marks.
Note that the diacritical marks are not removed by the model, so you have to
strip them manually if you want to ignore them.
<p></p>
</dd>
<dt><code>korektok-czech-130202/spellchecking_h2mor.conf</code></dt><dd>
Spellchecker model which considers corrections with edit distance at most
once. You should use this model for generic spellchecking.
<p></p>
</dd>
<dt><code>korektok-czech-130202/spellchecking_h2mor_2edits.conf</code></dt><dd>
Spellchecker model which considers corrections with edit distance at most
two. This model can be useful if the required corrections are not found
by the <code>spellchecking_h2mor.conf</code> model, but it may be considerably slower.
</dd>
</dl>
<a id="run_korektor" name="run_korektor"></a>
<h2>5.2. Running the Korektor</h2>
<p>
The <code>korektor</code> binary is used to run the Korektor. The only required argument
is the model configuration which should be used for correcting. The input is read
from standard input, it should be in UTF-8 encoding and it can be either
already tokenized and segmented, segmented only, or it can be a plain text.
The output is written to standard output and it is in UTF-8 encoding.
</p>
<p style="margin-bottom:0">
The full command syntax of <code>korektor</code> is
</p>
<pre style="margin-top:0">
korektor [options] model_configuration
Options: --input=untokenized|untokenized_lines|segmented|vertical|horizontal
--output=original|xml|vertical|horizontal
--corrections=maximum_number_of_corrections
--viterbi_order=viterbi_decoding_order
--viterbi_beam_size=maximum_viterbi_beam_size
--viterbi_stage_pruning=maximum_viterbi_stage_cost_increment
--context_free
--version
--help
</pre>
<a id="korektor_input_formats" name="korektor_input_formats"></a>
<h3>5.2.1. Input Formats</h3>
<p style="margin-bottom:0">
The input format is specified using the <code>--input</code> option. Currently supported
input formats are:
</p>
<ul style="margin-top:0">
<li><code>untokenized</code> (default): the input is a plain text, which is segmented and
tokenized automatically. Note that sentences can span over multiple lines,
but an empty lines always terminate a sentence.
</li>
<li><code>untokenized_lines</code>: very similar to <code>untokenized</code>, the only difference
is that sentences cannot span over multiple lines, so every newline is
a sentence terminator.
</li>
<li><code>segmented</code>: the input is assumed to be segmented using newlines, but it is
tokenized automatically.
</li>
<li><code>vertical</code>: the input is tokenized and segmented in vertical format, every
line is considered a word, with empty line denoting end of sentence.
</li>
<li><code>horizontal</code>: the input is tokenized and segmented in horizontal format,
every line is a sentence, with words separated by spaces.
</li>
</ul>
<a id="korektor_corrections" name="korektor_corrections"></a>
<h3>5.2.2. Number of Corrections</h3>
<p>
The maximum number of corrections that Korektor should return for every word is
specified using the <code>--corrections</code> option, and defaults to one.
</p>
<p>
Note that some output formats cannot handle multiple corrections, because they
can only replace the original word by a corrected one.
</p>
<a id="korektor_output_formats" name="korektor_output_formats"></a>
<h3>5.2.3. Output Formats</h3>
<p style="margin-bottom:0">
The output format is specified using the <code>--output</code> option. Currently
supported output formats are:
</p>
<ul style="margin-top:0">
<li><code>original</code> (default when number of corrections is 1): the original words
are replaced by the corrected ones, all other characters including spaces are
preserved. Note that this output format cannot handle multiple corrections
per word.
</li>
<li><code>xml</code> (default when number of corrections is greater than 1): the original
input is encoded as XML and the suggested corrections are marked
using the following XML elements:
<ul>
<li>spelling corrections for a word <i>w</i> are marked using the <code>spelling</code>
element with the suggested corrections listed in the <code>suggestions</code> attribute
ordered by correction probability with the most probable one first
</li>
<li>grammar corrections are marked as spelling corrections, but the <code>grammar</code>
element is used instead of <code>spelling</code>
</li>
</ul>
To illustrate, consider the input
<pre>
Hoši jely k babicce.
</pre>
The output in <code>xml</code> output format with at most three corrections is
<pre>
Hoši <grammar suggestions="jeli jely jel">jely</grammar> k <spelling suggestions="babičce babice babince">babicce</spelling>.
</pre>
</li>
<li><code>vertical</code>: each word is printed on a separate line, with empty line
denoting end of sentence. If there are any suggested corrections for a word,
they are printed on the same line as the original words using several <code>tab</code>
separated columns:
<ul>
<li>the first column contain the original word
</li>
<li>the second column contain either letter <code>S</code> or <code>G</code>, where <code>S</code> denotes
a spelling correction and <code>G</code> denotes a grammar correction
</li>
<li>the rest of the columns are the suggested corrections ordered by correction
probability with the most probable one first
</li>
</ul>
To illustrate, consider the input
<pre>
Hoši jely k babicce.
</pre>
The output in <code>vertical</code> output format with at most three corrections with
explicitly marked <code>tab</code> characters is
<pre>
Hoši
jely<---tab---->G<--tab-->jeli<---tab---->jely<--tab--->jel
k
babicce<--tab-->S<--tab-->babičce<--tab-->babice<--tab-->babince
.
</pre>
</li>
<li><code>horizontal</code>: the original words are replaced by the corrected ones. Each
sentence is printed on separate line and all words are space separated. Note
that this output format cannot handle multiple corrections per word.
</li>
</ul>
<a id="korektor_context_free" name="korektor_context_free"></a>
<h3>5.2.4. Context Free Corrections</h3>
<p>
Context free corrections can be generated by supplying the <code>--context_free</code>
option. In that case each word is considered separately and sentences boundaries
are ignored. This mode produces much worse results and should be used only when
no context is really available.
</p>
<a id="korektor_viterbi_decoding_options" name="korektor_viterbi_decoding_options"></a>
<h3>5.2.5. Viterbi Decoding Options</h3>
<p style="margin-bottom:0">
The decoding Viterbi algorithm can be tweaked using the following options:
</p>
<ul style="margin-top:0">
<li><code>--viterbi_order</code>: Use specific Viterbi decoding order instead of the default
one. Use 1 for fastest execution, but worst accuracy. Setting this to higher
value than maximum model order minus one has no effect.
</li>
<li><code>--viterbi_beam_size</code>: Limit Viterbi beam size to specified constant.
Use smaller value for faster execution, but worse accuracy.
</li>
<li><code>--viterbi_stage_pruning</code>: Limit maximum cost increment in one Viterbi stage.
Use smaller value for faster execution, but worse accuracy.
</li>
</ul>
<a id="run_tokenizer" name="run_tokenizer"></a>
<h2>5.3. Running the tokenizer</h2>
<p>
The <code>tokenizer</code> binary is used to run the tokenizer. The input is read
from standard input, it should be in UTF-8 encoding and it can be either
already tokenized and segmented, segmented only, or it can be a plain text.
The output is written to standard output and it is in UTF-8 encoding.
</p>
<p style="margin-bottom:0">
The full command syntax of <code>tokenizer</code> is
</p>
<pre style="margin-top:0">
korektor [options] model_configuration
Options: --input=untokenized|untokenized_lines|segmented|vertical|horizontal
--output=vertical|horizontal
--version
--help
</pre>
<a id="tokenizer_input_formats" name="tokenizer_input_formats"></a>
<h3>5.3.1. Input Formats</h3>
<p style="margin-bottom:0">
The input format is specified using the <code>--input</code> option. Currently supported
input formats are:
</p>
<ul style="margin-top:0">
<li><code>untokenized</code> (default): the input is a plain text, which is segmented and
tokenized automatically. Note that sentences can span over multiple lines,
but an empty lines always terminate a sentence.
</li>
<li><code>untokenized_lines</code>: very similar to <code>untokenized</code>, the only difference
is that sentences cannot span over multiple lines, so every newline is
a sentence terminator.
</li>
<li><code>segmented</code>: the input is assumed to be segmented using newlines, but it is
tokenized automatically.
</li>
<li><code>vertical</code>: the input is tokenized and segmented in vertical format, every
line is considered a word, with empty line denoting end of sentence.
</li>
<li><code>horizontal</code>: the input is tokenized and segmented in horizontal format,
every line is a sentence, with words separated by spaces.
</li>
</ul>
<a id="tokenizer_output_formats" name="tokenizer_output_formats"></a>
<h3>5.3.2. Output Formats</h3>
<p style="margin-bottom:0">
The output format is specified using the <code>--output</code> option. Currently
supported output formats are:
</p>
<ul style="margin-top:0">
<li><code>vertical</code>: each word is printed on a separate line, with empty line
denoting end of sentence.
</li>
<li><code>horizontal</code>: each sentence is printed on separate line and all words are
space separated.
</li>
</ul>
<a id="run_korektor_server" name="run_korektor_server"></a>
<h2>5.4. Running the REST Server</h2>
<p>
The REST server can be run using the <code>korektor_server</code> binary.
The binary uses <a href="http://github.com/ufal/microrestd">MicroRestD</a> as a REST
server implementation and provides
<a href="http://lindat.mff.cuni.cz/services/korektor/api-reference.php">Korektor REST API</a>.
</p>
<p style="margin-bottom:0">
The full command syntax of <code>korektor_server</code> is
</p>
<pre style="margin-top:0">
korektor_server [options] port (model_name weblicht_language model_file acknowledgements)*
Options: --daemon
</pre>
<p>
The <code>korektor_server</code> can run either in foreground or in background (when
<code>--daemon</code> is used). The specified model files are loaded during start and
kept in memory all the time. This behaviour might change in future to load the
models on demand.
</p>
<a id="model_creation" name="model_creation"></a>
<h1>6. Model Creation</h1>
<p>
In order to create a new spellchecker model for Korektor, several models
must be created and a configuration file describing these models must be
provided.
</p>
<p>
Korektor uses flexible morphology system which associates several
<i>morphological factors</i> to every word, with the word itself being considered
as a first one. Usually the factors are <code>form</code>, <code>lemma</code> and <code>tag</code>, but
arbitrary factors may be used. Note that currently there is a hard limit of
four factors for efficiency (you can change <code>FactorList::MAX_FACTORS</code> if you
want more).
</p>
<p>
For each morphological factor a language model is needed.
</p>
<p>
The last required model is an error model describing costs of various spelling
errors.
</p>
<a id="model_create_morphology" name="model_create_morphology"></a>
<h2>6.1. Creating a Morphology Model</h2>
<p>
To create a morphology model, a morphology lexicon input file must be provided
and processed by the <code>create_morphology</code> binary.
</p>
<a id="model_create_morphology_format" name="model_create_morphology_format"></a>
<h3>6.1.1. Morphology Lexicon Input Format</h3>
<p style="margin-bottom:0">
The morphology lexicon is an UTF-8 encoded file in the following format:
</p>
<ul style="margin-top:0">
<li>the first line contains names of the factors delimited by <code>|</code>
</li>
<li>following lines contain two space separated columns, the first column is a word
factor strings delimited by <code>|</code> (there must be the same number of tokens as
on the first line) and the second column is a count number of this morphology
entry.
</li>
</ul>
<p>
Example:
</p>
<pre>
form|lemma|tag
dog|dog|NN 68
likes|like|VB 220
...
</pre>
<a id="model_create_morphology_run" name="model_create_morphology_run"></a>
<h3>6.1.2. Running create_morphology</h3>
<p style="margin-bottom:0">
The <code>create_morphology</code> should be run as follows:
</p>
<pre style="margin-top:0">
create_morphology in_morphology_lexicon out_bin_morphology out_bin_vocabulary out_test_file
</pre>
<a id="model_create_lm" name="model_create_lm"></a>
<h2>6.2. Creating a Language Model for Each Morphological Factor</h2>
<p>
The language model for each morphological factor should be created by an
external tool such as SRILM or KenLM and stored in ARPA format.
</p>
<p style="margin-bottom:0">
To create a binary representation of such model in ARPA format, the
<code>create_lm_binary</code> tool should be used as follows:
</p>
<pre style="margin-top:0">
create_lm_binary in_arpa_model in_bin_morphology in_bin_vocabulary factor_name lm_order out_bin_lm
</pre>
<a id="model_create_error" name="model_create_error"></a>
<h2>6.3. Creating an Error Model</h2>
<p>
To create an error model, a textual error model description must be provided
and processed by the <code>create_error_model</code> binary.
</p>
<a id="model_create_error_format" name="model_create_error_format"></a>
<h3>6.3.1. Error Model Input Format</h3>
<p style="margin-bottom:0">
The textual error model description is in UTF-8 format and contains one error
model item (edit operation) per line. Each item contain three <code>tab</code> separated
columns <code>signature</code>, <code>edit distance</code> and <code>cost</code>:
</p>
<ul style="margin-top:0">
<li><code>signature</code>: Describes the edit operation in the following format:
<ul>
<li><code>s_ab</code>: substitution of letter <code>a</code> for letter <code>b</code>
</li>
<li><code>i_abc</code>: insertion of letter <code>a</code> between letters <code>b</code> and <code>c</code>
</li>
<li><code>d_ab</code>: deletion of letter <code>a</code> following after letter <code>b</code>
</li>
<li><code>swap_ab</code>: swap of letters <code>ab</code> to <code>ba</code>
</li>
<li><code>case</code>: change of letter casing (lowercase to uppercase and vice verse)
</li>
<li><code>substitutions</code>: default substitution operation used when no <code>s_..</code> rule apply
</li>
<li><code>insertions</code>: default insertion operation used when no <code>i_...</code> rule apply
</li>
<li><code>deletions</code>: default deletion operation used when no <code>d_..</code> rule apply
</li>
<li><code>swaps</code>: default swap operation used when no <code>swap_..</code> rule apply
<p></p>
</li>
</ul>
</li>
<li><code>edit distance</code>: Integral edit distance of this operation. This distance
is used during the similar words lookup which is limited by maximum edit
distance. The sensible default is 1, but it can be useful to use 0 for
example when removing/adding diacritical mark only.
<p></p>
</li>
<li><code>cost</code>: The logarithm of the probability of the edit operation.
</li>
</ul>
<p>
The first five lines must contain operations <code>case</code>, <code>substitutions</code>,
<code>insertions</code>, <code>deletions</code> and <code>swaps</code>, in this order.
</p>
<p>
Example (with textually marked <code>tab</code> characters):
</p>
<pre>
case<------tab------->0<---tab--->2.6
substitutions<--tab-->1<---tab--->3.8
insertions<---tab---->1<---tab--->4.4
deletions<----tab---->1<---tab--->3.5
swaps<------tab------>1<---tab--->4.1
s_qw<-------tab------>1<---tab--->3.7
s_ui<-------tab------>1<---tab--->2.3
s_yi<-------tab------>1<---tab--->2.1
s_aá<-------tab------>0<---tab--->1.7
i_iuo<------tab------>1<---tab--->4.8
...
</pre>
<a id="model_create_error_run" name="model_create_error_run"></a>
<h3>6.3.2. Running create_error_model</h3>
<p style="margin-bottom:0">
The <code>create_error_model</code> binary should be run as follows:
</p>
<pre style="margin-top:0">
create_morphology --binarize in_txt_error_model out_bin_error_model
</pre>
<a id="model_create_conf" name="model_create_conf"></a>
<h2>6.4. Configuration File</h2>
<p>
The configuration specifies morphology model, language models and error model
to use. In addition, it specifies similar word searching strategy and it can
enable a diagnostics mode.
</p>
<p>
When a file is specified in the configuration file, its name is
considered to be relative to the directory containing the configuration file.
</p>
<p style="margin-bottom:0">
The configuration file is line oriented and each line should adhere to one of
the following formats:
</p>
<ul style="margin-top:0">
<li>an empty line or a line starting with <code>#</code> is ignored
</li>
<li><code>morpholex=bin_morphology_file</code>: use the specified morphology model
</li>
<li><code>lm-bin_lm_file-model_order-model_weight</code>: use the specified language
model. The corresponding factor is stored in the language model itself.
Model weight is a floating point multiplicative factor used when all factor
language model probabilities are summed together.
</li>
<li><code>errormodel=bin_error_model_file</code>: use the specified error model file
</li>
<li><code>search-casing_treatment-max_edit_distance-max_cost</code>: defines method for finding
possible corrections. Multiple methods can be specified in the configuration
file. The methods are tried in the order of their appearance in the
configuration file until one produces nonempty set of possible corrections.
Each search method has the following options:
<ul>
<li><code>casing_treatment</code>: there are three possible method names:
<ul>
<li><code>case_sensitive</code>: the casing of the original word is honored when
looking up possible suggestions in the morphology model
</li>
<li><code>ignore_case</code>: the casing of the original word is ignored when
looking up possible suggestions in the morphology model, and the casing
defined in the morphology model is used instead of the original one
</li>
<li><code>ignore_case_keep_orig</code>: the casing of the original word is ignored
when looking up possible suggestions in the morphology model, but the
generated suggestions have the same casing as the original word
</li>
</ul>
</li>
<li><code>max_edit_distance</code>: the maximum edit distance of possible corrections
</li>
<li><code>max_cost</code>: the maximum cost of possible corrections
</li>
</ul>
</li>
<li><code>diagnostics=bin_vocabulary_file</code>: use diagnostics mode which dumps a lot of
information during spellchecking. A vocabulary file created during
<a href="#model_create_morphology">morphology model creation</a> is needed to print out
the morphological factors.
</li>
</ul>
<p>
The lines can be in arbitrary order, only the relative ordering of <code>search-</code>
lines is utilized when finding possible corrections.
</p>
<p>
As an example consider the configuration file <code>spellchecking_h2mor.txt</code> of
<code>korektor-czech-130202</code> model:
</p>
<pre>
# Binary file containing morphology and lexicon.
morpholex=data/morphology_h2mor_freq2.bin
# Error model binary.
errormodel=data/error_model_train0.bin
# Language models in the following format:
# lm-[filename]-[order]-[weight]
lm-data/form_lm_h2mor.bin-3-0.40
lm-data/lemma_lm_h2mor.bin-3-0.1
lm-data/tag_lm_h2mor.bin-3-0.50
# Search options, each item specify a distinct search rounds.
# Searches are triggered in the order specified in this file,
# whenever one of the search rounds find at least one possibility,
# the consecutive search rounds are not triggered.
# The format is the following:
# search-[casing_treatment]-[max_edit_distance]-[max_cost]
search-case_sensitive-1-6
search-ignore_case_keep_orig-1-6
search-ignore_case_keep_orig-2-9
# The diagnostics mode can be activated by uncommenting the following line.
#diagnostics=data/morphology_h2mor_freq2_vocab.bin
</pre>
<a id="contact" name="contact"></a>
<h1>7. Contact</h1>
<p style="margin-bottom:0">
Current Authors:
</p>
<ul style="margin-top:0">
<li><a href="http://ufal.mff.cuni.cz/milan-straka">Milan Straka</a>, <a href="mailto:[email protected]">[email protected]</a>
</li>
<li><a href="http://ufal.mff.cuni.cz/pavel-stranak">Pavel Straňák</a>, <a href="mailto:[email protected]">[email protected]</a>
</li>
<li><a href="http://ufal.mff.cuni.cz/loganathan-ramasamy">Loganathan Ramasamy</a>, <a href="mailto:[email protected]">[email protected]</a>
</li>
</ul>
<p style="margin-bottom:0">
Original Author:
</p>
<ul style="margin-top:0">
<li>Michal Richter, <a href="mailto:[email protected]">[email protected]</a>
</li>
</ul>
<p>
<a href="http://ufal.mff.cuni.cz/korektor">Korektor website</a>.
</p>
<p>
<a href="http://hdl.handle.net/11234/1-1469">Korektor LINDAT/CLARIN entry</a>.
</p>
<a id="korektor_acknowledgements" name="korektor_acknowledgements"></a>
<h1>8. Acknowledgements</h1>
<p>
This work has been using language resources developed and/or stored and/or distributed by the LINDAT/CLARIN project of the Ministry of Education of the Czech Republic (project <i>LM2010013</i>).
</p>
<p>
Acknowledgements for individual language models are listed in <a href="#users_manual">Korektor User's Manual</a>.
</p>