Skip to content

Commit 5d63df8

Browse files
committed
Added JSONPath
1 parent a03126f commit 5d63df8

File tree

2 files changed

+1047
-13
lines changed

2 files changed

+1047
-13
lines changed

app/models/agents/sentiment_value_agent.rb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@
33
module Agents
44
class SentimentValueAgent < Agent
55
description <<-MD
6-
The SentimentValueAgent generates `good-bad` (psychological valence or happiness index),`active-passive` (arousal), and `strong-weak` (dominance) score. It will output a value between 1 and 9. Make sure the content this agent is running on have sufficient length.
7-
Add more stuff
6+
The SentimentValueAgent generates `good-bad` (psychological valence or happiness index), `active-passive` (arousal), and `strong-weak` (dominance) score. It will output a value between 1 and 9. Make sure the content this agent is analyzing have sufficient length to get respectable results.
7+
8+
Provide a JSONPath in `content` field where content is residing and set `expected_receive_period_in_days` to the maximum number of days you would allow to be passed between events being received by this agent.
89
MD
910

1011
event_description <<-MD
1112
Events look like:
1213
{
13-
:content => "The quick brown fox jumps over the lazy dog."
14-
:valence => 6.199999
15-
:arousal => 5.432212
16-
:dominance => 4.346312
14+
:content => "The quick brown fox jumps over the lazy dog.",
15+
:valence => 6.196666666666666,
16+
:arousal => 4.993333333333333,
17+
:dominance => 5.63
1718
}
1819
MD
1920

2021
default_schedule "every_1h"
2122

2223
def default_options
2324
{
24-
25+
:content => "$.message.text",
26+
:expected_receive_period_in_days => 1
2527
}
2628
end
2729

2830
def working?
29-
true
31+
last_receive_at && last_receive_at > options[:expected_receive_period_in_days].to_i.days.ago
3032
end
3133

3234
def receive(incoming_events)
@@ -37,12 +39,13 @@ def receive(incoming_events)
3739
end
3840

3941
def validate_options
42+
errors.add(:base, "content and expected_receive_period_in_days must be present") unless options[:content].present? && options[:expected_receive_period_in_days].present?
4043
end
4144

4245
def sentiment_hash
4346
anew = {}
44-
CSV.foreach Rails.root.join('app/assets/anew.csv') do |row|
45-
anew[row[0]] = [row[2],row[4],row[6]].map {|val| val.to_f}
47+
CSV.foreach Rails.root.join('data/anew.csv') do |row|
48+
anew[row[0]] = row.values_at(2,4,6).map {|val| val.to_f}
4649
end
4750
anew
4851
end
@@ -68,9 +71,10 @@ def check
6871
if self.memory[:queue] && self.memory[:queue].length > 0
6972
anew = sentiment_hash
7073
self.memory[:queue].each do |text|
71-
if text[:message]
72-
sent_values = sentiment_values anew, text[:message]
73-
create_event :payload => {:content => text[:message], :valence => sent_values[0], :arousal => sent_values[1], :dominance => sent_values[2]}
74+
if Utils.values_at(text, options[:content])[0]
75+
content = Utils.values_at(text, options[:content])[0]
76+
sent_values = sentiment_values anew, content
77+
create_event :payload => {:content => content, :valence => sent_values[0], :arousal => sent_values[1], :dominance => sent_values[2]}
7478
end
7579
end
7680
self.memory[:queue] = []

0 commit comments

Comments
 (0)