Results 1 to 2 of 2

Thread: สร้างโปรแกรมพจนานุกรมส่วนตัวกันเะอะ !!

  1. #1
    Senior Member
    Join Date
    Sep 2003
    Location
    Thailand
    Posts
    136


    สร้างโปรแกรมพจนานุกรมส่วนตัวกันเะอะ !!

    ในวันนี้จะพาท่านเขียนโปรแกรมพจนานุกรมมาใช้งานกัน !!
    ก่อนอื่นเพื่อน ๆ ต้องติดตั้งโปรแกรมต่อไปนี้คัรบ !!
    - python
    - Mysql
    - Python/Mysql-Interface
    - คัดลอกฐานข้อมูลไปไว้ในไดเร็คทอรี่ data ภายใต้ mysqldata ด้วยไฟล์ฐานข้อมูลต่อไปนี้ครับ http://www.citecclub.org/~nprotech/dev/dictionary.rar

    จากนั้นเริ่มเขียนฟังก์ชั่นกันครับ.. อ๋อ ฟังก์ชั่นนี้ค้นหาได้ทั้งคำในภาษาไทย และอังกฤษนะครับ..
    def dictionary():
    import MySQLdb
    conn = MySQLdb.connect('localhost','root','1234','dictionary')
    cursor =conn.cursor()
    while 1:
    cmd = raw_input(">> ")
    if cmd == 'exit':
    break
    else:
    thai = ['xa1', 'xa2', 'xa3', 'xa4', 'xa5', 'xa6', 'xa7', 'xa8', 'xa9', 'xaa', 'xab', 'xac', 'xad', 'xae', 'xaf', 'xb0', 'xb1', 'xb2', 'xb3', 'xb4', 'xb5', 'xb6', 'xb7', 'xb8', 'xb9', 'xba', 'xbb', 'xbc', 'xbd', 'xbe', 'xbf', 'xc0', 'xc1', 'xc2', 'xc3', 'xc4', 'xc5', 'xc6', 'xc7', 'xc8', 'xc9', 'xca', 'xcb', 'xcc', 'xcd', 'xce', 'xcf', 'xd0', 'xd1', 'xd2', 'xd3', 'xd4', 'xd5', 'xd6', 'xd7', 'xd8', 'xd9', 'xda', 'xe0', 'xe1', 'xe2', 'xe3', 'xe4', 'xe5', 'xe6', 'xe7', 'xe8', 'xe9', 'xea', 'xeb', 'xec', 'xed', 'xee']
    english = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    if cmd[0] in thai:
    sql = "select tsearch,tentry,tenglish,eentry from telex where (tsearch like '%s') or (tentry like '%s');"%(cmd,cmd)
    else:
    sql = "select esearch,eentry,ethai,tentry from etlex where (esearch like '%s') or (eentry like '%s');"%(cmd,cmd)
    cursor.execute(sql)
    rows = cursor.fetchall()
    for i in range(len(rows)):
    print '%s | %s | %s'%(rows[i][0],rows[i][2],rows[i][3])
    #print 'Found %s : Total %d !!'%(cmd,len(rows))
    cursor.close()
    conn.close()

    เมื่อเรียกใช้งานจะปรากฎเชลล์คอยรับคำสั่งดังนี้คัรบ :
    >> ani%
    ในตัวอย่างนี้ผมป้อนคำว่า ani% หมายถึงเริ่มต้นด้วยคำว่า anim ตามหลังเป็นคำว่าอะไรก็ได้ (อันนี้เป็นไวยากรณ์ของ sql) ครับ

    ผลลัพธ์ที่ได้จะปรากฎผลลัพธ์ดังนี้ครับ !!
    animadvert upon | | แสดงความคิดเห็นเกี่ยวกับ (อย่างวางท่า)
    animadvert on | | แสดงความคิดเห็นเกี่ยวกับ (อย่างวางท่า)
    anisette | | เหล้าเจือรสของเมล็ดพืชชนิดหนึ่ง (anise)
    aniseed | | เมล็ดพืชชนิดหนึ่งใช้เป็นตัวแต่งกลิ่นแต่งรส
    anion | | ไอออนที่มีประจุลบ
    anise | | เมล็ดพืชชนิดหนึ่งใช้เป็นตัวแต่งกลิ่นแต่งรส
    animus | | ความตั้งใจ
    animism | | ความเชื่อว่ามีวิญญาณในธรรมชาติและจักรวาล
    animosity | | ความเกลียดชัง
    animator | | ผู้สร้างภาพที่เคลื่อนไหวได้
    animato | | มีชีวิตชีวา (ดนตรี)
    animator | | บุคคลหรือสิ่งที่มีชีวิตชีวา
    animato | | มีชีวิตชีวา (ดนตรี)
    animation | | ภาพการ์ตูนที่เคลื่อนไหวได้
    animation | | ความมีชีวิต
    animation | | ความมีชีวิตชีวา
    animated | | ที่เหมือนมีชีวิต
    animation | การสร้างภาพยนตร์ | การสร้างภาพเคลื่อนไหวได้
    animate | | ที่มีชีวิตชีวา
    animate | | ทำให้มีชีวิตชีวา
    animate | | ทำให้มีชีวิต
    animate | | ทำให้ดุจมีชีวิต
    animate | สร้างแรงบันดาลใจ | ดลใจ
    animate | ร่าเริง | ซึ่งมีชีวิตชีวา
    animality | | ความเป็นสัตว์
    animate | | ซึ่งมีชีวิต
    animalism | | ธรรมชาติของสัตว์
    animal-free | | ซึ่งไม่ใช้หรือไม่ได้บรรจุผลิตภัณฑ์ที่มีส่วนประกอบจากสัตว์
    animalcule | | สัตว์ที่มีขนาดเล็กมาก (จนมองด้วยตาเปล่าไม่เห็น)
    animal rights | | สิทธิของสัตว์ที่จะมีชีวิตอยู่อย่างอิสระปราศจากการหารประโยชน์ของมนุษย์หรือถูกมนุษย์ทารุณหรือกักขัง
    animal kingdom | | อาณาจักรสัตว์
    animal liberation | | การปลดปล่อยสัตว์จากการที่ถูกมนุษย์แสวงหาประโยชน์จากพวกมัน
    animal husbandry | | การเลี้ยงสัตว์
    animal | | สัตว์
    animal heat | | ความร้อนที่เกิดขึ้นในกระบวนการเผาผลาญอาหารในร่างกายสัตว์
    animal | คนที่โหดร้ายทารุณคล้ายสัตว์ | คนที่หยาบคาย
    animal | ซึ่งเกิดจากสัตว์ | เกี่ยวกับสัตว์
    animal | | เกี่ยวกับเนื้อหนังมังสา
    animadvert | | วิจารณ์
    animadversion | | การวิพากษ์วิจารณ์
    anility | | ความแก่
    anima | ชีวิต | จิตวิญญาณ
    anile | | เหมือนหญิงแก่

    หรือจะใช้ภาษาไทยก็ได้นะครับ เช่น
    >>> dictionary()
    >> เรียน%
    เรียนจบ | | graduate
    เรียนต่อ | continue to study | further study
    เรียนถาม | inquire; question | ask
    เรียนหนังสือ | learn; be in school; be educated | study
    เรียนรู้ | learn; read up; mug up | study
    เรียน | report; address | inform
    เรียน | | salutation of a letter as a conventional greeting
    เรียน | study | learn
    เรียนเชิญ | | invite
    เรียนพิเศษ | | take extra tutorial class

    เอาล่ะครับ ตัวอย่างนี้คงพอทำให้เพื่อน ๆ สนุกสนานกับพจนานุกรมเวอร์ชั่นด้วยตนเอง นอกจากนั้น เพื่อน ๆ ท่านใดจะนำไปใช้บริการเกี่ยวกับ Web-CGI หรือ พอร์ตไปใช้กับ Unix ก็สามารถทำได้เช่นเดียวกันครับ สำหรับวันนี้พบกับผมและการเรียนรู้สิ่งใหม่ ๆ สไตล์ไพธอนเพียงเท่านี้ครับ พบกันใหม่โอกาสหน้าครับ สวัสดี !!

  2. #2
    Anonymous
    Guest


    Re: สร้างโปรแกรมพจนานุกรมส่วนตัวกันเะอะ !!

    เยี่ยมครับ ขอบคุณครับที่แบ่งปัน

    ผมยังรออ่านหนังสืออยู่นะครับ ไม่รู้ว่าเป็นยังไงบ้าง

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •