Python Chinese word segmentation tool-Summary of the use of jieba Word Segmentation

Source: Internet
Author: User

The installation and basic usage of the jieba word splitting tool have been described in yesterday's blog. The content to be said today is closer to the actual application-reading Chinese information from the text, and using the jieba word segmentation tool for Word Segmentation and part-of-speech tagging.

ExampleCodeAs follows:

# Coding = utf-8import jiebaimport jieba. posseg as container gimport timet1 = time. time () F = open ("t_with_splitter.txt", "R") # Read text string = f. read (). decode ("UTF-8") Words = coding G. cut (string) # perform word segmentation result = "" # The variable for recording the final result for W in words: Result + = STR (W. word) + "/" + STR (W. flag) # add part-of-speech annotation F = open ("t_with_pos_tag.txt", "W") # Save the result to another document F. write (result) F. close () T2 = time. time () print ("Word Segmentation and part of speech tagging completed, time:" + STR (t2-t1) + "seconds. ") # Feedback results

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.