that_language 0.1.0.pre2 → 0.1.0.pre3
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.
- checksums.yaml +4 -4
- data/lib/that_language.rb +8 -4
- data/lib/that_language/result.rb +9 -31
- data/lib/that_language/result_set.rb +1 -6
- data/lib/that_language/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d9e07c608c8697fff8ea1c101e9ff7bbe76f210
|
4
|
+
data.tar.gz: 7dc5a309d40dcc6b55f421c4b91cc363398d73ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e452b3820aa528314595e704beda91a7da3e30b7dcb180655b3f81f14e1f15e1308a3f26d48e2bb4dbded2b5c85899be71fc844fbf7fe83a900993106c18b3a7
|
7
|
+
data.tar.gz: 05a4d5214eefa073e8267e63eeb5884919d26e855c0a8e98e150791e963e46a5444711fbf3df388bcc67dfa442a235a181df5001de8996156f2e2092df8652bd
|
data/lib/that_language.rb
CHANGED
@@ -15,11 +15,15 @@ module ThatLanguage
|
|
15
15
|
alias_method :config, :configuration
|
16
16
|
|
17
17
|
def language_code(text)
|
18
|
-
|
18
|
+
detect_context.language_code(text)
|
19
|
+
end
|
20
|
+
|
21
|
+
def detect(text)
|
22
|
+
detect_context.detect(text)
|
19
23
|
end
|
20
24
|
|
21
25
|
def details(text)
|
22
|
-
|
26
|
+
detect_context.details(text)
|
23
27
|
end
|
24
28
|
|
25
29
|
def available_language_codes
|
@@ -34,8 +38,8 @@ module ThatLanguage
|
|
34
38
|
|
35
39
|
private
|
36
40
|
|
37
|
-
def
|
38
|
-
@
|
41
|
+
def detect_context
|
42
|
+
@detect_context ||= Detect.new(lookup_context)
|
39
43
|
end
|
40
44
|
|
41
45
|
def lookup_context
|
data/lib/that_language/result.rb
CHANGED
@@ -3,14 +3,13 @@ require 'json'
|
|
3
3
|
module ThatLanguage
|
4
4
|
class Result
|
5
5
|
attr_reader :language_code, :value, :hit_count
|
6
|
-
attr_accessor :words_count
|
6
|
+
attr_accessor :words_count
|
7
7
|
|
8
8
|
def initialize(language_code:)
|
9
9
|
@language_code = language_code
|
10
10
|
@value = 0.0
|
11
11
|
@hit_count = 0
|
12
12
|
@words_count = 0
|
13
|
-
@total_value = 0.0
|
14
13
|
end
|
15
14
|
|
16
15
|
def add(value)
|
@@ -20,8 +19,10 @@ module ThatLanguage
|
|
20
19
|
@value += value
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
22
|
+
def confidence
|
23
|
+
return 0 unless words_count > 0
|
24
|
+
|
25
|
+
value / words_count
|
25
26
|
end
|
26
27
|
|
27
28
|
def hit_ratio
|
@@ -30,30 +31,23 @@ module ThatLanguage
|
|
30
31
|
@hit_count.to_f / @words_count
|
31
32
|
end
|
32
33
|
|
33
|
-
def percentage
|
34
|
-
return 0.0 if @total_value == 0
|
35
|
-
|
36
|
-
@value / @total_value
|
37
|
-
end
|
38
|
-
|
39
34
|
def <=>(other)
|
40
|
-
|
35
|
+
value <=> other.value
|
41
36
|
end
|
42
37
|
|
43
38
|
def <(other)
|
44
|
-
|
39
|
+
value < other.value
|
45
40
|
end
|
46
41
|
|
47
42
|
def >(other)
|
48
|
-
|
43
|
+
value > other.value
|
49
44
|
end
|
50
45
|
|
51
46
|
def to_h
|
52
47
|
{
|
53
48
|
language_code: language_code,
|
49
|
+
confidence: confidence,
|
54
50
|
value: value,
|
55
|
-
score: score,
|
56
|
-
percentage: percentage,
|
57
51
|
hit_ratio: hit_ratio,
|
58
52
|
hit_count: hit_count,
|
59
53
|
words_count: words_count
|
@@ -63,21 +57,5 @@ module ThatLanguage
|
|
63
57
|
def to_json
|
64
58
|
to_h.to_json
|
65
59
|
end
|
66
|
-
|
67
|
-
# TODO: spec
|
68
|
-
def winner!(second_score:)
|
69
|
-
@second_score = second_score
|
70
|
-
end
|
71
|
-
|
72
|
-
# TODO: spec
|
73
|
-
def winner?
|
74
|
-
!@second_score.nil?
|
75
|
-
end
|
76
|
-
|
77
|
-
# TODO: spec
|
78
|
-
def confidence
|
79
|
-
factor = 1 - (@second_score / score)
|
80
|
-
factor * hit_ratio
|
81
|
-
end
|
82
60
|
end
|
83
61
|
end
|
@@ -11,7 +11,7 @@ module ThatLanguage
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def winner
|
14
|
-
results.max
|
14
|
+
results.max
|
15
15
|
end
|
16
16
|
|
17
17
|
def results
|
@@ -43,14 +43,9 @@ module ThatLanguage
|
|
43
43
|
def finalize_results
|
44
44
|
_results.each do |result|
|
45
45
|
result.words_count = @words_count
|
46
|
-
result.total_value = total_value
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
def total_value
|
51
|
-
_results.inject(0) { |sum, result| sum += result.value }
|
52
|
-
end
|
53
|
-
|
54
49
|
def lookup
|
55
50
|
@lookup ||= Hash.new do |hash, language_code|
|
56
51
|
hash[language_code] = Result.new(language_code: language_code)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: that_language
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Helm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|