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.