Class: Applied::Sentiment
- Inherits:
-
Object
- Object
- Applied::Sentiment
- Defined in:
- lib/applied/sentiment.rb
Constant Summary collapse
- ENDPOINT =
"/api/sentiment_api/"
- PERMITTED_OPTIONS =
[:return_original, :classifier]
- CLASSIFIERS =
["default", "subjective"]
- AVAILABLE_LANGUAGES =
["eng", "nld", "deu", "fra", "spa", "ita", "rus"]
- DATA_MUST_BE_ARRAY =
"Data must be and Array"
- TEXT_MISSING =
"Missing text parameter, it is mandatory"
- ID_MISSING =
"Missing ID parameter, it is mandatory"
- LANGUAGE_MISSING =
"Missing language parameter, it is mandatory"
- BAD_RETURN =
"Bad value for return_original parameter. Allowed values are: true, false"
- BAD_CLASSIFIER =
"Bad value for classifier parameter. Allowed values are: 'default', 'subjective'"
Instance Attribute Summary collapse
-
#classifier ⇒ Object
Returns the value of attribute classifier.
-
#return_original ⇒ Object
Returns the value of attribute return_original.
Instance Method Summary collapse
Instance Attribute Details
#classifier ⇒ Object
Returns the value of attribute classifier.
21 22 23 |
# File 'lib/applied/sentiment.rb', line 21 def classifier @classifier end |
#return_original ⇒ Object
Returns the value of attribute return_original.
21 22 23 |
# File 'lib/applied/sentiment.rb', line 21 def return_original @return_original end |
Instance Method Details
#analyze(data, options = {}) ⇒ Object
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 |
# File 'lib/applied/sentiment.rb', line 23 def analyze(data, = {}) # checks on data raise Applied::BadData.new(DATA_MUST_BE_ARRAY) unless data.instance_of? Array data.each do |d| raise Applied::BadData.new(TEXT_MISSING) if d[:text].nil? or d[:text].empty? raise Applied::BadData.new(ID_MISSING) unless [Fixnum, String].include? d[:id].class raise Applied::BadData.new(LANGUAGE_MISSING) if d[:language_iso].nil? or d[:language_iso].empty? or not AVAILABLE_LANGUAGES.include? d[:language_iso] end # checks on options unless [:return_original].nil? raise Applied::BadOptions.new(BAD_RETURN) unless [true, false].include? [:return_original] else [:return_original] = false end unless [:classifier].nil? raise Applied::BadOptions.new(BAD_CLASSIFIER) unless CLASSIFIERS.include? [:classifier] else [:classifier] = "default" end # options cleanup .delete_if {|o| not PERMITTED_OPTIONS.include? o} call(ENDPOINT, data, ) end |