Skip to content

Commit 1ffa4f5

Browse files
committed
style: auto-correct offenses
1 parent 9d67f4e commit 1ffa4f5

38 files changed

+150
-518
lines changed

.rubocop_todo.yml

Lines changed: 3 additions & 322 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
class NoRedisError < LoadError
1+
class NoRedisError < RuntimeError
22
def initialize
33
msg =
4-
%q{The Redis Backend can only be used if Redis is installed.
4+
%q(The Redis Backend can only be used if Redis is installed.
55
This error is raised from 'lib/classifier-reborn/backends/bayes_redis_backend.rb'.
66
If you have encountered this error and would like to use the Redis Backend,
77
please run 'gem install redis' or include 'gem "redis"' in
88
your gemfile. For more info see https://github.com/jekyll/classifier-reborn#usage.
9-
}
9+
)
1010
super(msg)
1111
end
1212
end

lib/classifier-reborn/bayes.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,12 @@ def initialize(*args)
5454
@backend = options[:backend]
5555
@tokenizer = options[:tokenizer] || Tokenizer::Whitespace
5656
@token_filters = options[:token_filters] || [TokenFilter::Stopword]
57-
if @enable_stemmer && !@token_filters.include?(TokenFilter::Stemmer)
58-
@token_filters << TokenFilter::Stemmer
59-
end
60-
if @token_filters.include?(TokenFilter::Stopword)
61-
TokenFilter::Stopword.language = @language
62-
end
57+
@token_filters << TokenFilter::Stemmer if @enable_stemmer && !@token_filters.include?(TokenFilter::Stemmer)
58+
TokenFilter::Stopword.language = @language if @token_filters.include?(TokenFilter::Stopword)
6359

6460
populate_initial_categories
6561

66-
if options.key?(:stopwords)
67-
custom_stopwords options[:stopwords]
68-
end
62+
custom_stopwords options[:stopwords] if options.key?(:stopwords)
6963
end
7064

7165
# Provides a general training method for all categories specified in Bayes#new
@@ -168,7 +162,7 @@ def classify_with_score(text)
168162
# Return the classification without the score
169163
def classify(text)
170164
result, score = classify_with_score(text)
171-
result = nil if score < @threshold || score == Float::INFINITY if threshold_enabled?
165+
result = nil if threshold_enabled? && (score < @threshold || score == Float::INFINITY)
172166
result
173167
end
174168

@@ -256,7 +250,7 @@ def add_category(category)
256250
@backend.add_category(category)
257251
end
258252

259-
alias_method :append_category, :add_category
253+
alias append_category add_category
260254

261255
def reset
262256
@backend.reset
@@ -277,7 +271,7 @@ def custom_stopwords(stopwords)
277271
if stopwords.strip.empty?
278272
stopwords = []
279273
elsif File.exist?(stopwords)
280-
stopwords = File.read(stopwords).force_encoding("utf-8").split
274+
stopwords = File.read(stopwords).force_encoding('utf-8').split
281275
else
282276
return # Do not overwrite the default
283277
end

lib/classifier-reborn/extensions/hasher.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
42
# Copyright:: Copyright (c) 2005 Lucas Carlson
53
# License:: LGPL

lib/classifier-reborn/extensions/token_filter/stemmer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
42
# Copyright:: Copyright (c) 2005 Lucas Carlson
53
# License:: LGPL

lib/classifier-reborn/extensions/token_filter/stopword.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
42
# Copyright:: Copyright (c) 2005 Lucas Carlson
53
# License:: LGPL
@@ -31,7 +29,7 @@ def add_custom_stopword_path(path)
3129

3230
STOPWORDS_PATH.each do |path|
3331
if File.exist?(File.join(path, language))
34-
hash[language] = Set.new File.read(File.join(path, language.to_s)).force_encoding("utf-8").split
32+
hash[language] = Set.new File.read(File.join(path, language.to_s)).force_encoding('utf-8').split
3533
break
3634
end
3735
end

lib/classifier-reborn/extensions/token_filter/symbol.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
42
# Copyright:: Copyright (c) 2005 Lucas Carlson
53
# License:: LGPL

lib/classifier-reborn/extensions/tokenizer/token.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
42
# Copyright:: Copyright (c) 2005 Lucas Carlson
53
# License:: LGPL

lib/classifier-reborn/extensions/tokenizer/whitespace.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
42
# Copyright:: Copyright (c) 2005 Lucas Carlson
53
# License:: LGPL

lib/classifier-reborn/extensions/vector.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def self.diag(s)
1010
Matrix.diagonal(*s)
1111
end
1212

13-
alias_method :trans, :transpose
13+
alias trans transpose
1414

1515
def SV_decomp(maxSweeps = 20)
16-
if row_size >= column_size
17-
q = trans * self
18-
else
19-
q = self * trans
20-
end
16+
q = if row_size >= column_size
17+
trans * self
18+
else
19+
self * trans
20+
end
2121

2222
qrot = q.dup
2323
v = Matrix.identity(q.row_size)
@@ -31,11 +31,11 @@ def SV_decomp(maxSweeps = 20)
3131
(1..qrot.row_size - 1).each do |col|
3232
next if row == col
3333

34-
if (2.0 * qrot[row, col]) == (qrot[row, row] - qrot[col, col])
35-
h = Math.atan(1) / 2.0
36-
else
37-
h = Math.atan((2.0 * qrot[row, col]) / (qrot[row, row] - qrot[col, col])) / 2.0
38-
end
34+
h = if (2.0 * qrot[row, col]) == (qrot[row, row] - qrot[col, col])
35+
Math.atan(1) / 2.0
36+
else
37+
Math.atan((2.0 * qrot[row, col]) / (qrot[row, row] - qrot[col, col])) / 2.0
38+
end
3939
hcos = Math.cos(h)
4040
hsin = Math.sin(h)
4141
mzrot = Matrix.identity(qrot.row_size)

0 commit comments

Comments
 (0)