opener-scorer 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opener/scorer/output_processor.rb +22 -16
- data/lib/opener/scorer/version.rb +1 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dcd08283a4bd6b1d6e99e8925bb738820f529cf
|
4
|
+
data.tar.gz: 4212ffb0e1a53ff57452745d858f304b8d218f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 466ce5a7591c03b4d3a15e2c06992ff8df5b07925485aab7797864fd1b0a3e116cdd0c2438bb5ce44bdeb051239adee5a831f504050b0eb8ba88537d129abc53
|
7
|
+
data.tar.gz: 9c5cf6c073ccebe565c0b379bcc53a8cfb62b60a8b61a379861abd580fbb95646d36232c477067012b17f8685c6044f2ea5ef70b3c94d310f0a6dd9d68f1fa07
|
@@ -85,32 +85,33 @@ module Opener
|
|
85
85
|
return lemmas_hash
|
86
86
|
end
|
87
87
|
|
88
|
-
##
|
89
|
-
# Create a hash with all lemma ids that have a polarity.
|
90
|
-
#
|
91
88
|
# @param [Nokogiri::XML::Document] document
|
92
89
|
# @return [Hash]
|
93
90
|
#
|
94
91
|
def build_polarities_hash(document)
|
95
|
-
polarities_hash =
|
92
|
+
polarities_hash = {}
|
96
93
|
opinions = document.at('opinions')
|
97
94
|
|
98
95
|
return polarities_hash unless opinions
|
99
96
|
|
100
97
|
opinions.css('opinion').each do |opinion|
|
101
98
|
polarity = opinion.at('opinion_expression').attr('polarity').to_sym
|
99
|
+
strength = opinion.at('opinion_expression').attr('strength').to_i.abs
|
102
100
|
op_target = opinion.at('opinion_target')
|
103
101
|
op_expr = opinion.at('opinion_expression')
|
104
102
|
|
105
103
|
if op_target
|
106
104
|
op_target.css('span target').each do |target|
|
107
|
-
|
105
|
+
require 'pry'
|
106
|
+
polarities_hash[target.attr('id')] ||= {} rescue binding.pry
|
107
|
+
polarities_hash[target.attr('id')][polarity] = strength
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
if op_expr
|
112
|
-
op_expr.css('span target').each do |
|
113
|
-
polarities_hash[
|
112
|
+
op_expr.css('span target').each do |expression|
|
113
|
+
polarities_hash[expression.attr('id')] ||= {}
|
114
|
+
polarities_hash[expression.attr('id')][polarity] = strength
|
114
115
|
end
|
115
116
|
end
|
116
117
|
end
|
@@ -125,17 +126,20 @@ module Opener
|
|
125
126
|
# @return [Float]
|
126
127
|
#
|
127
128
|
def get_overall_score(document)
|
128
|
-
polarities =
|
129
|
+
polarities = {}
|
130
|
+
polarities[:positive] = []
|
131
|
+
polarities[:negative] = []
|
129
132
|
opinions = document.at('opinions')
|
130
133
|
|
131
134
|
return 0.0 unless opinions
|
132
135
|
|
133
136
|
opinions.css('opinion').each do |opinion|
|
134
|
-
|
137
|
+
sentiment = opinion.at('opinion_expression').attr('polarity').to_sym
|
138
|
+
polarities[sentiment] << opinion.at('opinion_expression').attr('strength').to_i.abs
|
135
139
|
end
|
136
140
|
|
137
|
-
positive = polarities.
|
138
|
-
negative = polarities.
|
141
|
+
positive = polarities[:positive].inject(0, :+)
|
142
|
+
negative = polarities[:negative].inject(0, :+)
|
139
143
|
|
140
144
|
return if (positive + negative) == 0
|
141
145
|
|
@@ -166,15 +170,17 @@ module Opener
|
|
166
170
|
# @return [Float]
|
167
171
|
#
|
168
172
|
def calculate_score(lemma_ids, polarities_hash)
|
169
|
-
|
173
|
+
positive_polarities = []
|
174
|
+
negative_polarities = []
|
170
175
|
|
171
176
|
lemma_ids.each do |id|
|
172
|
-
|
177
|
+
positive_polarities << polarities_hash[id].fetch(:positive, 0)
|
178
|
+
negative_polarities << polarities_hash[id].fetch(:negative, 0)
|
173
179
|
end
|
174
180
|
|
175
|
-
positive =
|
176
|
-
negative =
|
177
|
-
|
181
|
+
positive = positive_polarities.compact.inject(0, :+)
|
182
|
+
negative = negative_polarities.compact.inject(0, :+)
|
183
|
+
|
178
184
|
return if (positive + negative) == 0
|
179
185
|
|
180
186
|
score = ((positive - negative).to_f) / (positive + negative)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-scorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- development@olery.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -181,28 +181,28 @@ dependencies:
|
|
181
181
|
description: Component for calculating scores of KAF documents
|
182
182
|
email:
|
183
183
|
executables:
|
184
|
-
- scorer-server
|
185
|
-
- scorer-daemon
|
186
184
|
- scorer
|
185
|
+
- scorer-daemon
|
186
|
+
- scorer-server
|
187
187
|
extensions: []
|
188
188
|
extra_rdoc_files: []
|
189
189
|
files:
|
190
190
|
- config/database.rb
|
191
191
|
- lib/opener/scorer.rb
|
192
|
-
- lib/opener/scorer/version.rb
|
193
|
-
- lib/opener/scorer/output.rb
|
194
|
-
- lib/opener/scorer/server.rb
|
195
192
|
- lib/opener/scorer/cli.rb
|
193
|
+
- lib/opener/scorer/output.rb
|
196
194
|
- lib/opener/scorer/output_processor.rb
|
195
|
+
- lib/opener/scorer/server.rb
|
196
|
+
- lib/opener/scorer/version.rb
|
197
197
|
- lib/opener/scorer/views/index.erb
|
198
198
|
- config.ru
|
199
199
|
- opener-scorer.gemspec
|
200
200
|
- README.md
|
201
201
|
- LICENSE.txt
|
202
202
|
- exec/scorer.rb
|
203
|
-
- bin/scorer-server
|
204
|
-
- bin/scorer-daemon
|
205
203
|
- bin/scorer
|
204
|
+
- bin/scorer-daemon
|
205
|
+
- bin/scorer-server
|
206
206
|
homepage: http://opener-project.github.com/
|
207
207
|
licenses:
|
208
208
|
- Apache 2.0
|
@@ -228,4 +228,3 @@ signing_key:
|
|
228
228
|
specification_version: 4
|
229
229
|
summary: Component for calculating scores of KAF documents
|
230
230
|
test_files: []
|
231
|
-
has_rdoc: yard
|