A case analysis of Python smallseg participle usage

Source: Internet
Author: User

This example describes the Python smallseg participle usage. Share to everyone for your reference. The specific analysis is as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The #encoding =utf-8 #import Psyco #psyco. Full () Wor ds = [X.rstrip () for X in open ("Main.dic", mode= ' R ', encoding= ' Utf-8 ')] from smallseg import SEG SEG = SEG () print (' Load di CT ... ') Seg.set (words) print ("Dict is OK.") def cuttest (text): Wlist = seg.cut (text) wlist.reverse () tmp = "". Join (wlist) print (t MP) Print ("================================") if __name__== "__main__": Cuttest ("This is a pitch-black night." My name is Monkey king, I love Beijing, I love Python and C + +. Cuttest ("I don't like Japanese kimono.") Cuttest ("The Monkey returns to Earth.") "Cuttest (" The Letter of the Virgin Officer every month after the subordinate departments must personally account for 24 switches and other technical devices installation work ") Cuttest (" I need low-cost Rental ") cuttest (" Yonghe Clothing Accessories Co., Ltd. ") Cuttest (" I love Beijing Tian an door ") Cuttest ("abc") Cuttest ("Hidden Markov") Cuttest ("Monkey is a good website") cuttest ("Microsoft" is the word "microcomputer" and "SOFTware (software)" Two parts ") cuttest (" Grass mud horse and bullying horse is the popular term this year ") Cuttest (" The Itochu Store ") cuttest (" The Institute of Computing Technology, Chinese Academy of Sciences ") Cuttest (" Romeo and Juliet ") Cuttest (" I bought props and costumes ")

Smallseg participle, on the python3.3 run slightly some problems. The PY code xrange has changed its name to range in 3.*. In addition, there is no decode function in the 3.*.

Modified the two places above, the code is portable. The effect is also OK.

I hope this article will help you with your Python programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.