opener-polarity-tagger 3.2.4 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opener/{polarity_tagger/kaf → kaf}/document.rb +0 -0
- data/lib/opener/{polarity_tagger/kaf → kaf}/term.rb +4 -0
- data/lib/opener/polarity_tagger/internal.rb +20 -18
- data/lib/opener/polarity_tagger/lexicon_map.rb +18 -9
- data/lib/opener/polarity_tagger/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d99cc90032fe712bac6fa6952d1dc482d7ea5a86d9db9544f17e52d75d68f6
|
4
|
+
data.tar.gz: 8c8a5126f8a63a55bea7062c06d078bc87b0ff9286201956524755fb163e1172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 185160b82b01008ed03ce4a26e0d93ca18b1aab91e20c57acfe7425fa103c557606e0151e161ad7d36dc7380b2f26c9daae9e9649e4b1f7b65ce29c98f270ccc
|
7
|
+
data.tar.gz: 73f6b42eba61db2004fff08f54a1636767e8e77e93ec817717530accfa9fcd3001097e630c043fea0d3afd462c42b755a03f274c4d74e427c1753cf70fb30648
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'lexicons_cache'
|
2
2
|
require_relative 'lexicon_map'
|
3
|
-
require_relative 'kaf/document'
|
3
|
+
require_relative '../kaf/document'
|
4
4
|
|
5
5
|
module Opener
|
6
6
|
class PolarityTagger
|
@@ -16,44 +16,46 @@ module Opener
|
|
16
16
|
@ignore_pos = ignore_pos
|
17
17
|
end
|
18
18
|
|
19
|
-
def clear_cache lang: nil, environment:
|
20
|
-
end
|
21
|
-
|
22
19
|
def run input, params = {}
|
23
|
-
|
20
|
+
kaf = KAF::Document.from_xml input
|
24
21
|
|
25
22
|
@cache_keys = params[:cache_keys] ||= {}
|
26
|
-
@cache_keys.merge! lang:
|
27
|
-
@map =
|
23
|
+
@cache_keys.merge! lang: kaf.language
|
24
|
+
@map = kaf.map = CACHE[**@cache_keys].lexicons
|
28
25
|
|
29
|
-
|
26
|
+
raise Opener::Core::UnsupportedLanguageError, kaf.language if @map.blank?
|
27
|
+
|
28
|
+
kaf.terms.each do |t|
|
30
29
|
lemma = t.lemma&.downcase
|
30
|
+
text = t.text.to_s.downcase
|
31
31
|
pos = if @ignore_pos then nil else t.pos end
|
32
32
|
attrs = Hashie::Mash.new
|
33
33
|
|
34
|
-
|
34
|
+
# text matching have priority as sometimes
|
35
|
+
# the lemma provided by Stanza is a different word
|
36
|
+
lexicon, polarity_pos = @map.by_polarity text, pos
|
37
|
+
lexicon, polarity_pos = @map.by_polarity lemma, pos if lexicon.polarity == 'unknown'
|
35
38
|
|
36
|
-
if
|
37
|
-
attrs.polarity = lexicon.polarity
|
38
|
-
end
|
39
|
-
if l = @map.by_negator(lemma)
|
39
|
+
if l = @map.by_negator(text) || @map.by_negator(lemma)
|
40
40
|
lexicon, polarity_pos = l, nil
|
41
41
|
attrs.sentiment_modifier = 'shifter'
|
42
|
-
|
43
|
-
if l = @map.by_intensifier(lemma)
|
42
|
+
elsif l = @map.by_intensifier(text) || @map.by_intensifier(lemma)
|
44
43
|
lexicon, polarity_pos = l, nil
|
45
44
|
attrs.sentiment_modifier = 'intensifier'
|
45
|
+
elsif lexicon.polarity != 'unknown'
|
46
|
+
attrs.polarity = lexicon.polarity
|
46
47
|
end
|
47
48
|
|
48
49
|
if attrs.size > 0
|
49
|
-
attrs
|
50
|
+
attrs['lexicon-id'] = lexicon.id.to_s if lexicon.id
|
51
|
+
attrs.resource = lexicon.resource if lexicon.resource
|
50
52
|
t.setPolarity attrs, polarity_pos
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
|
56
|
+
kaf.add_linguistic_processor DESC, "#{LAST_EDITED}_#{VERSION}", 'terms'
|
55
57
|
|
56
|
-
|
58
|
+
kaf.to_xml
|
57
59
|
end
|
58
60
|
|
59
61
|
end
|
@@ -16,11 +16,11 @@ module Opener
|
|
16
16
|
adv: 'A',
|
17
17
|
noun: 'N',
|
18
18
|
propernoun: 'N',
|
19
|
-
other: 'O',
|
20
19
|
prep: 'P',
|
21
20
|
verb: 'V',
|
21
|
+
other: DEFAULT_POS,
|
22
22
|
nil => DEFAULT_POS,
|
23
|
-
multi_word_expression:
|
23
|
+
multi_word_expression: DEFAULT_POS,
|
24
24
|
}
|
25
25
|
|
26
26
|
def initialize lang:, lexicons:
|
@@ -46,13 +46,12 @@ module Opener
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def by_polarity lemma, short_pos
|
49
|
-
|
49
|
+
l = @with_polarity[lemma+short_pos] if short_pos
|
50
|
+
return [l, short_pos] if l
|
50
51
|
|
51
52
|
POS_ORDER.chars.each do |short_pos|
|
52
|
-
|
53
|
-
|
54
|
-
return [l, short_pos]
|
55
|
-
end
|
53
|
+
l = @with_polarity[lemma+short_pos]
|
54
|
+
return [l, short_pos] if l
|
56
55
|
end
|
57
56
|
|
58
57
|
[UNKNOWN, 'unknown']
|
@@ -60,6 +59,14 @@ module Opener
|
|
60
59
|
|
61
60
|
protected
|
62
61
|
|
62
|
+
def map_one_polarity l
|
63
|
+
poses = if l.poses.present? then l.poses else [l.pos] end
|
64
|
+
poses.each do |pos|
|
65
|
+
short_pos = POS_SHORT_MAP[pos&.to_sym] || DEFAULT_POS
|
66
|
+
@with_polarity[l.lemma+short_pos] = l
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
63
70
|
def map lexicons
|
64
71
|
return if blank?
|
65
72
|
|
@@ -71,8 +78,10 @@ module Opener
|
|
71
78
|
when 'intensifier' then @intensifiers[l.lemma] = l
|
72
79
|
else
|
73
80
|
if l.polarity
|
74
|
-
|
75
|
-
|
81
|
+
map_one_polarity l
|
82
|
+
l.variants&.each do |v|
|
83
|
+
map_one_polarity v
|
84
|
+
end
|
76
85
|
end
|
77
86
|
end
|
78
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-polarity-tagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
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:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opener-daemons
|
@@ -181,10 +181,10 @@ dependencies:
|
|
181
181
|
description: Polarity tagger for various languages.
|
182
182
|
email:
|
183
183
|
executables:
|
184
|
-
- polarity-tagger-server
|
185
|
-
- console
|
186
184
|
- polarity-tagger
|
187
185
|
- polarity-tagger-daemon
|
186
|
+
- polarity-tagger-server
|
187
|
+
- console
|
188
188
|
extensions:
|
189
189
|
- ext/hack/Rakefile
|
190
190
|
extra_rdoc_files: []
|
@@ -212,12 +212,12 @@ files:
|
|
212
212
|
- core/poltagger-basic-multi.py
|
213
213
|
- exec/polarity-tagger.rb
|
214
214
|
- ext/hack/Rakefile
|
215
|
+
- lib/opener/kaf/document.rb
|
216
|
+
- lib/opener/kaf/term.rb
|
215
217
|
- lib/opener/polarity_tagger.rb
|
216
218
|
- lib/opener/polarity_tagger/cli.rb
|
217
219
|
- lib/opener/polarity_tagger/external.rb
|
218
220
|
- lib/opener/polarity_tagger/internal.rb
|
219
|
-
- lib/opener/polarity_tagger/kaf/document.rb
|
220
|
-
- lib/opener/polarity_tagger/kaf/term.rb
|
221
221
|
- lib/opener/polarity_tagger/lexicon_map.rb
|
222
222
|
- lib/opener/polarity_tagger/lexicons_cache.rb
|
223
223
|
- lib/opener/polarity_tagger/public/markdown.css
|