textmood 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +47 -14
- data/bin/textmood +6 -0
- data/lang/da.txt +11277 -0
- data/lang/de.txt +12953 -0
- data/lang/{en_US.txt → en.txt} +8370 -8370
- data/lang/es.txt +14855 -0
- data/lang/fr.txt +12708 -0
- data/lang/no_NB.txt +9246 -9246
- data/lang/ru.txt +16494 -0
- data/lang/sv.txt +11106 -0
- data/lib/textmood.rb +22 -1
- metadata +8 -2
data/lib/textmood.rb
CHANGED
@@ -7,6 +7,8 @@ else
|
|
7
7
|
Encoding.default_internal = Encoding::UTF_8
|
8
8
|
end
|
9
9
|
|
10
|
+
require "json"
|
11
|
+
|
10
12
|
NORMALIZE_TO = 100
|
11
13
|
|
12
14
|
class TextMood
|
@@ -18,7 +20,20 @@ class TextMood
|
|
18
20
|
options[:end_ngram] ||= 1
|
19
21
|
@options = options
|
20
22
|
if options[:lang]
|
21
|
-
|
23
|
+
if options[:alias_file]
|
24
|
+
aliases = load_alias_file(options[:alias_file])
|
25
|
+
if aliases
|
26
|
+
file = aliases[options[:lang]]
|
27
|
+
unless file
|
28
|
+
raise ArgumentError, "Language tag not found in alias file"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise ArgumentError, "Alias file not found"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
file = File.dirname(__FILE__) + "/../lang/#{options[:lang]}.txt"
|
35
|
+
end
|
36
|
+
@sentiment_values = load_sentiment_file(file)
|
22
37
|
unless options[:include_symbols] == false
|
23
38
|
# load the symbols file (emoticons and other symbols)
|
24
39
|
@sentiment_values.merge!(load_sentiment_file(File.dirname(__FILE__) + "/../lang/symbols.txt"))
|
@@ -116,6 +131,12 @@ class TextMood
|
|
116
131
|
sentiment_values
|
117
132
|
end
|
118
133
|
|
134
|
+
# load the specified alias file into a hash
|
135
|
+
def load_alias_file(path)
|
136
|
+
file = File.open(path, "r:UTF-8") {|f| f.read}
|
137
|
+
JSON.parse(file)
|
138
|
+
end
|
139
|
+
|
119
140
|
def normalize_score(score, count)
|
120
141
|
factor = NORMALIZE_TO.to_f / count.to_f
|
121
142
|
(score * factor).round
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textmood
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,8 +19,14 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/textmood.rb
|
22
|
-
- lang/
|
22
|
+
- lang/da.txt
|
23
|
+
- lang/de.txt
|
24
|
+
- lang/en.txt
|
25
|
+
- lang/es.txt
|
26
|
+
- lang/fr.txt
|
23
27
|
- lang/no_NB.txt
|
28
|
+
- lang/ru.txt
|
29
|
+
- lang/sv.txt
|
24
30
|
- lang/symbols.txt
|
25
31
|
- bin/textmood
|
26
32
|
- test/test.rb
|