daff 1.1.12 → 1.1.13
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.
- data/README.md +1 -0
- data/lib/lib/coopy/alignment.rb +10 -120
- data/lib/lib/coopy/compare_table.rb +55 -4
- data/lib/lib/coopy/coopy.rb +1 -1
- data/lib/lib/coopy/index_pair.rb +8 -0
- data/lib/lib/coopy/merger.rb +2 -2
- data/lib/lib/coopy/table_diff.rb +2 -2
- metadata +43 -42
data/README.md
CHANGED
@@ -23,6 +23,7 @@ For certain languages you can use the command-line:
|
|
23
23
|
npm install daff -g # node/javascript
|
24
24
|
pip3 install daff # python3
|
25
25
|
gem install daff # ruby
|
26
|
+
composer require paulfitz/daff-php # php
|
26
27
|
````
|
27
28
|
|
28
29
|
Or use the library to view csv diffs on github via a chrome extension:
|
data/lib/lib/coopy/alignment.rb
CHANGED
@@ -85,12 +85,15 @@ module Coopy
|
|
85
85
|
return "" + "not implemented yet"
|
86
86
|
end
|
87
87
|
|
88
|
-
def to_order_pruned(rowlike)
|
89
|
-
return self.to_order_cached(true,rowlike)
|
90
|
-
end
|
91
|
-
|
92
88
|
def to_order
|
93
|
-
|
89
|
+
if @order_cache != nil
|
90
|
+
if @reference != nil
|
91
|
+
@order_cache = nil if !@order_cache_has_reference
|
92
|
+
end
|
93
|
+
end
|
94
|
+
@order_cache = self.to_order3 if @order_cache == nil
|
95
|
+
@order_cache_has_reference = true if @reference != nil
|
96
|
+
return @order_cache
|
94
97
|
end
|
95
98
|
|
96
99
|
def get_source
|
@@ -111,119 +114,7 @@ module Coopy
|
|
111
114
|
|
112
115
|
protected
|
113
116
|
|
114
|
-
def
|
115
|
-
if @order_cache != nil
|
116
|
-
if @reference != nil
|
117
|
-
@order_cache = nil if !@order_cache_has_reference
|
118
|
-
end
|
119
|
-
end
|
120
|
-
@order_cache = self.to_order3(prune,rowlike) if @order_cache == nil
|
121
|
-
@order_cache_has_reference = true if @reference != nil
|
122
|
-
return @order_cache
|
123
|
-
end
|
124
|
-
|
125
|
-
def prune_order(o,ref,rowlike)
|
126
|
-
tl = ref.tb
|
127
|
-
tr = @tb
|
128
|
-
if rowlike
|
129
|
-
return if tl.get_width != tr.get_width
|
130
|
-
elsif tl.get_height != tr.get_height
|
131
|
-
return
|
132
|
-
end
|
133
|
-
units = o.get_list
|
134
|
-
left_units = Array.new
|
135
|
-
left_locs = Array.new
|
136
|
-
right_units = Array.new
|
137
|
-
right_locs = Array.new
|
138
|
-
eliminate = Array.new
|
139
|
-
ct = 0
|
140
|
-
begin
|
141
|
-
_g1 = 0
|
142
|
-
_g = units.length
|
143
|
-
while(_g1 < _g)
|
144
|
-
i = _g1
|
145
|
-
_g1+=1
|
146
|
-
unit = units[i]
|
147
|
-
if unit.l < 0 && unit.r >= 0
|
148
|
-
right_units.push(unit)
|
149
|
-
right_locs.push(i)
|
150
|
-
ct+=1
|
151
|
-
elsif unit.r < 0 && unit.l >= 0
|
152
|
-
left_units.push(unit)
|
153
|
-
left_locs.push(i)
|
154
|
-
ct+=1
|
155
|
-
elsif ct > 0
|
156
|
-
left_units.slice!(0,left_units.length)
|
157
|
-
right_units.slice!(0,right_units.length)
|
158
|
-
left_locs.slice!(0,left_locs.length)
|
159
|
-
right_locs.slice!(0,right_locs.length)
|
160
|
-
ct = 0
|
161
|
-
end
|
162
|
-
while(left_locs.length > 0 && right_locs.length > 0)
|
163
|
-
l = left_units[0].l
|
164
|
-
r = right_units[0].r
|
165
|
-
view = tl.get_cell_view
|
166
|
-
match = true
|
167
|
-
if rowlike
|
168
|
-
w = tl.get_width
|
169
|
-
begin
|
170
|
-
_g2 = 0
|
171
|
-
while(_g2 < w)
|
172
|
-
j = _g2
|
173
|
-
_g2+=1
|
174
|
-
if !view.equals(tl.get_cell(j,l),tr.get_cell(j,r))
|
175
|
-
match = false
|
176
|
-
break
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
else
|
181
|
-
h = tl.get_height
|
182
|
-
begin
|
183
|
-
_g21 = 0
|
184
|
-
while(_g21 < h)
|
185
|
-
j1 = _g21
|
186
|
-
_g21+=1
|
187
|
-
if !view.equals(tl.get_cell(l,j1),tr.get_cell(r,j1))
|
188
|
-
match = false
|
189
|
-
break
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
if match
|
195
|
-
eliminate.push(left_locs[0])
|
196
|
-
eliminate.push(right_locs[0])
|
197
|
-
end
|
198
|
-
left_units.shift
|
199
|
-
right_units.shift
|
200
|
-
left_locs.shift
|
201
|
-
right_locs.shift
|
202
|
-
ct -= 2
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
if eliminate.length > 0
|
207
|
-
eliminate.sort {|a,b|
|
208
|
-
return a - b
|
209
|
-
}
|
210
|
-
del = 0
|
211
|
-
begin
|
212
|
-
_g3 = 0
|
213
|
-
while(_g3 < eliminate.length)
|
214
|
-
e = eliminate[_g3]
|
215
|
-
_g3+=1
|
216
|
-
begin
|
217
|
-
_this = o.get_list
|
218
|
-
_this.slice!(e - del,1)
|
219
|
-
end
|
220
|
-
del+=1
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def to_order3(prune,rowlike)
|
117
|
+
def to_order3
|
227
118
|
ref = @reference
|
228
119
|
if ref == nil
|
229
120
|
ref = ::Coopy::Alignment.new
|
@@ -283,7 +174,7 @@ module Coopy
|
|
283
174
|
while(ct_vp > 0 || ct_vl > 0 || ct_vr > 0)
|
284
175
|
ct+=1
|
285
176
|
if ct > max_ct
|
286
|
-
::Haxe::Log._trace.call("Ordering took too long, something went wrong",{ file_name: "Alignment.hx", line_number:
|
177
|
+
::Haxe::Log._trace.call("Ordering took too long, something went wrong",{ file_name: "Alignment.hx", line_number: 153, class_name: "coopy.Alignment", method_name: "toOrder3"})
|
287
178
|
break
|
288
179
|
end
|
289
180
|
xp = 0 if xp >= hp
|
@@ -400,7 +291,6 @@ module Coopy
|
|
400
291
|
xl+=1
|
401
292
|
xr+=1
|
402
293
|
end
|
403
|
-
self.prune_order(order,ref,rowlike) if prune
|
404
294
|
return order
|
405
295
|
end
|
406
296
|
|
@@ -49,7 +49,7 @@ module Coopy
|
|
49
49
|
def align_core2(align,a,b)
|
50
50
|
align.meta = ::Coopy::Alignment.new if align.meta == nil
|
51
51
|
self.align_columns(align.meta,a,b)
|
52
|
-
column_order = align.meta.
|
52
|
+
column_order = align.meta.to_order
|
53
53
|
common_units = Array.new
|
54
54
|
begin
|
55
55
|
_g = 0
|
@@ -187,6 +187,9 @@ module Coopy
|
|
187
187
|
end
|
188
188
|
end
|
189
189
|
pending_ct = ha
|
190
|
+
added_columns = {}
|
191
|
+
index_ct = 0
|
192
|
+
index_top = nil
|
190
193
|
begin
|
191
194
|
_g8 = 0
|
192
195
|
while(_g8 < top)
|
@@ -209,19 +212,27 @@ module Coopy
|
|
209
212
|
while(_g23 < _g13)
|
210
213
|
k1 = _g23
|
211
214
|
_g23+=1
|
212
|
-
|
215
|
+
col = active_columns[k1]
|
216
|
+
unit2 = common_units[col]
|
213
217
|
index1.add_columns(unit2.l,unit2.r)
|
214
|
-
|
218
|
+
if !added_columns.include?(col)
|
219
|
+
align.add_index_columns(unit2)
|
220
|
+
added_columns[col] = true
|
221
|
+
end
|
215
222
|
end
|
216
223
|
end
|
217
224
|
index1.index_tables(a,b)
|
225
|
+
index_top = index1 if k == top - 1
|
218
226
|
h = a.get_height
|
219
227
|
h = b.get_height if b.get_height > h
|
220
228
|
h = 1 if h < 1
|
221
229
|
wide_top_freq = index1.get_top_freq
|
222
230
|
ratio = wide_top_freq
|
223
231
|
ratio /= h + 20
|
224
|
-
|
232
|
+
if ratio >= 0.1
|
233
|
+
next if index_ct > 0 || k < top - 1
|
234
|
+
end
|
235
|
+
index_ct+=1
|
225
236
|
@indexes.push(index1) if @indexes != nil
|
226
237
|
fixed = Array.new
|
227
238
|
_it = ::Rb::RubyIterator.new(pending.keys)
|
@@ -246,6 +257,46 @@ module Coopy
|
|
246
257
|
end
|
247
258
|
end
|
248
259
|
end
|
260
|
+
if index_top != nil
|
261
|
+
offset = 0
|
262
|
+
scale = 1
|
263
|
+
begin
|
264
|
+
_g9 = 0
|
265
|
+
while(_g9 < 2)
|
266
|
+
sgn = _g9
|
267
|
+
_g9+=1
|
268
|
+
if pending_ct > 0
|
269
|
+
xb = nil
|
270
|
+
xb = hb - 1 if scale == -1 && hb > 0
|
271
|
+
begin
|
272
|
+
_g15 = 0
|
273
|
+
while(_g15 < ha)
|
274
|
+
xa0 = _g15
|
275
|
+
_g15+=1
|
276
|
+
xa = xa0 * scale + offset
|
277
|
+
xb2 = align.a2b(xa)
|
278
|
+
if xb2 != nil
|
279
|
+
xb = xb2 + scale
|
280
|
+
break if xb >= hb || xb < 0
|
281
|
+
next
|
282
|
+
end
|
283
|
+
next if xb == nil
|
284
|
+
ka = index_top.local_key(xa)
|
285
|
+
kb = index_top.remote_key(xb)
|
286
|
+
next if ka != kb
|
287
|
+
align.link(xa,xb)
|
288
|
+
pending_ct-=1
|
289
|
+
xb += scale
|
290
|
+
break if xb >= hb || xb < 0
|
291
|
+
break if pending_ct == 0
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
offset = ha - 1
|
296
|
+
scale = -1
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
249
300
|
end
|
250
301
|
align.link(0,0)
|
251
302
|
end
|
data/lib/lib/coopy/coopy.rb
CHANGED
data/lib/lib/coopy/index_pair.rb
CHANGED
@@ -73,6 +73,14 @@ module Coopy
|
|
73
73
|
return self.query_by_key(ka)
|
74
74
|
end
|
75
75
|
|
76
|
+
def local_key(row)
|
77
|
+
return @ia.to_key(@ia.get_table,row)
|
78
|
+
end
|
79
|
+
|
80
|
+
def remote_key(row)
|
81
|
+
return @ib.to_key(@ib.get_table,row)
|
82
|
+
end
|
83
|
+
|
76
84
|
def get_top_freq
|
77
85
|
return @ib.top_freq if @ib.top_freq > @ia.top_freq
|
78
86
|
return @ia.top_freq
|
data/lib/lib/coopy/merger.rb
CHANGED
@@ -100,9 +100,9 @@ module Coopy
|
|
100
100
|
@conflicts = 0
|
101
101
|
ct = ::Coopy::Coopy.compare_tables3(@parent,@local,@remote)
|
102
102
|
align = ct.align
|
103
|
-
@order = align.
|
103
|
+
@order = align.to_order
|
104
104
|
@units = @order.get_list
|
105
|
-
@column_order = align.meta.
|
105
|
+
@column_order = align.meta.to_order
|
106
106
|
@column_units = @column_order.get_list
|
107
107
|
allow_insert = @flags.allow_insert
|
108
108
|
allow_delete = @flags.allow_delete
|
data/lib/lib/coopy/table_diff.rb
CHANGED
@@ -196,7 +196,7 @@ module Coopy
|
|
196
196
|
output.clear
|
197
197
|
row_map = {}
|
198
198
|
col_map = {}
|
199
|
-
order = @align.
|
199
|
+
order = @align.to_order
|
200
200
|
units = order.get_list
|
201
201
|
has_parent = @align.reference != nil
|
202
202
|
a = nil
|
@@ -250,7 +250,7 @@ module Coopy
|
|
250
250
|
end
|
251
251
|
end
|
252
252
|
end
|
253
|
-
column_order = @align.meta.
|
253
|
+
column_order = @align.meta.to_order
|
254
254
|
column_units = column_order.get_list
|
255
255
|
show_rc_numbers = false
|
256
256
|
row_moves = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-10-
|
13
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Diff and patch tables
|
16
16
|
email:
|
@@ -125,46 +125,47 @@ summary: ! '[; ``` For
|
156
|
-
`data1` and `data2`: ```js
|
157
|
-
[''
|
158
|
-
[''
|
159
|
-
[''
|
160
|
-
we wrap them in `daff.TableView`:
|
161
|
-
var
|
162
|
-
the rows and columns in the two tables:
|
163
|
-
```
|
164
|
-
|
165
|
-
|
166
|
-
= new daff.
|
167
|
-
diff is now in `data_diff` in highlighter
|
128
|
+
pip3 install daff # python3 gem install daff # ruby composer require paulfitz/daff-php #
|
129
|
+
php ```` Or use the library to view csv diffs on github via a chrome extension:
|
130
|
+
> https://github.com/theodi/csvhub The diff format used by `daff` is specified
|
131
|
+
here: > http://dataprotocols.org/tabular-diff-format/ This library is a stripped
|
132
|
+
down version of the coopy toolbox (see http://share.find.coop). To compare tables
|
133
|
+
from different origins, or with automatically generated IDs, or other complications,
|
134
|
+
check out the coopy toolbox. The program ----------- You can run `daff`/`daff.py`/`daff.rb`
|
135
|
+
as a utility program: ```` $ daff daff can produce and apply tabular diffs. Call
|
136
|
+
as: daff [--output OUTPUT.csv] a.csv b.csv daff [--output OUTPUT.csv] parent.csv
|
137
|
+
a.csv b.csv daff [--output OUTPUT.jsonbook] a.jsonbook b.jsonbook daff patch [--inplace]
|
138
|
+
[--output OUTPUT.csv] a.csv patch.csv daff merge [--inplace] [--output OUTPUT.csv]
|
139
|
+
parent.csv a.csv b.csv daff trim [--output OUTPUT.csv] source.csv daff render [--output
|
140
|
+
OUTPUT.html] diff.csv daff git daff version The --inplace option to patch and merge
|
141
|
+
will result in modification of a.csv. If you need more control, here is the full
|
142
|
+
list of flags: daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT]
|
143
|
+
a.csv b.csv --context NUM: show NUM rows of context --all: do not prune
|
144
|
+
unchanged rows --act ACT: show only a certain kind of change (update, insert,
|
145
|
+
delete) daff diff --git path old-file old-hex old-mode new-file new-hex new-mode
|
146
|
+
--git: process arguments provided by git to diff drivers daff render [--output
|
147
|
+
OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv --css CSS.css: generate
|
148
|
+
a suitable css file to go with the html --fragment: generate just a html fragment
|
149
|
+
rather than a page --plain: do not use fancy utf8 characters to make arrows
|
150
|
+
prettier ```` Using with git -------------- Run `daff git csv` to install daff
|
151
|
+
as a diff and merge handler for `*.csv` files in your repository. Run `daff git`
|
152
|
+
for instructions on doing this manually. The library ----------- You can use `daff`
|
153
|
+
as a library from any supported language. We take here the example of Javascript. To
|
154
|
+
use `daff` on a webpage, first include `daff.js`: ```html <script src="daff.js"></script>
|
155
|
+
``` Or if using node outside the browser: ```js var daff = require(''daff''); ``` For
|
156
|
+
concreteness, assume we have two versions of a table, `data1` and `data2`: ```js
|
157
|
+
var data1 = [ [''Country'',''Capital''], [''Ireland'',''Dublin''], [''France'',''Paris''],
|
158
|
+
[''Spain'',''Barcelona''] ]; var data2 = [ [''Country'',''Code'',''Capital''], [''Ireland'',''ie'',''Dublin''],
|
159
|
+
[''France'',''fr'',''Paris''], [''Spain'',''es'',''Madrid''], [''Germany'',''de'',''Berlin'']
|
160
|
+
]; ``` To make those tables accessible to the library, we wrap them in `daff.TableView`:
|
161
|
+
```js var table1 = new daff.TableView(data1); var table2 = new daff.TableView(data2);
|
162
|
+
``` We can now compute the alignment between the rows and columns in the two tables:
|
163
|
+
```js var alignment = daff.compareTables(table1,table2).align(); ``` To produce
|
164
|
+
a diff from the alignment, we first need a table for the output: ```js var data_diff
|
165
|
+
= []; var table_diff = new daff.TableView(data_diff); ``` Using default options
|
166
|
+
for the diff: ```js var flags = new daff.CompareFlags(); var highlighter = new daff.TableDiff(alignment,flags);
|
167
|
+
highlighter.hilite(table_diff); ``` The diff is now in `data_diff` in highlighter
|
168
|
+
format, see specification here: > http://share.find.coop/doc/spec_hilite.html ```js
|
168
169
|
[ [ ''!'', '''', ''+++'', '''' ], [ ''@@'', ''Country'', ''Code'', ''Capital'' ],
|
169
170
|
[ ''+'', ''Ireland'', ''ie'', ''Dublin'' ], [ ''+'', ''France'', ''fr'', ''Paris''
|
170
171
|
], [ ''->'', ''Spain'', ''es'', ''Barcelona->Madrid'' ], [ ''+++'', ''Germany'',
|