-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentimentClassifier.h
More file actions
112 lines (89 loc) · 2.92 KB
/
Copy pathSentimentClassifier.h
File metadata and controls
112 lines (89 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* SentimentClassifier.h
*
* Created on: Dec 25, 2009
* Author: Christopher L. Tang
*/
#ifndef SENTIMENTCLASSIFIER_H_
#define SENTIMENTCLASSIFIER_H_
#include <string>
#include <iostream>
#include <vector>
#include <map>
//#include <boost/unordered_map.hpp>
using namespace std;
struct CDecision
// data structure for storing classification decisions
{
CDecision();
int decision;
// classification decision; 1: positive; 0: neutral; -1: negative
int raw_score;
// decision score; open range
int confidence;
// decision confidence; normalized score per feature [ -1000, 1000 ]
string content;
// normalized content produced by Classifier
vector<string> features;
// features contributing classification decision
};
struct FeatureScores
// data structure for storing feature scores
{
FeatureScores();
int score;
// composite feature score
int relevance;
// relevance score of feature
};
//typedef boost::unordered_map<string,int> StopwordsTable;
//typedef boost::unordered_map<string,FeatureScores> FeaturesTable;
typedef map<string,int> StopwordsTable;
typedef map<string,int> FeaturesCount;
typedef map<string,FeatureScores> FeaturesTable;
class SentimentClassifier {
public:
SentimentClassifier ( const string& feature_file,
const string& stopword_file );
bool Inited () const;
bool Classify ( const string& input, CDecision& cd );
bool Classify ( const string& title, const string& body,
const string& url, CDecision& cd );
void setUseQuestionMarks ( bool qm );
void setRelevanceCutoff ( float rc );
void setNeutralCutoff ( float nc );
void setMaxFeatureSize ( unsigned int mfs );
void setDebugLevel ( unsigned int dl );
bool getUseQuestionMarks () const;
float getRelevanceCutoff () const;
float getNeutralCutoff ( ) const;
unsigned int getMaxFeatureSize () const;
unsigned int getDebugLevel () const;
string getErrorMsg () const;
private:
bool UseQuestionMarks;
float RelevanceCutoff;
float NeutralCutoff;
unsigned int MaxFeatureSize;
unsigned int DebugLevel;
string error_msg;
int TitleWeight;
int BodyWeight;
int URLWeight;
bool isInited;
bool readFeatures ( const string& features_file );
bool readStopwords ( const string& stopwords_file );
bool parseFeature ( string& phrase, string& entry );
bool normalizeContent ( const string& content, string& ncontent );
bool normalizeUrl ( const string& content, string& ncontent );
bool classifyGreedy ( int weight, string& ncontent, CDecision& cd );
bool classifySentences ( int weight, const string& ucontent,
CDecision& cd );
bool classifyQuestionMarks ( int weight, const string& ucontent,
CDecision& cd );
FeaturesTable features;
StopwordsTable stopwords;
// This is an arbitrary scaling unit. Revisit later.
static const float FeatureScoreScale = 288.f; // = 200/ln(2)
};
#endif /* SENTIMENTCLASSIFIER_H_ */