Skip to content

LTN/Plone

Sections
Personal tools
You are here: Home » Members » poonlap's Home » latex » สร้าง hyphenation ภาษาไทยด้วย patgen/opatgen

สร้าง hyphenation ภาษาไทยด้วย patgen/opatgen

ท้าวความ

สืบเนื่องมาจากบอร์ด development ของ TLWG ได้มีการพูดถึงการตัดคำโดยอาศัย hyphenation ที่คุณอัศวิน(ว.จุฬา)ได้ทำไว้เลยไปหาข้อมูลและลองสร้าง pattern ของ hyphenation ภาษาไทยดูบ้าง.

จริงๆแล้วก่อนหน้านั้นประมาณ 1-2 ปีคุณอานนท์ก็พูดถึงการสร้าง hyphenation เหมือนกันแต่ก็ได้ซาหายไปแต่ไม่ได้หายสาปสูญพักไว้). ก็ได้ข้อมูลเกี่ยวกับการสร้าง hyphenation ว่าใช้ โปรแกรมที่เรียกว่า patgen ซึ่งมากับ แพกเกจ TeX อยู่แล้ว.

Patgen เป็นโปรแกรมเขียนด้วยภาษา pascal ในรูปของภาษา WEB. ถ้ามีรหัสต้นฉบับของ TeX อยู่จะเห็นเป็นไฟล์ patgen.web. ใช้โปรแกรม weave กระทำการกับไฟล์นี้จะได้เอกสารของ patgen ออกมา.

# weave patgen
This is WEAVE, Version 4.4 (Web2C 7.4.5)
*1*12*26*33*43*51*64*74*90*94*98*99
Writing the output file...*1*12*26*33*43*51*64*74*90*94*98*99
Writing the index...Done.
(No errors were found.)

ใช้ tex สร้างเอกสารอ่านได้ต่อไป.

# tex patgen
This is TeX, Version 3.14159 (Web2C 7.4.5)
(./patgen.tex
Babel  and hyphenation patterns for american, french, german, ngerman, n
ohyphenation, loaded.
(/usr/share/texmf/tex/plain/base/webmac.tex) *1 [46] [47] [48] [49] *12
[50] [51] [52] [53] [54] [55] *26 [56] [57] *33 [58] [59] [60] [61] *43
[62] [63] [64] *51 [65] [66] [67] [68] [69] [70] *64 [71] [72] [73] [74] *74
[75] [76] [77] [78] [79] [80] [81] *90 [82] [83] *94 [84] [85] *98 [86] *99
Index: [87] [88] [89] Section names: [90] Table of contents: (./CONTENTS.tex)
[45] )
Output written on patgen.dvi (46 pages, 202792 bytes).
Transcript written on patgen.log.

การใช้ patgen ถ้าดูจาก manpage ระบุไว้ว่า

patgen dictionary_file pattern_file log_file translate_file
dictionay_file คือไฟล์ที่รวมคำศัพท์ที่ใส่เครื่องหมาย "-" ไว้แล้ว. pattern_file คือ pattern ที่จะไปใช้กับ TeX. Log คือ log. translate_file คือไฟล์ที่แปลความข้อมูลนำเข้า. สรุปแล้วไม่รู้เรื่อง, เข้าใจลำบาก. ซ้ำร้ายหาตัวอย่างการใช้จากอินเทอร์เน็ตก็ไม่มี. หายข้อมูลได้ยากมาก.

ต่อมารู้ว่านอกจาก patgen แล้วยังมีโปรแกรม opatgen ซึ่งเป็นโปรแกรมเหมือนกับ patgen แต่เขียนด้วย C++ โดยคุณ David Antos. เลยไปเอามาใช้ดู. มีเอกสารเขียนไว้อย่างดีแุถมมีการใช้ opatgen สร้าง hyphenation ช่วยในการตัดคำภาษาไทยด้วย.

ปัญหา

เอาไฟล์ที่ใส่ "-" แล้วมากจากไหน. ปีที่แล้วเคยใช้ cttex สร้าง hyphenation ไฟล์ภาษาไทยไว้เลยเอามาลองดู.

ปัญหาต่อไปคือ translate ไฟล์นี่ทำอย่างไร? ตอนแรกคิดว่าเป็น .tcx ที่ใช้ใน LaTeX เอามาใช้ทีไรก็มี error ทุกที. เมื่อปีที่แล้วลองแล้วเลยเลิกไป. ปีนี้หลังจากที่คุณอัศวินทำ pattern ใช้เลยฮึดค้นคว้าหาข้อมูลดูจนได้วิธีทำจนได้.

translate_file

อ่านจากคู่มือการใช้ของ opatgen ซึ่งไฟล์ translate เหมือนกับ patgen (ถ้าเข้าใจไม่ผิด) สร้าง translate ไว้แบบนี้.

2 3
** หลังอักษรทุกตัวมี space อยู่สองตัว
 ก
 ข
 ค
 ฆ
 ง
 จ
 ฉ
 ช
 ซ
 ฌ
 ญ
 ฎ
 ฏ
 ฐ
 ฑ
 ฒ
 ณ
 ด
 ต
 ถ
 ท
 ธ
 น
 บ
 ป
 ผ
 ฝ
 พ
 ฟ
 ภ
 ม
 ย
 ร
 ฤ
 ล
 ว
 ศ
 ษ
 ส
 ห
 ฬ
 อ
 ฮ
 ะ
 ั
 า
 ำ
 ิ
 ี
 ึ
 ื
 ุ
 ู
 เ
 แ
 โ
 ใ
 ไ
 ๅ
 ๆ
 ็
 ่
 ้
 ๊
 ๋
 ์

ทำไมถึงเป็นอย่างนี้? มีความหมายอย่างไร? ลองไปหาคู่มือ opatgen อ่านดูครับ.

สร้าง pattern

คราวนี้ถึงเวลาสร้าง pattern โดยทำตาม manual บอก.

$ ./opatgen hyphenation.txt /dev/null output translate
This is OPATGEN, version 1.0
 
Written and maintained by David Antos, xantos (at) fi.muni.cz
Copyright (C) 2001 David Antos
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Thank you for using free software!
 
! Values of left_hyphen_min and right_hyphen_min in translate are invalid.
left_hyphen_min, right_hyphen_min: 2 3
left_hyphen_min = 2, right_hyphen_min = 3
66 letters
hyph_start, hyph_finish: 1 1
0 pattern lines read in
pat_start, pat_finish: 1 2
good weight, bad weight, threshold: 1 1 1
 
 
Generating level 1
 
Generating a pass with pat_len = 1, pat_dot = 0
 
0 good 0 bad 7006 missed
0 % 0 % 100 %
Count data structure statistics:
  nodes:                           68
  patterns:                        65
  trie_max:                        68
  current q_max_thresh:            3
Collecting candidates
26 good and 22 bad patterns added (more to come)
finding 4454 good and 1730 bad hyphens
efficiency = 2.53645
Pattern data structure statistics:
  nodes:                           68
  patterns:                        48
  trie_max:                        68
  current q_max_thresh:            5
  number of different outputs:     3
 
Generating a pass with pat_len = 1, pat_dot = 1
 
4454 good 1730 bad 2552 missed
63.5741 % 24.6931 % 36.4259 %
Count data structure statistics:
  nodes:                           68
  patterns:                        65
  trie_max:                        68
  current q_max_thresh:            3
Collecting candidates
5 good and 16 bad patterns added (more to come)
finding 5198 good and 1829 bad hyphens
efficiency = 2.83424
Pattern data structure statistics:
  nodes:                           68
  patterns:                        52
  trie_max:                        68
  current q_max_thresh:            5
  number of different outputs:     8
 
Generating a pass with pat_len = 2, pat_dot = 1
 
5198 good 1829 bad 1808 missed
74.1935 % 26.1062 % 25.8065 %
Count data structure statistics:
  nodes:                           445
  patterns:                        377
  trie_max:                        1573
  current q_max_thresh:            3
Collecting candidates
146 good and 100 bad patterns added (more to come)
finding 6236 good and 2239 bad hyphens
efficiency = 2.61468
Pattern data structure statistics:
  nodes:                           314
  patterns:                        298
  trie_max:                        729
  current q_max_thresh:            5
  number of different outputs:     8
 
Generating a pass with pat_len = 2, pat_dot = 0
 
6236 good 2239 bad 770 missed
89.0094 % 31.9583 % 10.9906 %
Count data structure statistics:
  nodes:                           596
  patterns:                        528
  trie_max:                        1472
  current q_max_thresh:            3
Collecting candidates
48 good and 379 bad patterns added (more to come)
finding 6586 good and 2384 bad hyphens
efficiency = 2.70806
Pattern data structure statistics:
  nodes:                           683
  patterns:                        667
  trie_max:                        1649
  current q_max_thresh:            5
  number of different outputs:     9
 
Generating a pass with pat_len = 2, pat_dot = 2
 
6586 good 2384 bad 420 missed
94.0051 % 34.028 % 5.99486 %
Count data structure statistics:
  nodes:                           1072
  patterns:                        1004
  trie_max:                        3418
  current q_max_thresh:            3
Collecting candidates
28 good and 811 bad patterns added (more to come)
finding 6648 good and 2405 bad hyphens
efficiency = 2.73243
Pattern data structure statistics:
  nodes:                           1203
  patterns:                        1187
  trie_max:                        3151
  current q_max_thresh:            5
  number of different outputs:     20
937 bad patterns deleted
total of 253 patterns at level 1
hyphenate word list ? y
Writing file pattmp.1
 
6648 good 2405 bad 358 missed
94.8901 % 34.3277 % 5.10991 %
 

ทำครั้งที่สอง.

$ cp output pattern
$ ./opatgen hyphenation.txt pattern output translate
This is OPATGEN, version 1.0
 
Written and maintained by David Antos, xantos (at) fi.muni.cz
Copyright (C) 2001 David Antos
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Thank you for using free software!
 
! Values of left_hyphen_min and right_hyphen_min in translate are invalid.
left_hyphen_min, right_hyphen_min: 2 3
left_hyphen_min = 2, right_hyphen_min = 3
66 letters
hyph_start, hyph_finish: 2 2
250 pattern lines read in
pat_start, pat_finish: 2 3
good weight, bad weight, threshold: 1 2 1
 
 
Generating level 2
 
Generating a pass with pat_len = 2, pat_dot = 1
 
6648 good 2405 bad 358 missed
94.8901 % 34.3277 % 5.10991 %
Count data structure statistics:
  nodes:                           1074
  patterns:                        1006
  trie_max:                        3549
  current q_max_thresh:            3
Collecting candidates
162 good and 580 bad patterns added (more to come)
finding 7829 good and 2452 bad hyphens
efficiency = 2.99503
Pattern data structure statistics:
  nodes:                           937
  patterns:                        900
  trie_max:                        2841
  current q_max_thresh:            5
  number of different outputs:     13
 
Generating a pass with pat_len = 2, pat_dot = 0
 
6601 good 1224 bad 405 missed
94.2192 % 17.4707 % 5.78076 %
Count data structure statistics:
  nodes:                           890
  patterns:                        822
  trie_max:                        2746
  current q_max_thresh:            3
Collecting candidates
230 good and 381 bad patterns added (more to come)
finding 7177 good and 1246 bad hyphens
efficiency = 4.86247
Pattern data structure statistics:
  nodes:                           1268
  patterns:                        1231
  trie_max:                        3697
  current q_max_thresh:            5
  number of different outputs:     30
 
Generating a pass with pat_len = 2, pat_dot = 2
 
6579 good 648 bad 427 missed
93.9052 % 9.24921 % 6.09478 %
Count data structure statistics:
  nodes:                           742
  patterns:                        674
  trie_max:                        2852
  current q_max_thresh:            3
Collecting candidates
66 good and 444 bad patterns added (more to come)
finding 6730 good and 656 bad hyphens
efficiency = 9.32133
Pattern data structure statistics:
  nodes:                           1461
  patterns:                        1424
  trie_max:                        4063
  current q_max_thresh:            5
  number of different outputs:     60
 
Generating a pass with pat_len = 3, pat_dot = 1
 
6571 good 497 bad 435 missed
93.791 % 7.09392 % 6.20896 %
Count data structure statistics:
  nodes:                           1298
  patterns:                        980
  trie_max:                        4356
  current q_max_thresh:            3
Collecting candidates
130 good and 664 bad patterns added (more to come)
finding 6742 good and 504 bad hyphens
efficiency = 10.6341
Pattern data structure statistics:
  nodes:                           2329
  patterns:                        2218
  trie_max:                        5618
  current q_max_thresh:            5
  number of different outputs:     60
 
Generating a pass with pat_len = 3, pat_dot = 2
 
6564 good 326 bad 442 missed
93.6911 % 4.65315 % 6.30888 %
Count data structure statistics:
  nodes:                           1166
  patterns:                        942
  trie_max:                        4693
  current q_max_thresh:            3
Collecting candidates
69 good and 743 bad patterns added (more to come)
finding 6651 good and 329 bad hyphens
efficiency = 16.7111
Pattern data structure statistics:
  nodes:                           3137
  patterns:                        2998
  trie_max:                        8546
  current q_max_thresh:            5
  number of different outputs:     60
 
Generating a pass with pat_len = 3, pat_dot = 0
 
6561 good 239 bad 445 missed
93.6483 % 3.41136 % 6.3517 %
Count data structure statistics:
  nodes:                           1554
  patterns:                        1275
  trie_max:                        6987
  current q_max_thresh:            3
Collecting candidates
81 good and 1122 bad patterns added (more to come)
finding 6679 good and 241 bad hyphens
efficiency = 20.7422
Pattern data structure statistics:
  nodes:                           4172
  patterns:                        4006
  trie_max:                        12059
  current q_max_thresh:            5
  number of different outputs:     60
 
Generating a pass with pat_len = 3, pat_dot = 3
 
6559 good 121 bad 447 missed
93.6198 % 1.72709 % 6.38025 %
Count data structure statistics:
  nodes:                           1432
  patterns:                        866
  trie_max:                        3776
  current q_max_thresh:            3
Collecting candidates
34 good and 782 bad patterns added (more to come)
finding 6598 good and 121 bad hyphens
efficiency = 42.5677
Pattern data structure statistics:
  nodes:                           4704
  patterns:                        4501
  trie_max:                        13259
  current q_max_thresh:            5
  number of different outputs:     78
3557 bad patterns deleted
total of 772 patterns at level 2
hyphenate word list ? y
Writing file pattmp.2
 
6559 good 82 bad 447 missed
93.6198 % 1.17043 % 6.38025 %
 


ทำต่อไปเรื่อยๆ.

$ cp output pattern
$ ../tmp/opatgen hyphenation.txt pattern output translate
This is OPATGEN, version 1.0
 
Written and maintained by David Antos, xantos (at) fi.muni.cz
Copyright (C) 2001 David Antos
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Thank you for using free software!
 
! Values of left_hyphen_min and right_hyphen_min in translate are invalid.
left_hyphen_min, right_hyphen_min: 2 3
left_hyphen_min = 2, right_hyphen_min = 3
66 letters
hyph_start, hyph_finish: 3 3
944 pattern lines read in
pat_start, pat_finish: 3 4
good weight, bad weight, threshold: 3 4 3
 
 
Generating level 3
 
Generating a pass with pat_len = 3, pat_dot = 1
 
6559 good 82 bad 447 missed
93.6198 % 1.17043 % 6.38025 %
Count data structure statistics:
  nodes:                           5699
  patterns:                        4620
  trie_max:                        24097
  current q_max_thresh:            3
Collecting candidates
149 good and 4347 bad patterns added (more to come)
finding 6793 good and 98 bad hyphens
efficiency = 27.502
Pattern data structure statistics:
  nodes:                           5870
  patterns:                        5212
  trie_max:                        17163
  current q_max_thresh:            5
  number of different outputs:     25
 
Generating a pass with pat_len = 3, pat_dot = 2
 
6793 good 98 bad 213 missed
96.9597 % 1.3988 % 3.04025 %
Count data structure statistics:
  nodes:                           5544
  patterns:                        4212
  trie_max:                        19196
  current q_max_thresh:            3
Collecting candidates
40 good and 4076 bad patterns added (more to come)
finding 6846 good and 103 bad hyphens
efficiency = 47.8741
Pattern data structure statistics:
  nodes:                           8497
  patterns:                        7556
  trie_max:                        26323
  current q_max_thresh:            5
  number of different outputs:     43
 
Generating a pass with pat_len = 3, pat_dot = 0
 
6846 good 103 bad 160 missed
97.7162 % 1.47017 % 2.28376 %
Count data structure statistics:
  nodes:                           6623
  patterns:                        5254
  trie_max:                        24340
  current q_max_thresh:            3
Collecting candidates
39 good and 5149 bad patterns added (more to come)
finding 6896 good and 104 bad hyphens
efficiency = 48.2238
Pattern data structure statistics:
  nodes:                           10036
  patterns:                        8977
  trie_max:                        32880
  current q_max_thresh:            5
  number of different outputs:     77
 
Generating a pass with pat_len = 3, pat_dot = 3
 
6896 good 104 bad 110 missed
98.4299 % 1.48444 % 1.57008 %
Count data structure statistics:
  nodes:                           5371
  patterns:                        4196
  trie_max:                        20482
  current q_max_thresh:            3
Collecting candidates
24 good and 4111 bad patterns added (more to come)
finding 6923 good and 105 bad hyphens
efficiency = 53.6667
Pattern data structure statistics:
  nodes:                           10835
  patterns:                        9724
  trie_max:                        35891
  current q_max_thresh:            5
  number of different outputs:     135
 
Generating a pass with pat_len = 4, pat_dot = 2
 
6923 good 105 bad 83 missed
98.8153 % 1.49872 % 1.1847 %
Count data structure statistics:
  nodes:                           325
  patterns:                        117
  trie_max:                        534
  current q_max_thresh:            3
Collecting candidates
28 good and 50 bad patterns added (more to come)
finding 6956 good and 105 bad hyphens
efficiency = 52.3008
Pattern data structure statistics:
  nodes:                           10916
  patterns:                        9802
  trie_max:                        35891
  current q_max_thresh:            5
  number of different outputs:     135
 
Generating a pass with pat_len = 4, pat_dot = 1
 
6956 good 105 bad 50 missed
99.2863 % 1.49872 % 0.713674 %
Count data structure statistics:
  nodes:                           230
  patterns:                        75
  trie_max:                        340
  current q_max_thresh:            3
Collecting candidates
14 good and 37 bad patterns added (more to come)
finding 6975 good and 105 bad hyphens
efficiency = 58.6134
Pattern data structure statistics:
  nodes:                           10967
  patterns:                        9852
  trie_max:                        35891
  current q_max_thresh:            5
  number of different outputs:     135
 
Generating a pass with pat_len = 4, pat_dot = 3
 
6975 good 105 bad 31 missed
99.5575 % 1.49872 % 0.442478 %
Count data structure statistics:
  nodes:                           236
  patterns:                        68
  trie_max:                        352
  current q_max_thresh:            3
Collecting candidates
7 good and 41 bad patterns added (more to come)
finding 6982 good and 105 bad hyphens
efficiency = 62.3393
Pattern data structure statistics:
  nodes:                           11033
  patterns:                        9899
  trie_max:                        35996
  current q_max_thresh:            5
  number of different outputs:     135
 
Generating a pass with pat_len = 4, pat_dot = 0
 
6982 good 105 bad 24 missed
99.6574 % 1.49872 % 0.342564 %
Count data structure statistics:
  nodes:                           356
  patterns:                        179
  trie_max:                        965
  current q_max_thresh:            3
Collecting candidates
12 good and 155 bad patterns added (more to come)
finding 6994 good and 105 bad hyphens
efficiency = 59.7778
Pattern data structure statistics:
  nodes:                           11193
  patterns:                        10059
  trie_max:                        36229
  current q_max_thresh:            5
  number of different outputs:     135
 
Generating a pass with pat_len = 4, pat_dot = 4
 
6994 good 105 bad 12 missed
99.8287 % 1.49872 % 0.171282 %
Count data structure statistics:
  nodes:                           286
  patterns:                        77
  trie_max:                        381
  current q_max_thresh:            3
Collecting candidates
6 good and 69 bad patterns added (more to come)
finding 7000 good and 105 bad hyphens
efficiency = 63.0631
Pattern data structure statistics:
  nodes:                           11263
  patterns:                        10128
  trie_max:                        36229
  current q_max_thresh:            5
  number of different outputs:     141
8907 bad patterns deleted
total of 319 patterns at level 3
hyphenate word list ? y
Writing file pattmp.3
 
7000 good 105 bad 6 missed
99.9144 % 1.49872 % 0.0856409 %
 

จะเห็นได้ว่าค่าความถูกต้องมากขึ้น. ถ้าใช้ patgen แทน opatgen ก็มีวิธีการทำเหมือนๆกัน(ยังไม่ได้่ตรวจสอบ).

เอาเท่านี้ก่อนแล้วกันครับ.

Created by poonlap
Last modified 2005-06-01 02:58 PM

เป็นประโยชน์กับอนุชนรุ่นหลัง

Posted by vee at 2004-01-30 10:33 PM

เป็นประโยชน์กับอนุชนรุ่นหลัง ... *เจ๋ง*

 

Powered by Plone

This site conforms to the following standards: