Algorithm to determine how positive or negative a statement/text is

前端 未结 14 1425
北荒
北荒 2020-12-07 07:21

I need an algorithm to determine if a sentence, paragraph or article is negative or positive in tone... or better yet, how negative or positive.

For instance:

<
14条回答
  •  执笔经年
    2020-12-07 08:18

       use Algorithm::NaiveBayes;
         my $nb = Algorithm::NaiveBayes->new;
    
         $nb->add_instance
           (attributes => {foo => 1, bar => 1, baz => 3},
            label => 'sports');
    
         $nb->add_instance
           (attributes => {foo => 2, blurp => 1},
            label => ['sports', 'finance']);
    
         ... repeat for several more instances, then:
         $nb->train;
    
         # Find results for unseen instances
         my $result = $nb->predict
           (attributes => {bar => 3, blurp => 2});
    

提交回复
热议问题