27 เมษายน 2010ตัดคำภาษาไทยด้วย Groovy (ไม่ใช้ grails)

เหล้าเก่าเอามาเล่าใหม่ขวดใหม่

ผมโมดิฟาย LexTo ของ Sansarn overload method addDict  โดยเพิ่ม addDict (string )

เพราะว่าก่อนหน้านี้มีแต่ addDict (File ) มันมีปัญหาเรื่อง Encoding ของ Dictionary กับ Input String ไม่ตรงกัน  ตัดไม่ได้อีก เลยต้องโมดิฟายนิดหน่อย โหลดได้ที่ http://github.com/NAzT/LT (เป็น Netbeans Project ) หลังจากนั้นทำเป็น .jar (กด Build ได้เลย)

def Tokenizer = new LongLexTo(“Self”)  // ใช้ constructor เป็น LongLexTo(String ) เพื่อไม่ให้มันไปโหลด Dict

def input = “สวัสดีครับผม”  //  input string ที่ต้องการตัด

Tokenizer.addDict(“สวัสดี”); // เพิ่มคำลงไปใน(จาก) Dictionary

Tokenizer.addDict(“ครับ”);  // เพิ่มคำลงไปใน(จาก) Dictionary

Tokenizer.wordInstance(input);  // จัดการตัดคำ

def myIndexList=Tokenizer.getIndexList();  // ขอตำแหน่งของคำที่ตัดได้

// เริ่มการแสดงผลคำที่ตัดคั่นด้วย |
def longlexnews=”"
def indexer=0
myIndexList.eachWithIndex{ val, idx ->
longlexnews+= input[indexer..val-1] + “|”
indexer=val
}
println longlexnews



Related Blogs


    Tags: , , ,
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...

    Leave a Reply

    Comment ไม่ได้กดที่นี่

    Get Adobe Flash playerPlugin by wpburn.com wordpress themes