Python's lexical diversity analysis of Twitter tweet elements (Word, screen Name, Hash Tag)

Source: Internet
Author: User

CODE:

#!/usr/bin/python #-*-Coding:utf-8-*-"Created on 2014-7-3@author:guaguastd@name:tweet_lexical_diversity.py" ' I F __name__ = = ' __main__ ': # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 from Login im Port Twitter_login # Get the twitter access API Twitter_api = Twitter_login () # import tweet from Tweet im Port extract_tweet_entities # import Search from search import search_for_tweet # import Lexical_diversit  Y from lexical_diversity import lexical_diversity,average_words while 1:query = Raw_input (' \ninput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ' If query = = ' exit ': print ' successfully            Exit! ' Break statuses = Search_for_tweet (twitter_api, query) status_texts,screen_names,hashtags,words = Ext Ract_tweet_entities (statuses) for tokens in (words, screen_names, hashtags): print ' \rlexical D IversiTy of%s: '% token print lexical_diversity (token) for status in (Status_texts,): print ' \rav Erage Words of%s: '% status print average_words (status)

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYouLength of statuses 30Le xical diversity of [u ' RT ', U ' @xmlovex: ', U ' #MentionSomeoneImportantForYou ', U ' @purpledrauhl_23 ', U ' rt ', U ' @KillahPimpp : ', U ' #MentionSomeoneImportantForYou ', U ' @MissRosaa_ ', U ' #MentionSomeoneImportantForYou ', U ' @justinbieber ', U ' "@ KILLAHPIMPP: ', U ' #MentionSomeoneImportantForYou ', U ' @_k_l_o_ "', U ' RT ', U ' @KillahPimpp: ', U ' # Mentionsomeoneimportantforyou ', U ' @_k_l_o_ ', U ' \[email protected]: ', U ' "@KillahPimpp: ', U ' # Mentionsomeoneimportantforyou ', U ' @0hdearpriscii "', U ' aww ', U ' ily\u0001f618\u0001f46f\u201dily2\u2764\ufe0f ', U ' RT ', U ' @KillahPimpp: ', U ' #MentionSomeoneImportantForYou ', U ' @0hdearpriscii ', U ' "@KillahPimpp: ', U ' # Mentionsomeoneimportantforyou ', U ' @0hdearpriscii "', U ' aww ', U ' ily\u0001f618\u0001f46f ', U ' # Mentionsomeoneimportantforyou ', u ' @ ', u ' my ', U ' brotherrrr ', U ' http://t.co/LprqvaLvyu ', U ' RT ', U ' @KillahPimpp: ', U ' # Mentionsomeoneimportantforyou ', U ' @BeyonceTaPia ', U ' \u0001f498 ', U ' RT ', U ' @thuggie_salma: ', U ' "@KillahPimpp: ', U ' #MentionSomeoneImportantForYou ', U ' @thuggie_ Salma "', U ' baeee ', U ' \u0001f618\u0001f60f\u0001f62d ', U ' #MentionSomeoneImportantForYou ', U ' @BeyonceTapia ', U ' \ u0001f498 ', U ' "@KillahPimpp: ', U ' #MentionSomeoneImportantForYou ', U ' @thuggie_salma" ', U ' baeee ', U ' \u0001f618\ u0001f60f\u0001f62d ', U ' rt ', U ' @KillahPimpp: ', U ' #MentionSomeoneImportantForYou ', U ' @thuggie_salma ', U ' rt ', U ' @ KILLAHPIMPP: ', U ' #MentionSomeoneImportantForYou ', U ' @NotNormal_Javi ', U ' #MentionSomeoneImportantForYou ', U ' @ Notnormal_javi ', U ' #MentionSomeoneImportantForYou ', U ' @thuggie_salma ', U ' RT ', U ' @KillahPimpp: ', U ' # Mentionsomeoneimportantforyou ', U ' @EbbsContreras ', U ' RT ', U ' @sashaalexxa_: ', U ' #MentionSomeoneImportantForYou ', U ' @ ', U ' #MentionSomeoneImportantForYou ', U ' @EbbsContreras ', U ' RT ', U ' @NotNormal_Javi: ', U ' # Mentionsomeoneimportantforyou ', U ' cheeseburgers ', U ' \u0001f354\u0001f354 ', U ' #MentionSomeoneImportantForYou ', U ' @ Taetae2beast ', U ' #MentionSomeoneImPortantforyou ', u ' @ ', U ' #MentionSomeoneImportantForYou ', U ' @Brendaaa23 ', U ' #MentionSomeoneImportantForYou ', U ' cheeseburgers ', U ' \u0001f354\u0001f354 ', U ' #MentionSomeoneImportantForYou ', U ' @_k_l_o_ ', U ' # Mentionsomeoneimportantforyou ', U ' @MissRosaa_ ', U ' #MentionSomeoneImportantForYou ', U ' @0hdearpriscii ', U ' @ Loveasharie ', U ' @DJZeeti ', U ' speechless ', U ' Beauty ', U ' and ', U ' pretty ', U ' smile ', U '. #WomanCrushWednesday ', U ' # Mentionsomeoneimportantforyou ', U ' #TeamSharie ', U ' @louiswonderwall ', U ' my ', U ' babeeeee\u0001f60d\u0001f60d\ u0001f60d\u0001f60d\u0001f60d ', U ' #MentionSomeoneImportantForYou ']: 0.407079646018Lexical diversity of [u ' Xmlovex ', U ' killahpimpp ', U ' Missrosaa_ ', U ' justinbieber ', U ' killahpimpp ', U ' _k_l_o_ ', U ' killahpimpp ', U ' _k_l_o_ ', U ' 0hDearPriscii ', U ' killahpimpp ', U ' 0hDearPriscii ', U ' killahpimpp ', U ' 0hDearPriscii ', U ' killahpimpp ', U ' 0hDearPriscii ', U ' killahpimpp ', U ' Beyoncetapia ', U ' Thuggie_salma ', U ' killahpimpp ', U ' Thuggie_salma ', U ' Beyoncetapia ', U ' killahpimpp ', U ' Thuggie_salma ', U ' killahpimpp ', U ' Thuggie_salma ', U ' killahpimpp ', U ' Notnormal_javi ', U ' Notnormal_javi ', U ' Thuggie_salma ', U ' killahpimpp ', U ' Ebbscontreras ', U ' Sashaalexxa_ ', U ' Ebbscontreras ', U ' Notnormal_javi ', U ' taetae2beast ', U ' Brendaaa23 ', U ' _k_l_o_ ', U ' Missrosaa_ ', U ' 0hDearPriscii ', U ' Loveasharie ', U ' Djzeeti ', U ' louiswonderwall ']: 0.380952380952Lexical diversity of [u ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' mentionsomeoneimportantforyou ', U ' womancrushwednesday ', U ' mentionsomeoneimportantforyou ', U ' Teamsharie ', U ' mentionsomeoneimportantforyou ']: 0.09375Average words of [u ' RT @xmlovex: #MentionSomeoneImportantForYou @purpledrauhl_23 ', U ' RT @KillahPimpp: # Mentionsomeoneimportantforyou @MissRosaa_ ', u ' #MentionSomeoneImportantForYou @justinbieber ', U ' "@KillahPimpp: # Mentionsomeoneimportantforyou @_k_l_o_ "', U ' RT @KillahPimpp: #MentionSomeoneImportantForYou @_k_l_o_ ', U ' \[email  protected]: "@KillahPimpp: #MentionSomeoneImportantForYou @0hdearpriscii" Aww ily\u0001f618\u0001f46f\ u201dily2\u2764\ufe0f ', U ' RT @KillahPimpp: #MentionSomeoneImportantForYou @0hdearpriscii ', U ' "@KillahPimpp: # Mentionsomeoneimportantforyou @0hDearpriscii "Aww ily\u0001f618\u0001f46f ', U ' #MentionSomeoneImportantForYou @ my brotherrrr http://t.co/LprqvaLvyu ', U ' RT @KillahPimpp: #MentionSomeoneImportantForYou @BeyonceTapia \u0001f498 ', U ' rt @thuggie_salma: "@KillahPimpp: # Mentionsomeoneimportantforyou @thuggie_salma "Baeee \u0001f618\u0001f60f\u0001f62d ', U ' # Mentionsomeoneimportantforyou @BeyonceTapia \u0001f498 ', U ' "@KillahPimpp: #MentionSomeoneImportantForYou @thuggie_ Salma "Baeee \u0001f618\u0001f60f\u0001f62d ', U ' rt @KillahPimpp: #MentionSomeoneImportantForYou @thuggie_salma ', U ' RT @KillahPimpp: #MentionSomeoneImportantForYou @NotNormal_Javi ', u ' #MentionSomeoneImportantForYou @NotNormal_Javi ', U ' #MentionSomeoneImportantForYou @thuggie_salma ', U ' RT @KillahPimpp: #MentionSomeoneImportantForYou @EbbsContreras ' , u ' RT @sashaalexxa_: #MentionSomeoneImportantForYou @ ', u ' #MentionSomeoneImportantForYou @EbbsContreras ', U ' RT @ Notnormal_javi: #MentionSomeoneImportantForYou cheeseburgers \u0001f354\u0001f354 ', U ' #MentionSomeoneImportAntforyou @TaeTae2Beast ', U ' #MentionSomeoneImportantForYou @ ', u ' #MentionSomeoneImportantForYou @Brendaaa23 ', U ' # Mentionsomeoneimportantforyou cheeseburgers \u0001f354\u0001f354 ', u ' #MentionSomeoneImportantForYou @_k_l_o_ ', U ' # Mentionsomeoneimportantforyou @MissRosaa_ ', u ' #MentionSomeoneImportantForYou @0hdearpriscii ', U ' @LoveASharie @ Djzeeti speechless beauty and pretty smile. #WomanCrushWednesday #MentionSomeoneImportantForYou #TeamSharie ', U ' @louisw Onderwall my babeeeee\u0001f60d\u0001f60d\u0001f60d\u0001f60d\u0001f60d #MentionSomeoneImportantForYou ']:  3.76666666667Input the query (eg #MentionSomeoneImportantForYou, exit to quit):

Python's lexical diversity analysis of Twitter tweet elements (Word, screen Name, Hash Tag)

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.