บันทึกของวีร์ | Vee(r)'s Blog

มีนาคม 20, 2012

Part-of-speech tagger สำหรับภาษาไทย

Filed under: ไม่มีหมวดหมู่ — ป้ายกำกับ:, , , , , , — वीर @ 8:45 am

โพสนี้จะใช้ model ที่ได้มาจาก corpus ของ NAiST Lab นะครับ ส่วนโปรกรมก็จะใช้ Jitar เนื่องจากว่า Jitar เขาใช้ Java นะครับ ก่อนอื่นก็ต้องติดตั้ง JDK ก่อน จากนั้นก็โหลด Jitar และ Model มาได้เลย  ตาม URL นี้ http://naist.cpe.ku.ac.th/pkg/jitar_model_large.zip และ http://naist.cpe.ku.ac.th/pkg/jitar-20100224.zip

พอแตก Zip ออกมาได้หาไฟล์ jitar-0.0.4.jar, ngrams และ lexicon ลากไปอยู่ใน folder เดียวกัน จากนั้นก็สร้างไฟล์สำหรับลองใช้โปรแกรมผมใช้ชื่อ test.txt เขียนข้างในว่า “ฉัน กิน ข้าว” อย่าลืมเว้นวรรคด้วยนะครับ ต้องใช้ charset เป็น UTF-8 ด้วย

เสร็จแล้วก็ลองรันดูแบบนี้ครับ java -cp jitar-0.0.4.jar org.langkit.tagger.cli.Tag lexicon ngrams < test.txt ก็จะได้ผลลัพธ์ออกเป็น pper vt ncn

pper คือ สรรพนามสำหรับแทนคน

vt คือ สกรรมกริยม

ncn คือ สามัญนาม

กุมภาพันธ์ 25, 2011

workaround สำหรับ jitar, ภาษาไทย และ UTF-8 บน Windows อาจจะ GNU/Linux ด้วย

Filed under: Deep geeky — ป้ายกำกับ:, , , , , — वीर @ 12:31 am

ถ้าใช้ JRE บน Windows มันจะเลือก encoding เป็น MS874 ให้ ส่วนบน GNU/Linux ก็ซวยไป ถ้าเป็น Solaris ก็ไม่มีปัญหาอะไร เรื่องแบบนี้จะไปแก้ใน jitar ก็ใช่ที่ จะแก้ JRE ก็ไม่ไหว ก็เลย ทำ jitar ให้ใช้ UTF-8 แบบบังคับไปก่อน แต่ไม่ request pull นะ เพราะมันไม่น่าทำ น่าแก้ที่ JRE หรือไม่ก็เปลี่ยนไปใช้ MS874 มั้ง

http://www.oracle.com/technetwork/java/javase/locales-137662.html
https://github.com/veer66/jitar

กุมภาพันธ์ 15, 2011

ใช้ Miktex

Filed under: Light IT — ป้ายกำกับ:, , , , , , — वीर @ 10:37 pm

ผมลง basic-miktex-2.9.3972 และ texmaker บน Windows 7 สิ่งเคยใช้ได้บน Fedora มันก็เจ๊ง ปัญหาก็เกิดจากขาด package บางอย่างไปเท่านั้นเอง สิ่งที่ต้องทำคือเรียก mpm ขึ้นมาลง thailatex ลง unicode และอะไรอื่นๆ ที่มันต้องการก็เสร็จแล้ว

ผมใช้ \usepackage[utf8x]{inputenc} และ \usepackage[thai,english]{babel} ด้วย มันอาจจะมีท่าดีกว่านี้แต่ก็ขี้เกียจแก้

เคยลองใช้ Word 2007 ก็ยังงงๆ อยู่ ก็เลยใช้ Latex ไปก่อนแล้วกัน

กุมภาพันธ์ 4, 2011

กรณีเจ๊งของ PHP และ regular expression เวลาเจอภาษไทย + UTF-8

Filed under: PHP — ป้ายกำกับ:, , , , — वीर @ 4:41 pm

ถ้ามี code แบบนี้ใช้ charset เป็น UTF-8

<?php
	print_r(preg_split("/\\s/", "ประเภท"));
?>

แบบนี้มันไม่น่าจะ split ได้เพราะว่า ไม่มี space ใน “ประเภท” เลยแต่มัน split ได้ซะงั้น

Array
(
    [0] => เธ›เธฃเธฐเน€เธ
    [1] => เธ—
)

แถวๆ “ภ” มันคงแปลงไปเป็นอะไรแล้ว code ไปเป็น space มั้ง

แต่ไม่ว่าจะเพราะว่าอะไร มีท่าแก้ง่ายๆ แบบนี้ใส่ u เข้าไป หายครับ

<?php
	print_r(preg_split("/\\s/u", "ประเภท"));
?>

ผมใช้ php 5.3.5 ที่มากับ xampp 1.7.4 และทดลองบน Windows 7 ครับ

กันยายน 3, 2010

จดไว้ X11 กับภาษาไทย

Filed under: ไม่มีหมวดหมู่ — ป้ายกำกับ:, , — वीर @ 12:03 am
Section "InputDevice"
	Identifier  "Keyboard0"
	Driver      "kbd"
    Option      "CoreKeyboard"
    Option      "XkbRules"  "xorg"
    Option      "XkbModel"  "pc104"
    Option      "XkbLayout" "us,th"
    Option      "XkbVariant"  "basic,tis"
    Option      "XKbOptions" "grp:alt_shift_toggle"
EndSection

เมษายน 23, 2010

ใช้ Tubsub API ผ่าน PHP

Filed under: NLP — ป้ายกำกับ:, , , , , — वीर @ 2:16 pm

ก็เขียน code แบบนี้เลยครับ

<?php
  function tubsub($txt) {
    $txt = urlencode($txt);
    $data = "input=$txt";
    $ch = curl_init("http://vivaldi.cpe.ku.ac.th/~vee/tubsube2t.php");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);      
    curl_close($ch);
    $ans = json_decode($output);
    return $ans[0];
  }

  print tubsub("toto") . "\n";
?>

เขียนแบบข้างบนโปรแกรมก็จะพิมพ์ออกมาว่าเขียน toto ภาษาไทยเขียนอย่างไร ถ้าจะใช้กับอย่างอื่นก็ copy function tubsub ไปใช้ได้เลยครับ

ธันวาคม 1, 2009

double click เพื่อเลือกคำเดียวใน Firefox

Filed under: Software development — ป้ายกำกับ:, , , , , — वीर @ 4:01 pm

ปกติกด double click ไปบน text แล้วมันควรเลือกคำเดียว แต่ว่า Firefox เวลาเจอภาษาไทยกลับไปเลือกก้อนใหญ่ๆ ผมก็เลยถามไปที่ Thai Linux/FOSS developers <a href="http://thep.blogspot.com/"ป๋าเทพบอกว่าน่าจะเป็น bug 425915

วันนี้ผมก็เลยลองดูสักหน่อย สำหรับกรณีปัญหาที่เกิดจากการเลือกคำด้วย double click ผมคิดว่า code ส่วนที่จะแก้คือ layout/generic/nsSelection.cpp ใน method ชื่อ nsTypedSelection::selectFrames โดยก่อนที่จะเรียก textFrame->SetSelectedRange(startOffset, endOffset, aFlags, mType); ค่า endOffset น่าจะหาโดยใช้ nsIWordBreak::FindWord

แต่ว่า nsIWordBreak ตอนนี้มี implementation แต่ nsSampleWordBreak ที่มี comment ข้างในว่า

// need to call Thai word breaker from here
// we should pass the whole Thai segment to the thai word breaker to
find a shorter answer

แต่ว่าไฟล์นี้ก็สร้างมาตั้งนานแล้วยังไม่มีการแก้ไขอะไร

ผมรู้สึกไม่มั่นใจเท่าไหร่ที่ต้องไปเรียก nsIWordBreak เองใน nsTypedSelection::selectFrames อยากจะถาม ท่านอื่นๆ ว่าน่าจะใช้ทางนี้หรือเปล่า หรือว่า nsIWordBreak ไม่ควรใช้ ถ้าหากควรใช้ ควรจะเอาไปใส่ใน nsTypedSelection::selectFrames หรือเปล่า?

ผมก็ถามไปใน group ด้วย

วันนี้ก็เอาไว้แค่นี้ก่อน ดึงจังหวะรอดู comment นิดนึง

พฤศจิกายน 23, 2009

XMLChid – This product is created with the use of ORCHID corpus jointly developed by NECTEC and NICT

Filed under: 1 — ป้ายกำกับ:, , , , — वीर @ 5:06 pm

Orchid เป็นคลังข้อความที่มีคำ ชนิดของคำ (ทางภาษาศาสตร์) และข้อมูลอื่นๆ อยู่ มีมาตั้งแต่ พ.ศ. 2540 ตอนนี้มีหน้าเว็บที่เข้าไปดาวโหลดได้แล้ว http://www.hlt.nectec.or.th/orchid/

ผมลองเปิดดูคิดว่าถ้าเป็น xml ก็น่าจะใช้ได้ง่ายดีเหมือนกัน ก็เลยลองแปลงเป็น xml ดู ทำมาได้ปี 2 แล้วมั้ง แต่ว่าพึ่งเอามาปล่อย เพราะว่า พึ่งเห็น license ของ orchid ที่ชัดเจน และจะเอาไปใช้ในการเรียนการสอนวิชา NLP

license ของ Orchid ซึ่งก็รวมถึง XMLChid มีว่าแบบนี้

     	

@1997 National Electronics and Computer Technology Center (NECTEC). All
rights reserved.

LICENSE AGREEMENT

License agreement (LA) is a legal agreement between you and NECTEC.Please read it carefully before redistribution, reproduction or downloading from ORCHID services. This license agreement consists of the above copyright notice, definitions, the acceptance of license agreement, terms of use, and disclaimer information. In addition, it provides warranty information, specific terms and conditions that depart from other "free" softwares or corpora and "open source" softwares or copora.

1. Definitions

(a) "NECTEC" refers to National Electronics and Computer Technology Center which is an organization under National Science and Technology Development Agency (NSTDA), Ministry of Science and Technology, Thailand.

(b) "NICT" refers to National Institute of Information and Communications Technology, Japan.

(b) "ORCHID" refers to a database or corpus jointly developed by NECTEC and NICT.

(c) "Services" refer to any supplies for accessing to a variety of resources, including tools, downloading, communication and collected information, and also any update, enhancement, new features, and/or the addition of any new Web property.

(d) "Terms of Use" or "TOU" refers to terms and conditions for utilizing ORCHID.

(e) "You" refers to any end users and/or government and private contributors who download program and data from ORCHID website in order to reproduce, redistribute and update content, material, or any products corresponding to ORCHID.

2. Acceptance of License Agreement
NECTEC reserves the right to update the license agreement at any time without prior notice.

3. Terms of Use

Redistribution and use of ORCHID, with or without modification, are permitted provided that all of the following conditions are met:

(a) Redistribution of ORCHID must retain the above copyright notice, Acceptance of License Agreement, TOU, and the disclaimer in section 4.

(b) Any product, created and redistributed by you, which is composed or uses of any part from ORCHID must include the following acknowledgement:

"This product is created with the use of ORCHID corpus jointly developed by NECTEC and NICT."

(c) Products derived from the adaptation of ORCHID must not be called "ORCHID", nor may "ORCHID" appear in their name, without prior written permission of NECTEC.

(d) You must not use "ORCHID" in a manner likely to cause any damage to NECTEC, NICT, or third person. NECTEC shall reserve our rights to demand any compensation, retaining fee, costs of action and execution, and expenses occurred out of such manner.

(e) Neither the name of the National Electronics and Computer Technology Center (NECTEC) / National Science and Technology Development Agency (NSTDA) / National Institute of Information and Communications Technology (NICT) nor the names of its contributors may be used to endorse or promote product derived from this software without specific prior written permission.

4. Disclaimer of Warranty

ORCHID, INFORMATION, CONTENT, MATERIAL, OR PRODUCT JOINLY PROVIDED OR RELEASED BY NECTEC AND NICT ARE THE COPYRIGHTED WORK OF NECTEC AND NICT. MOREOVER, ORCHID, INFORMATION, CONTENT, MATERIAL, OR PRODUCT JOINTLY PROVIDED OR RELEASED BY NECTEC, NICT AND CONTRIBUTORS ARE ALSO ON AN "AS IS" AND "AS AVAILABLE" BASIS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NECTEC, NICT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE SOFTWARE, INFORMATION CONTENT, MATERIAL, OR PRODUCT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

พอดีเขาห้ามใช้ชื่อเดิมก็เลยตั้งชื่อให้ใหม่ว่า XMLChid ซึ่งดาวโหลดได้ที่ http://naist.cpe.ku.ac.th/pkg/xmlchid-20091123.tar.gz

การติดตั้งและใช้งาน KUCut บน Windows (XP)

Filed under: NLP — ป้ายกำกับ:, , , , , , — वीर @ 1:42 pm

KUCut มีคนถามบ่อยเหมือนกันว่าติดตั้งใช้งานอย่างไร ผมก็เลยเขียนเป็น blog ไว้เลยดีกว่า

  1. ติดตั้ง Python 2.6.2
  2. ขั้นตอนแรกก็ดาวโหลด KUCut มาก่อนจาก kucut-1.2.7.tar.gz
  3. จากนั้นก็แตกไฟล์ zip ที่ดาวโหลดมาแล้วออกมา ในกรณีนี้ผมเก็บไว้ใน Desktop
  4. เรียกใช้งานโปรแกรม command prompt
  5. ใช้คำสั่ง cd เปลี่ยน directory ไปเป็น directory ของ KUCut
    kucut_screen1
  6. ติดตั้ง KUCut ด้วยคำสั่ง
    C:\Python26\python.exe setup.py install
    
  7. ลองสร้างไฟล์ test1.txt เขียนภาษาไทยไว้เพื่อทดสอบ (ใช้ character set TIS-620)
    ผมเขียนสิ่งนี้ลงไป:

    ทดลอง โปรแกรมตัดคำ
    
  8. สั่งตัดคำโดยใช้คำสั่ง
    C:\Python26\python.exe C:\Python26\Scripts\kucut --line="_" test1.txt
    
  9. ก็จะได้ไฟล์ test1.txt.cut ออกมา เปิดดูข้างในก็ควรจะเป็นแบบนี้
    ทดลอง _ โปรแกรม ตัด คำ 
    

เป็นอันเรียบร้อย วิธีใช้จาก Python เดี๋ยวผมจะเขียนอีกทีครับ (ถ้าผมทำได้)

พฤศจิกายน 15, 2009

เรียนนักพัฒนาเว็บ ผมขอความกรุณาให้ใช้แฟลชแต่น้อย

Filed under: Light IT — ป้ายกำกับ:, , , , , — वीर @ 11:27 am

เรียนนักพัฒนาเว็บ ผมขอความกรุณาให้ใช้แฟลชแต่น้อย ปัจจุบันนี้ผมใช้งานระบบปฎิบัติการ GNU/Linux ที่ Adobe ก็ผลิตแฟลช player ให้มาเหมือนกัน แต่ว่าใช้งานภาษาไทยได้ไม่ค่อยสมบูรณ์ ดังนั้นการใช้แฟลชสำหรับเปิดวิดีโอจึงไม่เป็นปัญหา เพราะไม่ต้องแสดงข้อความภาษาไทย แต่ว่าการใช้แฟลชแสดงข่าวสาร หรือชื่อรายการที่เป็นตัวหนังสือ ก็มักจะแสดงผลไม่ได้บนแฟลชที่ใช้กับ GNU/Linux

ถึงแม้ว่าผู้ใช้ GNU/Linux จะเป็นคนส่วนน้อย แต่ก็อยากจะขอความเห็นใจจากท่านนักพัฒนาเว็บบ้าง

update: ตอนนี้เริ่มมีความหวังว่าเฟลชจะใช้ภาษาไทยได้ http://www.blognone.com/node/13944 ^_^

เรื่องที่เก่ากว่า

Theme: Shocking Blue Green. บลอกที่ WordPress.com .

Follow

Get every new post delivered to your Inbox.

Join 632 other followers