Classify type of tweet based on regex in python -


Extend this question:

I classify each as one of my datasets Attach the twitter type to the following, and for each record in the dataset. Currently, when I run my script shown below, returns me [none] , so obviously I'm missing something here

The current format :

  ['CREATED_AT'] ['text']  

Desired format:

  ['CREATED_AT'] ['text'] ['tweets_type']  

tweet classification:

( 1) Tweet -> There is a "RT @ many names" in the Tweet text column

(2) Meditation -> In a "tweet post" someone G "but no" RT @ any user name "

(3) Tweet -> There is no" RT No "name in the column and no" @Username "

code:

  import json import time of import reload loading streaming streaming json data dcit def import_tweets (parameter1): data = [] row Except for (parameter1): Try: Pass data for i: '[CREATED_AT'] = 'except for the. Append (json.loads (line)): time.strftime ('% y- % M-% d% H:% M:% s', time .stratim (I ['created'], '% A% B% D% H:% M:% S + 0000% Y') returns Remove the data # timestamp and a list def in tweeter Tech T def extract_tweets (parameter2): tweets = [] in Parameter 2: tweets.append ([i ['CREATED_AT'], i ['text']] Return Tweets # RETWEET / Categorize each Tweet as / Tweet_type.append ([i, tweet_type: (parameter3): tweet_type = [] In parameter 3: match = re.match (r'RT \ s @ .... + ', I [1]): 'retouse'] and: match = ri matches (r '@ .... +', i [1]) if match: tweeter_type .appe Nd ([i, 'answer']) and: match = re match (r '.... + +', i [1]) match: tweet-type.append ([i, 'mention']) second Tweet-type.append ([i, 'tweet']) tweet_type data = import_tweets ('Tweets.json') tweets = extract_tweets (data) tweet_type = tweet_type (tweets) # Make sure that the text of the tweet was categorized , Print sample tweet_type [: 5]  

There are two problems:

< Ol>
  • tweet_type.append (i.append (['tweet'])) - list.append () calls do not return anything (Which means that they are inherently Do not even return). This is the main problem you are not joining any tweets.

  • return tweet_type is too much indented on the right - the loop exits the function when it first runs.


  • Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -