guerrilla_patch 2.8.6 → 2.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +3 -1
- data/README.md +8 -2
- data/Rakefile +1 -1
- data/lib/guerrilla_patch/text_matcher.rb +60 -0
- data/lib/guerrilla_patch/version.rb +1 -1
- data/spec/guerrilla_patch/kernel_spec.rb +2 -2
- data/spec/guerrilla_patch/text_matcher_spec.rb +76 -0
- metadata +13 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25ce0c43673c51855562aa9b2ad730bd9785c864
|
4
|
+
data.tar.gz: b73e4ec9f0981702d4cdb5c014da52c556b2460e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edb23ab42444b88ccbdd989c6343e5321c6436991968591c811180fd6f00edb0ae4427004cd45268540efeb758b5b707a7233aee03f09f2e5276e8e22b62cc1a
|
7
|
+
data.tar.gz: 1769f366c9067ce4e22be25f4a36361cb77ee836c63461f5e6055d4dc45622f360367211a0bc5887c240e57369606d24f45769827b80539de3956600e53fb981
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,7 +31,7 @@ def initialize(amount, index:nil, envy_no_more:nil)
|
|
31
31
|
end
|
32
32
|
```
|
33
33
|
|
34
|
-
It's
|
34
|
+
It's equivalent to this:
|
35
35
|
|
36
36
|
```
|
37
37
|
def initialize(amount, index:nil, envy_no_more:nil)
|
@@ -144,6 +144,13 @@ end
|
|
144
144
|
|
145
145
|
Somehow for my convoluted brain the later reads better.
|
146
146
|
|
147
|
+
Text matching
|
148
|
+
-----------------------------------------
|
149
|
+
```
|
150
|
+
source = { 1 => "Petar goes to the store.", 2 => "It is crazy there." }
|
151
|
+
target = { 1 => "Petar goes to the store. It is crazy there." }
|
152
|
+
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
153
|
+
```
|
147
154
|
|
148
155
|
Contributing to guerrilla_patch
|
149
156
|
-------------------------------
|
@@ -161,4 +168,3 @@ Copyright
|
|
161
168
|
|
162
169
|
Copyright (c) 2012 drKreso. See LICENSE.txt for
|
163
170
|
further details.
|
164
|
-
|
data/Rakefile
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
class TextMatcher
|
2
|
+
|
3
|
+
def self.match(source, target)
|
4
|
+
result = {}
|
5
|
+
source.each_pair { |key,value| source[key] = value.gsub(' ', '').downcase }
|
6
|
+
target.each_pair { |key,value| target[key] = value.gsub(' ', '').downcase }
|
7
|
+
|
8
|
+
mapped_source = source.each_with_index.map { |key_value,index| [index] * key_value[1].size }.flatten(1)
|
9
|
+
mapped_target = target.each_with_index.map { |key_value,index| [index] * key_value[1].size }.flatten(1)
|
10
|
+
|
11
|
+
source_clean_chars = source.each_value.map {|v| v}.join('')
|
12
|
+
target_clean_chars = target.each_value.map {|v| v}.join('')
|
13
|
+
|
14
|
+
#we have difference so we'll clean up source to match target
|
15
|
+
if source_clean_chars != target_clean_chars
|
16
|
+
source_index = 0
|
17
|
+
target_index = 0
|
18
|
+
while(target_index < target_clean_chars.size)
|
19
|
+
if source_clean_chars[source_index] == nil
|
20
|
+
target_index += 1
|
21
|
+
elsif source_clean_chars[source_index] != target_clean_chars[target_index]
|
22
|
+
mapped_source.insert(source_index, '-')
|
23
|
+
source_index += 1
|
24
|
+
else
|
25
|
+
source_index += 1
|
26
|
+
target_index += 1
|
27
|
+
end
|
28
|
+
puts target_index
|
29
|
+
end
|
30
|
+
puts " "
|
31
|
+
puts "#{mapped_source}"
|
32
|
+
puts "#{mapped_target}"
|
33
|
+
end
|
34
|
+
|
35
|
+
(0...mapped_target.size).each do |index|
|
36
|
+
if index == "-"
|
37
|
+
#nothing should happen
|
38
|
+
else
|
39
|
+
result[mapped_target[index]] ||= []
|
40
|
+
if mapped_source[index] == "-"
|
41
|
+
#nothing should happen
|
42
|
+
else
|
43
|
+
result[mapped_target[index]] << [mapped_source[index]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
result.each_pair { |key, value| result[key] = value.flatten.uniq }
|
48
|
+
|
49
|
+
#map real ids
|
50
|
+
target_as_pairs = target.map {|key, value| [key, value]}
|
51
|
+
source_as_pairs = source.map {|key, value| [key, value]}
|
52
|
+
real_result = {}
|
53
|
+
result.each_pair do |target_index, source_indexes|
|
54
|
+
real_result[target_as_pairs[target_index][0]] = source_indexes.map { |source_index| source_as_pairs[source_index][0] }
|
55
|
+
end
|
56
|
+
|
57
|
+
real_result
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -107,8 +107,8 @@ describe Array do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'can sum by name' do
|
110
|
-
apple =
|
111
|
-
orange =
|
110
|
+
apple = double(:price => 100)
|
111
|
+
orange = double(:price => 200)
|
112
112
|
[apple, orange].sum_me(:price).should == 300
|
113
113
|
end
|
114
114
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'guerrilla_patch/text_matcher.rb'
|
2
|
+
|
3
|
+
describe TextMatcher do
|
4
|
+
|
5
|
+
it 'should pair exact matches' do
|
6
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica"}
|
7
|
+
target = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica"}
|
8
|
+
TextMatcher.match(source,target).should == { 1 => [1], 2 => [2] }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should pair exact matches' do
|
12
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3=> "Sve je na popustu."}
|
13
|
+
target = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3=> "Sve je na popustu."}
|
14
|
+
TextMatcher.match(source,target).should == { 1 => [1], 2 => [2], 3 => [3] }
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should pair two for one target' do
|
18
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica." }
|
19
|
+
target = { 1 => "Petar ide u ducan.Tamo je ludnica." }
|
20
|
+
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should pair mismatced case' do
|
24
|
+
source = { 1 => "Petar ide u Ducan.", 2 => "Tamo je ludnica." }
|
25
|
+
target = { 1 => "Petar ide u ducan.Tamo je ludnica." }
|
26
|
+
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should pair two for one target and continue matching' do
|
30
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3 => "A" }
|
31
|
+
target = { 1 => "Petar ide u ducan.Tamo je ludnica.", 2 => "A" }
|
32
|
+
TextMatcher.match(source,target).should == { 1 => [1, 2], 2 => [3] }
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should pair when index is bigger than single digit number' do
|
36
|
+
source = { 1 => "A", 2 => "B", 3 => "C", 4 => "D", 5 => "EF", 6 => "G", 7 => "H", 8 => "I",
|
37
|
+
9 => "J", 10 => "KL", 11 => "M", 12 => "N", 13 => "O" }
|
38
|
+
target = { 1 => "A", 2 => "B", 3 => "C", 4 => "D", 5 => "E", 6 => "FG", 7 => "H", 8 => "I",
|
39
|
+
9 => "J", 10 => "K", 11 => "LM", 12 => "N", 13 => "O" }
|
40
|
+
TextMatcher.match(source,target).should == { 1=>[1], 2=>[2], 3=>[3], 4=>[4], 5=>[5], 6=>[5, 6],
|
41
|
+
7=>[7], 8=>[8], 9=>[9], 10=>[10], 11=>[10, 11],
|
42
|
+
12=>[12], 13=>[13]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should pair two for one target regardless of spacing' do
|
47
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica." }
|
48
|
+
target = { 1 => "Petar ide u ducan. Tamo je ludnica." }
|
49
|
+
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
50
|
+
end
|
51
|
+
|
52
|
+
xit 'should recover after missing target' do
|
53
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica." }
|
54
|
+
target = { 1 => "Petar ide u ducan.", 2 => "missing", 3=> "Tamo je ludnica." }
|
55
|
+
TextMatcher.match(source,target).should == { 1 => [1], 2 => [], 3 => [2] }
|
56
|
+
end
|
57
|
+
|
58
|
+
xit 'should recover after missing source' do
|
59
|
+
source = { 1 => "Petar ide u ducan.", 2 => "missing", 3 => "Tamo je ludnica." }
|
60
|
+
target = { 1 => "Petar ide u ducan.", 2=> "Tamo je ludnica." }
|
61
|
+
TextMatcher.match(source,target).should == { 1 => [1], 2 => [3] }
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should recover on half match' do
|
65
|
+
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3 => "Ovo je ok.", 4 => "Sadrzi zadnje dvije." }
|
66
|
+
target = { 1 => "Petar ide u ducan. Tamo", 2=> "je ludnica." , 3 => "Ovo je ok. Sadrzi zadnje dvije." }
|
67
|
+
TextMatcher.match(source,target).should == { 1 => [1,2], 2 => [2], 3 => [3,4] }
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should recover on half match from source side' do
|
71
|
+
source = { 1 => "Petar ide u ducan. Tamo", 2 => "je ludnica.", 3 => "Ovo je ok.", 4 => "Sadrzi zadnje dvije." }
|
72
|
+
target = { 1 => "Petar ide u ducan.", 2=> "Tamo je ludnica." , 3 => "Ovo je ok. Sadrzi zadnje dvije." }
|
73
|
+
TextMatcher.match(source,target).should == { 1 => [1], 2 => [1,2], 3 => [3,4] }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guerrilla_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.8.
|
5
|
-
prerelease:
|
4
|
+
version: 2.8.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- drKreso
|
@@ -18,10 +17,10 @@ executables: []
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
|
-
- .document
|
22
|
-
- .gitignore
|
23
|
-
- .rspec
|
24
|
-
- .travis.yml
|
20
|
+
- ".document"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".travis.yml"
|
25
24
|
- Gemfile
|
26
25
|
- Gemfile.lock
|
27
26
|
- LICENSE.txt
|
@@ -36,42 +35,37 @@ files:
|
|
36
35
|
- lib/guerrilla_patch/allocate.rb
|
37
36
|
- lib/guerrilla_patch/kernel.rb
|
38
37
|
- lib/guerrilla_patch/string.rb
|
38
|
+
- lib/guerrilla_patch/text_matcher.rb
|
39
39
|
- lib/guerrilla_patch/version.rb
|
40
40
|
- spec/guerrilla_patch/aggregate_by_type/aggregator_spec.rb
|
41
41
|
- spec/guerrilla_patch/aggregate_by_type/divide_by_type_spec.rb
|
42
42
|
- spec/guerrilla_patch/allocate_spec.rb
|
43
43
|
- spec/guerrilla_patch/kernel_spec.rb
|
44
44
|
- spec/guerrilla_patch/string_spec.rb
|
45
|
+
- spec/guerrilla_patch/text_matcher_spec.rb
|
45
46
|
homepage: http://github.com/drKreso/guerrilla_patch
|
46
47
|
licenses:
|
47
48
|
- MIT
|
49
|
+
metadata: {}
|
48
50
|
post_install_message:
|
49
51
|
rdoc_options: []
|
50
52
|
require_paths:
|
51
53
|
- lib
|
52
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
55
|
requirements:
|
55
|
-
- -
|
56
|
+
- - ">="
|
56
57
|
- !ruby/object:Gem::Version
|
57
58
|
version: '0'
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
hash: 4217734096640871137
|
61
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
60
|
requirements:
|
64
|
-
- -
|
61
|
+
- - ">="
|
65
62
|
- !ruby/object:Gem::Version
|
66
63
|
version: '0'
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
hash: 4217734096640871137
|
70
64
|
requirements: []
|
71
65
|
rubyforge_project:
|
72
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.5.1
|
73
67
|
signing_key:
|
74
|
-
specification_version:
|
68
|
+
specification_version: 4
|
75
69
|
summary: Since I am tired of hunting down monkey patches at large I am caging them
|
76
70
|
inside this gem
|
77
71
|
test_files:
|
@@ -80,3 +74,4 @@ test_files:
|
|
80
74
|
- spec/guerrilla_patch/allocate_spec.rb
|
81
75
|
- spec/guerrilla_patch/kernel_spec.rb
|
82
76
|
- spec/guerrilla_patch/string_spec.rb
|
77
|
+
- spec/guerrilla_patch/text_matcher_spec.rb
|