Text analysis--affective analysis--text analysis

Source: Internet
Author: User
Tags processing text nltk
Text Analysis-Affective analysis

Natural language Processing (NLP)

• Translating natural Language (text) into a form that is easier to understand by computer programs
• Preprocessing-derived string-> to quantify simple emotional analysis

Construct an emotional dictionary by oneself construct a dictionary, as

Like-> 1, good-> 2, Bad->-1, terrible-2 based on keyword matching

Problem:

Encounter new words, special words, etc., poor extensibility using machine learning model, nltk.classify

Import NLTK from Nltk.stem import Wordnetlemmatizer to Nltk.corpus import stopwords from nltk.classify import Naivebayes Classifier Text1 = ' I like the movie so much! ' Text2 = ' It's a good movie. ' Text3 = ' This is a great one. ' Text4 = ' Th

At are a really bad movie. ' Text5 = ' that is a terrible movie. ' def proc_text (text): "" Pre-processing text "" "# participle raw_words = nltk.word_tokenize (text) # Forms normalized WOR

    Dnet_lematizer = Wordnetlemmatizer () words = [Wordnet_lematizer.lemmatize (Raw_word) for Raw_word in Raw_words] # Remove Deactivate word filtered_words = [word for word in words if Word not in stopwords.words (' Chinese ')] # True indicates that the word is in the text, in order to make
              Use the classifier in NLTK to return {word:true to Word in Filtered_words} # to construct a training sample train_data = [[Proc_text (Text1), 1], [Proc_text (Text2), 1], [Proc_text (Text3), 1], [Proc_text (TEXT4), 0], [proc_text (TEXT5), 0]] print (train_data) "" [[{' I]: True, ' much ': true, ' movie ': true, ' LiKe ': True, '! ': true}, 1], [{' Good ': true, '. ': true, ' that ': true, ' movie ': true}, 1], [{' Here ': true, ' great ': true, ' on E ': true, '. ': true}, 1], [{' Really ': true, '. ': true, ' that ': true, ' movie ': true, ' bad ': true}, 0], [{' This ': true, ' ter  Rible ': true, '. ': true, ' movie ': True}, 0]] "" "# Training Model Nb_model = Naivebayesclassifier.train (train_data) # test Model TEXT6 = ' That's a bad one. ' Print (Nb_model.classify (Proc_text (TEXT5)) #0










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.