stimmung 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/emoticons.txt +0 -1
  3. data/lib/stimmung.rb +10 -10
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cabcb933856e7bbdf3aa844be363c1ce1eb3d341
4
- data.tar.gz: 7d2dd009a5b9ddb6076f9ca3a4326fb9ccb5094c
3
+ metadata.gz: 6f9169fc6c1557a510676990396f70de9a8b4cf6
4
+ data.tar.gz: 07d8be74953098bdd5a104475e03518df04baf15
5
5
  SHA512:
6
- metadata.gz: acd7f86db207dc8748c61e33927f169e2ca60030ff5cc20958db98d11243790041c7c46c5d648b6ba4f9256da40ce32d581c07de9fc3c2c44a3c60c982afc876
7
- data.tar.gz: 4f5beb6caddecd13c09f11d5ebd0a6101ad958b428a55ade161139739c7191a2deaf69bc63c9db64cc7f88e083c4222c7a2697cdeb1690886a0f385a4058c3fc
6
+ metadata.gz: 497d9424d744ab4b54775857f12b1dfb0293fe289d3f3acb5887bda1ae01e70c84bedcbdefd2b8f22e47900020038c0e284fdb6f75041106e28d2deba9d384cc
7
+ data.tar.gz: c46e355f12a984014826a005a18e979c3022f9a8d7c27c30a874b928aacc95ad01690d7e99297dfce19ee963698b6cec96c1d137f362427cf4879403304fbd62
@@ -40,7 +40,6 @@
40
40
  1.0 :-P
41
41
  1.0 :D
42
42
  1.0 :P
43
- 1.0 :P
44
43
  1.0 :]
45
44
  1.0 :o)
46
45
  1.0 :p
@@ -1,25 +1,25 @@
1
+ #<Encoding:UTF-8>
2
+
1
3
  class Stimmung
2
4
  attr_accessor :words
3
5
 
4
6
  def initialize(*dicts)
5
7
  @words = Hash.new(0.0)
6
- if dicts.empty?
7
- load_dictionary(File.join(File.dirname(__FILE__), 'emoticons.txt'), File.join(File.dirname(__FILE__), 'german.txt'))
8
- else
9
- load_dictionary(*dicts)
10
- end
8
+ directory = File.dirname(__FILE__)
9
+ dicts = %w(emoticons.txt german.txt).map! {|file| File.join(directory, file)} if dicts.empty?
10
+ load_dictionary(*dicts)
11
11
  end
12
12
 
13
13
  def score(str)
14
- str.to_s.downcase.split(/[\s\!\?\.]+/).reduce(0.0){|s,e| s += @words[e] }
14
+ str.downcase.gsub(/(\w{3,})(\W)(?=\s|$)/, '\1').split(/\s|\b(?=\W)/).reduce(0.0) {|s,e| s += @words[e]}
15
15
  end
16
16
 
17
17
  def load_dictionary(*files)
18
18
  files.each do |file|
19
- File.readlines(file).each do |line|
20
- score, text = line.chomp.split(/\s/)
21
- @words[text] = score.to_f
19
+ File.foreach(file, :encoding => 'UTF-8') do |line|
20
+ score, text = line.chomp!.split
21
+ @words[text.downcase.freeze] = score.to_f
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimmung
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pachacamac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Sentiment analysis for the German language
14
14
  email: pachacamac@inboxalias.com