everypolitician-daff 1.3.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +252 -0
- data/bin/daff.rb +3 -0
- data/lib/daff.rb +150 -0
- data/lib/lib/coopy/alignment.rb +307 -0
- data/lib/lib/coopy/cell_builder.rb +17 -0
- data/lib/lib/coopy/cell_info.rb +33 -0
- data/lib/lib/coopy/column_change.rb +16 -0
- data/lib/lib/coopy/combined_table.rb +127 -0
- data/lib/lib/coopy/combined_table_body.rb +151 -0
- data/lib/lib/coopy/combined_table_head.rb +103 -0
- data/lib/lib/coopy/compare_flags.rb +127 -0
- data/lib/lib/coopy/compare_table.rb +688 -0
- data/lib/lib/coopy/conflict_info.rb +23 -0
- data/lib/lib/coopy/coopy.rb +1065 -0
- data/lib/lib/coopy/cross_match.rb +17 -0
- data/lib/lib/coopy/csv.rb +290 -0
- data/lib/lib/coopy/diff_render.rb +339 -0
- data/lib/lib/coopy/diff_summary.rb +28 -0
- data/lib/lib/coopy/flat_cell_builder.rb +75 -0
- data/lib/lib/coopy/highlight_patch.rb +977 -0
- data/lib/lib/coopy/highlight_patch_unit.rb +38 -0
- data/lib/lib/coopy/index.rb +131 -0
- data/lib/lib/coopy/index_item.rb +37 -0
- data/lib/lib/coopy/index_pair.rb +96 -0
- data/lib/lib/coopy/json_table.rb +165 -0
- data/lib/lib/coopy/json_tables.rb +129 -0
- data/lib/lib/coopy/merger.rb +197 -0
- data/lib/lib/coopy/meta.rb +20 -0
- data/lib/lib/coopy/mover.rb +197 -0
- data/lib/lib/coopy/ndjson.rb +134 -0
- data/lib/lib/coopy/nested_cell_builder.rb +74 -0
- data/lib/lib/coopy/ordering.rb +54 -0
- data/lib/lib/coopy/property_change.rb +16 -0
- data/lib/lib/coopy/row.rb +11 -0
- data/lib/lib/coopy/row_change.rb +42 -0
- data/lib/lib/coopy/row_stream.rb +11 -0
- data/lib/lib/coopy/simple_meta.rb +314 -0
- data/lib/lib/coopy/simple_table.rb +345 -0
- data/lib/lib/coopy/simple_view.rb +70 -0
- data/lib/lib/coopy/sparse_sheet.rb +51 -0
- data/lib/lib/coopy/sql_column.rb +47 -0
- data/lib/lib/coopy/sql_compare.rb +605 -0
- data/lib/lib/coopy/sql_database.rb +21 -0
- data/lib/lib/coopy/sql_helper.rb +17 -0
- data/lib/lib/coopy/sql_table.rb +335 -0
- data/lib/lib/coopy/sql_table_name.rb +23 -0
- data/lib/lib/coopy/sql_tables.rb +128 -0
- data/lib/lib/coopy/sqlite_helper.rb +316 -0
- data/lib/lib/coopy/table.rb +24 -0
- data/lib/lib/coopy/table_comparison_state.rb +50 -0
- data/lib/lib/coopy/table_diff.rb +1185 -0
- data/lib/lib/coopy/table_io.rb +72 -0
- data/lib/lib/coopy/table_modifier.rb +40 -0
- data/lib/lib/coopy/table_stream.rb +102 -0
- data/lib/lib/coopy/table_view.rb +148 -0
- data/lib/lib/coopy/tables.rb +52 -0
- data/lib/lib/coopy/terminal_diff_render.rb +213 -0
- data/lib/lib/coopy/unit.rb +93 -0
- data/lib/lib/coopy/view.rb +20 -0
- data/lib/lib/coopy/viterbi.rb +177 -0
- data/lib/lib/haxe/ds/int_map.rb +19 -0
- data/lib/lib/haxe/ds/string_map.rb +19 -0
- data/lib/lib/haxe/format/json_parser.rb +265 -0
- data/lib/lib/haxe/format/json_printer.rb +240 -0
- data/lib/lib/haxe/imap.rb +10 -0
- data/lib/lib/haxe/io/bytes.rb +34 -0
- data/lib/lib/haxe/io/eof.rb +18 -0
- data/lib/lib/haxe/io/error.rb +22 -0
- data/lib/lib/haxe/io/output.rb +41 -0
- data/lib/lib/hx_overrides.rb +19 -0
- data/lib/lib/hx_sys.rb +74 -0
- data/lib/lib/lambda.rb +37 -0
- data/lib/lib/list.rb +36 -0
- data/lib/lib/math.rb +5 -0
- data/lib/lib/rb/boot.rb +39 -0
- data/lib/lib/rb/ruby_iterator.rb +50 -0
- data/lib/lib/reflect.rb +41 -0
- data/lib/lib/std.rb +12 -0
- data/lib/lib/string_buf.rb +19 -0
- data/lib/lib/sys/io/file_handle.rb +18 -0
- data/lib/lib/sys/io/file_output.rb +36 -0
- data/lib/lib/sys/io/hx_file.rb +20 -0
- data/lib/lib/type.rb +37 -0
- data/lib/lib/value_type.rb +23 -0
- data/lib/lib/x_list/list_iterator.rb +32 -0
- metadata +235 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a11fc20d411b513efdaba697341732ec8c959fab
|
4
|
+
data.tar.gz: a75fc65eec245636dbc871738e095dfb377131ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4ac298ae1a62e410888ec924c776d65cf3d2dbd2432c03941bcaec938f86ddda1f055c60653eb4bcc23a3f81cdd35c8f41149d9e12e3793aaf30a53c4c422cc
|
7
|
+
data.tar.gz: 2d2787dde77d711ae818defcf35fcd2285f23a3ffda84ce4a907531c6bbb7f8027f58a06fc694745a34c973332b50c37d2b4891efb6924bc3dd869b7de2d26f5
|
data/README.md
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/paulfitz/daff.svg?branch=master)](https://travis-ci.org/paulfitz/daff)
|
2
|
+
[![NPM version](https://badge.fury.io/js/daff.svg)](http://badge.fury.io/js/daff)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/daff.svg)](http://badge.fury.io/rb/daff)
|
4
|
+
[![PyPI version](https://badge.fury.io/py/daff.svg)](http://badge.fury.io/py/daff)
|
5
|
+
[![PHP version](https://badge.fury.io/ph/paulfitz%2Fdaff-php.svg)](http://badge.fury.io/ph/paulfitz%2Fdaff-php)
|
6
|
+
[![Bower version](https://badge.fury.io/bo/daff.svg)](http://badge.fury.io/bo/daff)
|
7
|
+
![Badge count](http://img.shields.io/:badges-7/7-33aa33.svg)
|
8
|
+
|
9
|
+
daff: data diff
|
10
|
+
===============
|
11
|
+
|
12
|
+
This is a library for comparing tables, producing a summary of their
|
13
|
+
differences, and using such a summary as a patch file. It is
|
14
|
+
optimized for comparing tables that share a common origin, in other
|
15
|
+
words multiple versions of the "same" table.
|
16
|
+
|
17
|
+
For a live demo, see:
|
18
|
+
> http://paulfitz.github.com/daff/
|
19
|
+
|
20
|
+
Install the library for your favorite language:
|
21
|
+
````sh
|
22
|
+
npm install daff -g # node/javascript
|
23
|
+
pip install daff # python
|
24
|
+
gem install daff # ruby
|
25
|
+
composer require paulfitz/daff-php # php
|
26
|
+
install.packages('daff') # R wrapper by Edwin de Jonge
|
27
|
+
bower install daff # web/javascript
|
28
|
+
````
|
29
|
+
|
30
|
+
Other translations are available here:
|
31
|
+
> https://github.com/paulfitz/daff/releases
|
32
|
+
|
33
|
+
Or use the library to view csv diffs on github via a chrome extension:
|
34
|
+
> https://github.com/theodi/csvhub
|
35
|
+
|
36
|
+
The diff format used by `daff` is specified here:
|
37
|
+
> http://dataprotocols.org/tabular-diff-format/
|
38
|
+
|
39
|
+
This library is a stripped down version of the coopy toolbox (see
|
40
|
+
http://share.find.coop). To compare tables from different origins,
|
41
|
+
or with automatically generated IDs, or other complications, check out
|
42
|
+
the coopy toolbox.
|
43
|
+
|
44
|
+
The program
|
45
|
+
-----------
|
46
|
+
|
47
|
+
You can run `daff`/`daff.py`/`daff.rb` as a utility program:
|
48
|
+
````
|
49
|
+
$ daff
|
50
|
+
daff can produce and apply tabular diffs.
|
51
|
+
Call as:
|
52
|
+
daff [--output OUTPUT.csv] a.csv b.csv
|
53
|
+
daff [--output OUTPUT.csv] parent.csv a.csv b.csv
|
54
|
+
daff [--output OUTPUT.ndjson] a.ndjson b.ndjson
|
55
|
+
daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv
|
56
|
+
daff merge [--inplace] [--output OUTPUT.csv] parent.csv a.csv b.csv
|
57
|
+
daff trim [--output OUTPUT.csv] source.csv
|
58
|
+
daff render [--output OUTPUT.html] diff.csv
|
59
|
+
daff git
|
60
|
+
daff version
|
61
|
+
|
62
|
+
The --inplace option to patch and merge will result in modification of a.csv.
|
63
|
+
|
64
|
+
If you need more control, here is the full list of flags:
|
65
|
+
daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv
|
66
|
+
--context NUM: show NUM rows of context
|
67
|
+
--all: do not prune unchanged rows
|
68
|
+
--act ACT: show only a certain kind of change (update, insert, delete)
|
69
|
+
|
70
|
+
daff diff --git path old-file old-hex old-mode new-file new-hex new-mode
|
71
|
+
--git: process arguments provided by git to diff drivers
|
72
|
+
|
73
|
+
daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv
|
74
|
+
--css CSS.css: generate a suitable css file to go with the html
|
75
|
+
--fragment: generate just a html fragment rather than a page
|
76
|
+
--plain: do not use fancy utf8 characters to make arrows prettier
|
77
|
+
````
|
78
|
+
|
79
|
+
Formats supported are CSV, TSV, and [ndjson](http://dataprotocols.org/ndjson/).
|
80
|
+
|
81
|
+
Using with git
|
82
|
+
--------------
|
83
|
+
|
84
|
+
Run `daff git csv` to install daff as a diff and merge handler
|
85
|
+
for `*.csv` files in your repository. Run `daff git` for instructions
|
86
|
+
on doing this manually. Your CSV diffs and merges will get smarter,
|
87
|
+
since git will suddenly understand about rows and columns, not just lines:
|
88
|
+
|
89
|
+
![Example CSV diff](http://paulfitz.github.io/daff-doc/images/daff_vs_diff.png)
|
90
|
+
|
91
|
+
The library
|
92
|
+
-----------
|
93
|
+
|
94
|
+
You can use `daff` as a library from any supported language. We take
|
95
|
+
here the example of Javascript. To use `daff` on a webpage,
|
96
|
+
first include `daff.js`:
|
97
|
+
```html
|
98
|
+
<script src="daff.js"></script>
|
99
|
+
```
|
100
|
+
Or if using node outside the browser:
|
101
|
+
```js
|
102
|
+
var daff = require('daff');
|
103
|
+
```
|
104
|
+
|
105
|
+
For concreteness, assume we have two versions of a table,
|
106
|
+
`data1` and `data2`:
|
107
|
+
```js
|
108
|
+
var data1 = [
|
109
|
+
['Country','Capital'],
|
110
|
+
['Ireland','Dublin'],
|
111
|
+
['France','Paris'],
|
112
|
+
['Spain','Barcelona']
|
113
|
+
];
|
114
|
+
var data2 = [
|
115
|
+
['Country','Code','Capital'],
|
116
|
+
['Ireland','ie','Dublin'],
|
117
|
+
['France','fr','Paris'],
|
118
|
+
['Spain','es','Madrid'],
|
119
|
+
['Germany','de','Berlin']
|
120
|
+
];
|
121
|
+
```
|
122
|
+
|
123
|
+
To make those tables accessible to the library, we wrap them
|
124
|
+
in `daff.TableView`:
|
125
|
+
```js
|
126
|
+
var table1 = new daff.TableView(data1);
|
127
|
+
var table2 = new daff.TableView(data2);
|
128
|
+
```
|
129
|
+
|
130
|
+
We can now compute the alignment between the rows and columns
|
131
|
+
in the two tables:
|
132
|
+
```js
|
133
|
+
var alignment = daff.compareTables(table1,table2).align();
|
134
|
+
```
|
135
|
+
|
136
|
+
To produce a diff from the alignment, we first need a table
|
137
|
+
for the output:
|
138
|
+
```js
|
139
|
+
var data_diff = [];
|
140
|
+
var table_diff = new daff.TableView(data_diff);
|
141
|
+
```
|
142
|
+
|
143
|
+
Using default options for the diff:
|
144
|
+
```js
|
145
|
+
var flags = new daff.CompareFlags();
|
146
|
+
var highlighter = new daff.TableDiff(alignment,flags);
|
147
|
+
highlighter.hilite(table_diff);
|
148
|
+
```
|
149
|
+
|
150
|
+
The diff is now in `data_diff` in highlighter format, see
|
151
|
+
specification here:
|
152
|
+
> http://share.find.coop/doc/spec_hilite.html
|
153
|
+
|
154
|
+
```js
|
155
|
+
[ [ '!', '', '+++', '' ],
|
156
|
+
[ '@@', 'Country', 'Code', 'Capital' ],
|
157
|
+
[ '+', 'Ireland', 'ie', 'Dublin' ],
|
158
|
+
[ '+', 'France', 'fr', 'Paris' ],
|
159
|
+
[ '->', 'Spain', 'es', 'Barcelona->Madrid' ],
|
160
|
+
[ '+++', 'Germany', 'de', 'Berlin' ] ]
|
161
|
+
```
|
162
|
+
|
163
|
+
For visualization, you may want to convert this to a HTML table
|
164
|
+
with appropriate classes on cells so you can color-code inserts,
|
165
|
+
deletes, updates, etc. You can do this with:
|
166
|
+
```js
|
167
|
+
var diff2html = new daff.DiffRender();
|
168
|
+
diff2html.render(table_diff);
|
169
|
+
var table_diff_html = diff2html.html();
|
170
|
+
```
|
171
|
+
|
172
|
+
For 3-way differences (that is, comparing two tables given knowledge
|
173
|
+
of a common ancestor) use `daff.compareTables3` (give ancestor
|
174
|
+
table as the first argument).
|
175
|
+
|
176
|
+
Here is how to apply that difference as a patch:
|
177
|
+
```js
|
178
|
+
var patcher = new daff.HighlightPatch(table1,table_diff);
|
179
|
+
patcher.apply();
|
180
|
+
// table1 should now equal table2
|
181
|
+
```
|
182
|
+
|
183
|
+
For other languages, you should find sample code in
|
184
|
+
the packages on the [Releases](https://github.com/paulfitz/daff/releases) page.
|
185
|
+
|
186
|
+
Supported languages
|
187
|
+
-------------------
|
188
|
+
|
189
|
+
The `daff` library is written in [Haxe](http://haxe.org/), which
|
190
|
+
can be translated reasonably well into at least the following languages:
|
191
|
+
|
192
|
+
* Javascript
|
193
|
+
* Python
|
194
|
+
* Java
|
195
|
+
* C#
|
196
|
+
* C++
|
197
|
+
* Ruby (using an [unofficial haxe target](https://github.com/paulfitz/haxe) developed for `daff`)
|
198
|
+
* PHP
|
199
|
+
|
200
|
+
Some translations are done for you on the
|
201
|
+
[Releases](https://github.com/paulfitz/daff/releases) page.
|
202
|
+
To make another translation, or to compile from source
|
203
|
+
first follow the [Haxe getting started tutorial](http://haxe.org/doc/start) for the
|
204
|
+
language you care about. At the time of writing, if you are on OSX, you should
|
205
|
+
install haxe using `brew install haxe --HEAD`. Then do one of:
|
206
|
+
|
207
|
+
```
|
208
|
+
make js
|
209
|
+
make php
|
210
|
+
make py
|
211
|
+
make java
|
212
|
+
make cs
|
213
|
+
make cpp
|
214
|
+
```
|
215
|
+
|
216
|
+
For each language, the `daff` library expects to be handed an interface to tables you create, rather than creating them
|
217
|
+
itself. This is to avoid inefficient copies from one format to another. You'll find a `SimpleTable` class you can use if
|
218
|
+
you find this awkward.
|
219
|
+
|
220
|
+
Other possibilities:
|
221
|
+
|
222
|
+
* There's a daff wrapper for R written by [Edwin de Jonge](https://github.com/edwindj), see https://github.com/edwindj/daff and http://cran.r-project.org/web/packages/daff
|
223
|
+
* There's a hand-written ruby port by [James Smith](https://github.com/Floppy), see https://github.com/theodi/coopy-ruby
|
224
|
+
|
225
|
+
API documentation
|
226
|
+
-----------------
|
227
|
+
|
228
|
+
* You can browse the `daff` classes at http://paulfitz.github.io/daff-doc/
|
229
|
+
|
230
|
+
Sponsors
|
231
|
+
--------
|
232
|
+
|
233
|
+
<img src="http://datacommons.coop/images/the_zen_of_venn.png" alt="the zen of venn" height="100">
|
234
|
+
The [Data Commons Co-op](http://datacommons.coop), "perhaps the geekiest of all cooperative organizations on the planet," has given great moral support during the development of `daff`.
|
235
|
+
Donate a multiple of `42.42` in your currency to let them know you care: [http://datacommons.coop/donate/](http://datacommons.coop/donate/)
|
236
|
+
|
237
|
+
Reading material
|
238
|
+
----------------
|
239
|
+
|
240
|
+
* http://dataprotocols.org/tabular-diff-format/ : a specification of the diff format we use.
|
241
|
+
* http://theodi.org/blog/csvhub-github-diffs-for-csv-files : using this library with github.
|
242
|
+
* https://github.com/ropensci/unconf/issues/19 : a thread about diffing data in which daff shows up in at least four guises (see if you can spot them all).
|
243
|
+
* http://theodi.org/blog/adapting-git-simple-data : using this library with gitlab.
|
244
|
+
* http://okfnlabs.org/blog/2013/08/08/diffing-and-patching-data.html : a summary of where the library came from.
|
245
|
+
* http://blog.okfn.org/2013/07/02/git-and-github-for-data/ : a post about storing small data in git/github.
|
246
|
+
* http://blog.ouseful.info/2013/08/27/diff-or-chop-github-csv-data-files-and-openrefine/ : counterpoint - a post discussing tracked-changes rather than diffs.
|
247
|
+
* http://blog.byronjsmith.com/makefile-shortcuts.html : a tutorial on using `make` for data, with daff in the mix. "Since git considers changes on a per-line basis,
|
248
|
+
looking at diffs of comma-delimited and tab-delimited files can get obnoxious. The program daff fixes this problem."
|
249
|
+
|
250
|
+
## License
|
251
|
+
|
252
|
+
daff is distributed under the MIT License.
|
data/bin/daff.rb
ADDED
data/lib/daff.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Translation requires Ruby >= 1.9.3
|
5
|
+
ruby_major, ruby_minor, ruby_patch = RUBY_VERSION.split('.').map{|x| x.to_i}
|
6
|
+
if ruby_major<1 || (ruby_major==1 && (ruby_minor<9 || (ruby_minor==9 && ruby_patch<3)))
|
7
|
+
$stderr.puts "Your current Ruby version is: #{RUBY_VERSION}. Haxe/Ruby generates code for version 1.9.3 or later."
|
8
|
+
Kernel.exit 1
|
9
|
+
end
|
10
|
+
def haxe_me(source_name)
|
11
|
+
$hx_types ||= {}
|
12
|
+
$hx_types[source_name.join('.')] = self
|
13
|
+
_haxe_vars_ = {}
|
14
|
+
instance_methods(false).grep(/=$/).grep(/^[^\[=]/).each do |v|
|
15
|
+
_haxe_vars_[v.to_s[0..-2].to_sym] = ('@'+v.to_s[0..-2]).to_sym
|
16
|
+
end
|
17
|
+
old_get = instance_method(:[]) rescue nil
|
18
|
+
define_method(:[]) do |x|
|
19
|
+
return old_get.bind(self).(x) if x.is_a?(Fixnum)
|
20
|
+
tag = _haxe_vars_[x]
|
21
|
+
return instance_variable_get(tag) if tag
|
22
|
+
method x
|
23
|
+
end
|
24
|
+
old_set = instance_method(:[]=) rescue nil
|
25
|
+
define_method(:[]=) do |x,y|
|
26
|
+
return old_set.bind(self).(x,y) if x.is_a?(Fixnum)
|
27
|
+
instance_variable_set(_haxe_vars_[x],y)
|
28
|
+
end
|
29
|
+
define_method(:haxe_name) do
|
30
|
+
source_name.join('.')
|
31
|
+
end
|
32
|
+
class << self
|
33
|
+
define_method(:[]) do |x|
|
34
|
+
method x
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'date'
|
40
|
+
require_relative 'lib/hx_overrides'
|
41
|
+
require_relative 'lib/lambda'
|
42
|
+
require_relative 'lib/list'
|
43
|
+
require_relative 'lib/x_list/list_iterator'
|
44
|
+
require_relative 'lib/reflect'
|
45
|
+
require_relative 'lib/std'
|
46
|
+
require_relative 'lib/string_buf'
|
47
|
+
require_relative 'lib/hx_sys'
|
48
|
+
require_relative 'lib/value_type'
|
49
|
+
require_relative 'lib/type'
|
50
|
+
require_relative 'lib/coopy/alignment'
|
51
|
+
require_relative 'lib/coopy/cell_builder'
|
52
|
+
require_relative 'lib/coopy/cell_info'
|
53
|
+
require_relative 'lib/coopy/column_change'
|
54
|
+
require_relative 'lib/coopy/table'
|
55
|
+
require_relative 'lib/coopy/combined_table'
|
56
|
+
require_relative 'lib/coopy/combined_table_body'
|
57
|
+
require_relative 'lib/coopy/combined_table_head'
|
58
|
+
require_relative 'lib/coopy/compare_flags'
|
59
|
+
require_relative 'lib/coopy/compare_table'
|
60
|
+
require_relative 'lib/coopy/conflict_info'
|
61
|
+
require_relative 'lib/coopy/coopy'
|
62
|
+
require_relative 'lib/coopy/cross_match'
|
63
|
+
require_relative 'lib/coopy/csv'
|
64
|
+
require_relative 'lib/coopy/diff_render'
|
65
|
+
require_relative 'lib/coopy/diff_summary'
|
66
|
+
require_relative 'lib/coopy/flat_cell_builder'
|
67
|
+
require_relative 'lib/coopy/row'
|
68
|
+
require_relative 'lib/coopy/highlight_patch'
|
69
|
+
require_relative 'lib/coopy/highlight_patch_unit'
|
70
|
+
require_relative 'lib/coopy/index'
|
71
|
+
require_relative 'lib/coopy/index_item'
|
72
|
+
require_relative 'lib/coopy/index_pair'
|
73
|
+
require_relative 'lib/coopy/meta'
|
74
|
+
require_relative 'lib/coopy/json_table'
|
75
|
+
require_relative 'lib/coopy/json_tables'
|
76
|
+
require_relative 'lib/coopy/merger'
|
77
|
+
require_relative 'lib/coopy/mover'
|
78
|
+
require_relative 'lib/coopy/ndjson'
|
79
|
+
require_relative 'lib/coopy/nested_cell_builder'
|
80
|
+
require_relative 'lib/coopy/ordering'
|
81
|
+
require_relative 'lib/coopy/property_change'
|
82
|
+
require_relative 'lib/coopy/row_change'
|
83
|
+
require_relative 'lib/coopy/row_stream'
|
84
|
+
require_relative 'lib/coopy/simple_meta'
|
85
|
+
require_relative 'lib/coopy/simple_table'
|
86
|
+
require_relative 'lib/coopy/view'
|
87
|
+
require_relative 'lib/coopy/simple_view'
|
88
|
+
require_relative 'lib/coopy/sparse_sheet'
|
89
|
+
require_relative 'lib/coopy/sql_column'
|
90
|
+
require_relative 'lib/coopy/sql_compare'
|
91
|
+
require_relative 'lib/coopy/sql_database'
|
92
|
+
require_relative 'lib/coopy/sql_helper'
|
93
|
+
require_relative 'lib/coopy/sql_table'
|
94
|
+
require_relative 'lib/coopy/sql_table_name'
|
95
|
+
require_relative 'lib/coopy/sql_tables'
|
96
|
+
require_relative 'lib/coopy/sqlite_helper'
|
97
|
+
require_relative 'lib/coopy/table_comparison_state'
|
98
|
+
require_relative 'lib/coopy/table_diff'
|
99
|
+
require_relative 'lib/coopy/table_io'
|
100
|
+
require_relative 'lib/coopy/table_modifier'
|
101
|
+
require_relative 'lib/coopy/table_stream'
|
102
|
+
require_relative 'lib/coopy/tables'
|
103
|
+
require_relative 'lib/coopy/terminal_diff_render'
|
104
|
+
require_relative 'lib/coopy/unit'
|
105
|
+
require_relative 'lib/coopy/viterbi'
|
106
|
+
require_relative 'lib/haxe/imap'
|
107
|
+
require_relative 'lib/haxe/ds/int_map'
|
108
|
+
require_relative 'lib/haxe/ds/string_map'
|
109
|
+
require_relative 'lib/haxe/format/json_parser'
|
110
|
+
require_relative 'lib/haxe/format/json_printer'
|
111
|
+
require_relative 'lib/haxe/io/bytes'
|
112
|
+
require_relative 'lib/haxe/io/output'
|
113
|
+
require_relative 'lib/haxe/io/eof'
|
114
|
+
require_relative 'lib/haxe/io/error'
|
115
|
+
require_relative 'lib/rb/boot'
|
116
|
+
require_relative 'lib/rb/ruby_iterator'
|
117
|
+
require_relative 'lib/sys/io/file_handle'
|
118
|
+
require_relative 'lib/sys/io/hx_file'
|
119
|
+
require_relative 'lib/sys/io/file_output'
|
120
|
+
|
121
|
+
|
122
|
+
def _hx_ushr(x,ct) (((x<0) ? (x + 0x100000000) : x) >> ct) end
|
123
|
+
def _hx_str(x) (x.nil? ? 'null' : x.to_s) end
|
124
|
+
def _hx_add(x,y) (((x.is_a? String)||(y.is_a? String)) ? (_hx_str(x)+_hx_str(y)) : (x+y)) end
|
125
|
+
def _hx_ord(s) return 0 if s.nil?; s.ord end
|
126
|
+
$hx_exception_classes = {}
|
127
|
+
def hx_exception_class(c)
|
128
|
+
$hx_exception_classes[c.name] ||= Class.new(RuntimeError) do
|
129
|
+
Object.const_set((c.name.split(/::/)[-1]||'') + 'HaxeException',self)
|
130
|
+
attr_accessor :hx_exception_target
|
131
|
+
def initialize(target) @hx_exception_target = target; end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
def hx_raise(x)
|
135
|
+
hx_exception_class(x.class).new(x)
|
136
|
+
end
|
137
|
+
def hx_rescue(x)
|
138
|
+
hx_exception_class(x.class)
|
139
|
+
end
|
140
|
+
def hx_rescued(x)
|
141
|
+
return x.hx_exception_target if x.respond_to? :hx_exception_target
|
142
|
+
x
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
require_relative 'lib/coopy/table_view'
|
147
|
+
Daff = Coopy
|
148
|
+
if __FILE__ == $0
|
149
|
+
Coopy::Coopy.main
|
150
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class Alignment
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@map_a2b = {}
|
9
|
+
@map_b2a = {}
|
10
|
+
@ha = @hb = 0
|
11
|
+
@map_count = 0
|
12
|
+
@reference = nil
|
13
|
+
@meta = nil
|
14
|
+
@comp = nil
|
15
|
+
@order_cache_has_reference = false
|
16
|
+
@ia = -1
|
17
|
+
@ib = -1
|
18
|
+
@marked_as_identical = false
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
attr_accessor :map_a2b
|
24
|
+
attr_accessor :map_b2a
|
25
|
+
attr_accessor :ha
|
26
|
+
attr_accessor :hb
|
27
|
+
attr_accessor :ta
|
28
|
+
attr_accessor :tb
|
29
|
+
attr_accessor :ia
|
30
|
+
attr_accessor :ib
|
31
|
+
attr_accessor :map_count
|
32
|
+
attr_accessor :order_cache
|
33
|
+
attr_accessor :order_cache_has_reference
|
34
|
+
attr_accessor :index_columns
|
35
|
+
attr_accessor :marked_as_identical
|
36
|
+
|
37
|
+
public
|
38
|
+
|
39
|
+
attr_accessor :reference
|
40
|
+
attr_accessor :meta
|
41
|
+
attr_accessor :comp
|
42
|
+
attr_accessor :has_addition
|
43
|
+
attr_accessor :has_removal
|
44
|
+
|
45
|
+
def range(ha,hb)
|
46
|
+
@ha = ha
|
47
|
+
@hb = hb
|
48
|
+
end
|
49
|
+
|
50
|
+
def tables(ta,tb)
|
51
|
+
@ta = ta
|
52
|
+
@tb = tb
|
53
|
+
end
|
54
|
+
|
55
|
+
def headers(ia,ib)
|
56
|
+
@ia = ia
|
57
|
+
@ib = ib
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_rowlike(flag)
|
61
|
+
end
|
62
|
+
|
63
|
+
def link(a,b)
|
64
|
+
if a != -1
|
65
|
+
@map_a2b[a] = b
|
66
|
+
else
|
67
|
+
@has_addition = true
|
68
|
+
end
|
69
|
+
if b != -1
|
70
|
+
@map_b2a[b] = a
|
71
|
+
else
|
72
|
+
@has_removal = true
|
73
|
+
end
|
74
|
+
@map_count+=1
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_index_columns(unit)
|
78
|
+
@index_columns = Array.new if @index_columns == nil
|
79
|
+
@index_columns.push(unit)
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_index_columns
|
83
|
+
@index_columns
|
84
|
+
end
|
85
|
+
|
86
|
+
def a2b(a)
|
87
|
+
@map_a2b[a]
|
88
|
+
end
|
89
|
+
|
90
|
+
def b2a(b)
|
91
|
+
@map_b2a[b]
|
92
|
+
end
|
93
|
+
|
94
|
+
def count
|
95
|
+
@map_count
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
result = "" + "not implemented yet" + " // " + "not implemented yet"
|
100
|
+
result += " (" + _hx_str(@reference.to_s) + ")" if @reference != nil
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_order
|
105
|
+
if @order_cache != nil
|
106
|
+
if @reference != nil
|
107
|
+
@order_cache = nil if !@order_cache_has_reference
|
108
|
+
end
|
109
|
+
end
|
110
|
+
@order_cache = self.to_order3 if @order_cache == nil
|
111
|
+
@order_cache_has_reference = true if @reference != nil
|
112
|
+
@order_cache
|
113
|
+
end
|
114
|
+
|
115
|
+
def add_to_order(l,r,p = -2)
|
116
|
+
@order_cache = ::Coopy::Ordering.new if @order_cache == nil
|
117
|
+
@order_cache.add(l,r,p)
|
118
|
+
@order_cache_has_reference = p != -2
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_source
|
122
|
+
@ta
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_target
|
126
|
+
@tb
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_source_header
|
130
|
+
@ia
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_target_header
|
134
|
+
@ib
|
135
|
+
end
|
136
|
+
|
137
|
+
protected
|
138
|
+
|
139
|
+
def to_order3
|
140
|
+
order = Array.new
|
141
|
+
if @reference == nil
|
142
|
+
_it = ::Rb::RubyIterator.new(@map_a2b.keys)
|
143
|
+
while(_it.has_next) do
|
144
|
+
k = _it._next
|
145
|
+
unit = ::Coopy::Unit.new
|
146
|
+
unit.l = k
|
147
|
+
unit.r = self.a2b(k)
|
148
|
+
order.push(unit)
|
149
|
+
end
|
150
|
+
_it2 = ::Rb::RubyIterator.new(@map_b2a.keys)
|
151
|
+
while(_it2.has_next) do
|
152
|
+
k1 = _it2._next
|
153
|
+
if self.b2a(k1) == -1
|
154
|
+
unit1 = ::Coopy::Unit.new
|
155
|
+
unit1.l = -1
|
156
|
+
unit1.r = k1
|
157
|
+
order.push(unit1)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
else
|
161
|
+
_it3 = ::Rb::RubyIterator.new(@map_a2b.keys)
|
162
|
+
while(_it3.has_next) do
|
163
|
+
k2 = _it3._next
|
164
|
+
unit2 = ::Coopy::Unit.new
|
165
|
+
unit2.p = k2
|
166
|
+
unit2.l = @reference.a2b(k2)
|
167
|
+
unit2.r = self.a2b(k2)
|
168
|
+
order.push(unit2)
|
169
|
+
end
|
170
|
+
_it4 = ::Rb::RubyIterator.new(@reference.map_b2a.keys)
|
171
|
+
while(_it4.has_next) do
|
172
|
+
k3 = _it4._next
|
173
|
+
if @reference.b2a(k3) == -1
|
174
|
+
unit3 = ::Coopy::Unit.new
|
175
|
+
unit3.p = -1
|
176
|
+
unit3.l = k3
|
177
|
+
unit3.r = -1
|
178
|
+
order.push(unit3)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
_it5 = ::Rb::RubyIterator.new(@map_b2a.keys)
|
182
|
+
while(_it5.has_next) do
|
183
|
+
k4 = _it5._next
|
184
|
+
if self.b2a(k4) == -1
|
185
|
+
unit4 = ::Coopy::Unit.new
|
186
|
+
unit4.p = -1
|
187
|
+
unit4.l = -1
|
188
|
+
unit4.r = k4
|
189
|
+
order.push(unit4)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
top = order.length
|
194
|
+
remotes = Array.new
|
195
|
+
locals = Array.new
|
196
|
+
begin
|
197
|
+
_g = 0
|
198
|
+
while(_g < top)
|
199
|
+
o = _g
|
200
|
+
_g+=1
|
201
|
+
if order[o].r >= 0
|
202
|
+
remotes.push(o)
|
203
|
+
else
|
204
|
+
locals.push(o)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
remote_sort = lambda {|a,b|
|
209
|
+
order[a].r - order[b].r
|
210
|
+
}
|
211
|
+
local_sort = lambda {|a1,b1|
|
212
|
+
return 0 if a1 == b1
|
213
|
+
return order[a1].l - order[b1].l if order[a1].l >= 0 && order[b1].l >= 0
|
214
|
+
return 1 if order[a1].l >= 0
|
215
|
+
return -1 if order[b1].l >= 0
|
216
|
+
a1 - b1
|
217
|
+
}
|
218
|
+
if @reference != nil
|
219
|
+
remote_sort = lambda {|a2,b2|
|
220
|
+
return 0 if a2 == b2
|
221
|
+
o1 = order[a2].r - order[b2].r
|
222
|
+
if order[a2].p >= 0 && order[b2].p >= 0
|
223
|
+
o2 = order[a2].p - order[b2].p
|
224
|
+
return o1 if o1 * o2 < 0
|
225
|
+
o3 = order[a2].l - order[b2].l
|
226
|
+
return o3
|
227
|
+
end
|
228
|
+
o1
|
229
|
+
}
|
230
|
+
local_sort = lambda {|a3,b3|
|
231
|
+
return 0 if a3 == b3
|
232
|
+
if order[a3].l >= 0 && order[b3].l >= 0
|
233
|
+
o11 = order[a3].l - order[b3].l
|
234
|
+
if order[a3].p >= 0 && order[b3].p >= 0
|
235
|
+
o21 = order[a3].p - order[b3].p
|
236
|
+
return o11 if o11 * o21 < 0
|
237
|
+
return o21
|
238
|
+
end
|
239
|
+
end
|
240
|
+
return 1 if order[a3].l >= 0
|
241
|
+
return -1 if order[b3].l >= 0
|
242
|
+
a3 - b3
|
243
|
+
}
|
244
|
+
end
|
245
|
+
remotes.sort!{|a,b| remote_sort.call(a,b)}
|
246
|
+
locals.sort!{|a,b| local_sort.call(a,b)}
|
247
|
+
revised_order = Array.new
|
248
|
+
at_r = 0
|
249
|
+
at_l = 0
|
250
|
+
begin
|
251
|
+
_g1 = 0
|
252
|
+
while(_g1 < top)
|
253
|
+
o4 = _g1
|
254
|
+
_g1+=1
|
255
|
+
if at_r < remotes.length && at_l < locals.length
|
256
|
+
ur = order[remotes[at_r]]
|
257
|
+
ul = order[locals[at_l]]
|
258
|
+
if ul.l == -1 && ul.p >= 0 && ur.p >= 0
|
259
|
+
if ur.p > ul.p
|
260
|
+
revised_order.push(ul)
|
261
|
+
at_l+=1
|
262
|
+
next
|
263
|
+
end
|
264
|
+
elsif ur.l > ul.l
|
265
|
+
revised_order.push(ul)
|
266
|
+
at_l+=1
|
267
|
+
next
|
268
|
+
end
|
269
|
+
revised_order.push(ur)
|
270
|
+
at_r+=1
|
271
|
+
next
|
272
|
+
end
|
273
|
+
if at_r < remotes.length
|
274
|
+
ur1 = order[remotes[at_r]]
|
275
|
+
revised_order.push(ur1)
|
276
|
+
at_r+=1
|
277
|
+
next
|
278
|
+
end
|
279
|
+
if at_l < locals.length
|
280
|
+
ul1 = order[locals[at_l]]
|
281
|
+
revised_order.push(ul1)
|
282
|
+
at_l+=1
|
283
|
+
next
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
order = revised_order
|
288
|
+
result = ::Coopy::Ordering.new
|
289
|
+
result.set_list(order)
|
290
|
+
result.ignore_parent if @reference == nil
|
291
|
+
result
|
292
|
+
end
|
293
|
+
|
294
|
+
public
|
295
|
+
|
296
|
+
def mark_identical
|
297
|
+
@marked_as_identical = true
|
298
|
+
end
|
299
|
+
|
300
|
+
def is_marked_as_identical
|
301
|
+
@marked_as_identical
|
302
|
+
end
|
303
|
+
|
304
|
+
haxe_me ["coopy", "Alignment"]
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|