cmp_text 0.1.3 → 0.1.4
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/README.md +2 -2
- data/lib/cmp_text/version.rb +1 -1
- data/lib/cmp_text.rb +11 -11
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b86b1adf38b65156b8ab2a97c6dfaa70f100e55
|
|
4
|
+
data.tar.gz: 8ba73d5ecf9ceeb5867c87457a81afc72c61e3de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94c9426a43779d71016b3d15b43dc98dd6029d3e84c9fa8beb6d1213964f4fd28bc64fab488b8ae2bcefdb58f23058bd0c4144646c1e8849d6a99e164bd17a64
|
|
7
|
+
data.tar.gz: d8bcadf974ae4a4cca146414be0e0cbf2e5a0a25368ef6853edd2362dcb675a3f89ad86792554e024d6d6ba2afd083be9cd1d74a460710773a7a9255513b637d
|
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# CmpText
|
|
2
|
-
最新版本 0.1.
|
|
2
|
+
最新版本 0.1.4
|
|
3
3
|
## Installation
|
|
4
4
|
|
|
5
5
|
添加这行代码到你的 Gemfile:
|
|
@@ -34,7 +34,7 @@ gem 'cmp_text'
|
|
|
34
34
|
例如直接输入两个字符串:
|
|
35
35
|
|
|
36
36
|
```ruby
|
|
37
|
-
CmpText::Analysis.txt_cmp('我来自武汉','我来自中国') # => 0.
|
|
37
|
+
CmpText::Analysis.txt_cmp('我来自武汉','我来自中国') # => 0.60
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
或者用print方法打印出JSON结果, 'succ_char'比对成功的部分,'failed_char'比对失败的部分:
|
data/lib/cmp_text/version.rb
CHANGED
data/lib/cmp_text.rb
CHANGED
|
@@ -12,6 +12,13 @@ module CmpText
|
|
|
12
12
|
def txt_cmp(f0, f1)
|
|
13
13
|
str_f0, str_f1 = open(f0), open(f1)
|
|
14
14
|
|
|
15
|
+
arr_f0_each_char = str_f0.dup.split('')
|
|
16
|
+
arr_f1_each_char = str_f1.dup.split('')
|
|
17
|
+
str_f0_size = str_f0.dup.size
|
|
18
|
+
str_f1_size = str_f1.dup.size
|
|
19
|
+
|
|
20
|
+
return 0.00 if [str_f0_size, str_f1_size].max == 0
|
|
21
|
+
|
|
15
22
|
@log_text = {
|
|
16
23
|
or_text_1: str_f0.dup,
|
|
17
24
|
or_text_2: str_f1.dup,
|
|
@@ -19,11 +26,6 @@ module CmpText
|
|
|
19
26
|
failed_char: []
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
arr_f0_each_char = str_f0.dup.split('')
|
|
23
|
-
arr_f1_each_char = str_f1.dup.split('')
|
|
24
|
-
str_f0_size = str_f0.dup.size
|
|
25
|
-
str_f1_size = str_f1.dup.size
|
|
26
|
-
|
|
27
29
|
arr_f0_each_char.each_with_index do |char, index|
|
|
28
30
|
cmp = false
|
|
29
31
|
break if [arr_f0_each_char.size, arr_f1_each_char.size].any?{|size| size == 0}
|
|
@@ -48,21 +50,19 @@ module CmpText
|
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
@log_text[:failed_char] << arr_f0_each_char.join << arr_f1_each_char.join
|
|
51
|
-
|
|
53
|
+
|
|
52
54
|
@log_text[:failed_char].delete('')
|
|
53
55
|
|
|
54
56
|
result = @log_text[:succ_char].join.size.to_f / [ @log_text[:or_text_1].size.to_f, @log_text[:or_text_2].size.to_f].max
|
|
57
|
+
|
|
58
|
+
result.round(2)
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
def print(f0, f1)
|
|
58
62
|
result = txt_cmp(f0, f1)
|
|
59
63
|
|
|
60
|
-
{ result: "匹配度是 #{(result * 100).round(
|
|
64
|
+
{ result: "匹配度是 #{(result * 100).round(4)}%", data: @log_text}
|
|
61
65
|
end
|
|
62
66
|
end
|
|
63
67
|
end
|
|
64
68
|
end
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|