daff 1.1.2
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/bin/daff.rb +3 -0
- data/lib/daff.rb +95 -0
- data/lib/lib/coopy/alignment.rb +409 -0
- data/lib/lib/coopy/bag.rb +10 -0
- data/lib/lib/coopy/cell_info.rb +29 -0
- data/lib/lib/coopy/change.rb +48 -0
- data/lib/lib/coopy/change_type.rb +21 -0
- data/lib/lib/coopy/compare.rb +98 -0
- data/lib/lib/coopy/compare_flags.rb +46 -0
- data/lib/lib/coopy/compare_table.rb +402 -0
- data/lib/lib/coopy/coopy.rb +414 -0
- data/lib/lib/coopy/cross_match.rb +16 -0
- data/lib/lib/coopy/csv.rb +181 -0
- data/lib/lib/coopy/diff_render.rb +254 -0
- data/lib/lib/coopy/highlight_patch.rb +651 -0
- data/lib/lib/coopy/highlight_patch_unit.rb +37 -0
- data/lib/lib/coopy/index.rb +101 -0
- data/lib/lib/coopy/index_item.rb +20 -0
- data/lib/lib/coopy/index_pair.rb +87 -0
- data/lib/lib/coopy/mover.rb +195 -0
- data/lib/lib/coopy/ordering.rb +49 -0
- data/lib/lib/coopy/report.rb +23 -0
- data/lib/lib/coopy/row.rb +9 -0
- data/lib/lib/coopy/simple_cell.rb +23 -0
- data/lib/lib/coopy/simple_table.rb +242 -0
- data/lib/lib/coopy/simple_view.rb +41 -0
- data/lib/lib/coopy/sparse_sheet.rb +50 -0
- data/lib/lib/coopy/table.rb +17 -0
- data/lib/lib/coopy/table_comparison_state.rb +32 -0
- data/lib/lib/coopy/table_diff.rb +738 -0
- data/lib/lib/coopy/table_io.rb +33 -0
- data/lib/lib/coopy/table_modifier.rb +39 -0
- data/lib/lib/coopy/table_text.rb +25 -0
- data/lib/lib/coopy/unit.rb +70 -0
- data/lib/lib/coopy/view.rb +14 -0
- data/lib/lib/coopy/viewed_datum.rb +37 -0
- data/lib/lib/coopy/viterbi.rb +172 -0
- data/lib/lib/coopy/workspace.rb +22 -0
- data/lib/lib/haxe/ds/int_map.rb +14 -0
- data/lib/lib/haxe/ds/string_map.rb +14 -0
- data/lib/lib/haxe/format/json_parser.rb +264 -0
- data/lib/lib/haxe/format/json_printer.rb +239 -0
- data/lib/lib/haxe/io/bytes.rb +33 -0
- data/lib/lib/haxe/io/eof.rb +17 -0
- data/lib/lib/haxe/io/error.rb +21 -0
- data/lib/lib/haxe/io/output.rb +40 -0
- data/lib/lib/haxe/log.rb +16 -0
- data/lib/lib/hx_overrides.rb +18 -0
- data/lib/lib/imap.rb +6 -0
- data/lib/lib/lambda.rb +36 -0
- data/lib/lib/list.rb +42 -0
- data/lib/lib/rb/boot.rb +19 -0
- data/lib/lib/rb/ruby_iterator.rb +49 -0
- data/lib/lib/reflect.rb +29 -0
- data/lib/lib/string_buf.rb +14 -0
- data/lib/lib/sys.rb +19 -0
- data/lib/lib/sys/io/file.rb +19 -0
- data/lib/lib/sys/io/file_handle.rb +17 -0
- data/lib/lib/sys/io/file_output.rb +35 -0
- data/lib/lib/type.rb +32 -0
- data/lib/lib/value_type.rb +22 -0
- metadata +181 -0
data/lib/lib/type.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
class Type
|
5
|
+
|
6
|
+
def Type._typeof(v)
|
7
|
+
_g = v.class.to_s
|
8
|
+
case(_g)
|
9
|
+
when "TrueClass"
|
10
|
+
return ValueType.tbool
|
11
|
+
when "FalseClass"
|
12
|
+
return ValueType.tbool
|
13
|
+
when "String"
|
14
|
+
return ValueType.tclass(String)
|
15
|
+
when "Fixnum"
|
16
|
+
return ValueType.tint
|
17
|
+
when "Float"
|
18
|
+
return ValueType.tfloat
|
19
|
+
when "Proc"
|
20
|
+
return ValueType.tfunction
|
21
|
+
when "NilClass"
|
22
|
+
return ValueType.tnull
|
23
|
+
when "Hash"
|
24
|
+
return ValueType.tobject
|
25
|
+
else
|
26
|
+
return ValueType.tclass(v.class) if v.respond_to?("class")
|
27
|
+
return ValueType.tunknown
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
class ValueType
|
5
|
+
ISENUM__ = true
|
6
|
+
attr_accessor :tag
|
7
|
+
attr_accessor :index
|
8
|
+
attr_accessor :params
|
9
|
+
def initialize(t,index,p = nil ) @tag = t; @index = index; @params = p; end
|
10
|
+
|
11
|
+
def ValueType.tbool() ValueType.new("TBool",3) end
|
12
|
+
def ValueType.tclass(c) ValueType.new("TClass",6,[c]) end
|
13
|
+
def ValueType.tenum(e) ValueType.new("TEnum",7,[e]) end
|
14
|
+
def ValueType.tfloat() ValueType.new("TFloat",2) end
|
15
|
+
def ValueType.tfunction() ValueType.new("TFunction",5) end
|
16
|
+
def ValueType.tint() ValueType.new("TInt",1) end
|
17
|
+
def ValueType.tnull() ValueType.new("TNull",0) end
|
18
|
+
def ValueType.tobject() ValueType.new("TObject",4) end
|
19
|
+
def ValueType.tunknown() ValueType.new("TUnknown",8) end
|
20
|
+
CONSTRUCTS__ = ["TNull","TInt","TFloat","TBool","TObject","TFunction","TClass","TEnum","TUnknown"]
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Smith
|
9
|
+
- Paul Fitzpatrick
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Diff and patch tables
|
16
|
+
email:
|
17
|
+
- james@floppy.org.uk
|
18
|
+
- paul@robotrebuilt.com
|
19
|
+
executables:
|
20
|
+
- daff.rb
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/daff.rb
|
25
|
+
- lib/lib/type.rb
|
26
|
+
- lib/lib/lambda.rb
|
27
|
+
- lib/lib/reflect.rb
|
28
|
+
- lib/lib/imap.rb
|
29
|
+
- lib/lib/rb/boot.rb
|
30
|
+
- lib/lib/rb/ruby_iterator.rb
|
31
|
+
- lib/lib/value_type.rb
|
32
|
+
- lib/lib/hx_overrides.rb
|
33
|
+
- lib/lib/coopy/simple_table.rb
|
34
|
+
- lib/lib/coopy/workspace.rb
|
35
|
+
- lib/lib/coopy/compare_table.rb
|
36
|
+
- lib/lib/coopy/table_io.rb
|
37
|
+
- lib/lib/coopy/compare.rb
|
38
|
+
- lib/lib/coopy/index_item.rb
|
39
|
+
- lib/lib/coopy/simple_cell.rb
|
40
|
+
- lib/lib/coopy/index_pair.rb
|
41
|
+
- lib/lib/coopy/diff_render.rb
|
42
|
+
- lib/lib/coopy/cross_match.rb
|
43
|
+
- lib/lib/coopy/table_diff.rb
|
44
|
+
- lib/lib/coopy/alignment.rb
|
45
|
+
- lib/lib/coopy/table_modifier.rb
|
46
|
+
- lib/lib/coopy/highlight_patch.rb
|
47
|
+
- lib/lib/coopy/table_text.rb
|
48
|
+
- lib/lib/coopy/simple_view.rb
|
49
|
+
- lib/lib/coopy/row.rb
|
50
|
+
- lib/lib/coopy/change_type.rb
|
51
|
+
- lib/lib/coopy/index.rb
|
52
|
+
- lib/lib/coopy/bag.rb
|
53
|
+
- lib/lib/coopy/coopy.rb
|
54
|
+
- lib/lib/coopy/viewed_datum.rb
|
55
|
+
- lib/lib/coopy/cell_info.rb
|
56
|
+
- lib/lib/coopy/view.rb
|
57
|
+
- lib/lib/coopy/highlight_patch_unit.rb
|
58
|
+
- lib/lib/coopy/compare_flags.rb
|
59
|
+
- lib/lib/coopy/unit.rb
|
60
|
+
- lib/lib/coopy/mover.rb
|
61
|
+
- lib/lib/coopy/table_comparison_state.rb
|
62
|
+
- lib/lib/coopy/csv.rb
|
63
|
+
- lib/lib/coopy/ordering.rb
|
64
|
+
- lib/lib/coopy/change.rb
|
65
|
+
- lib/lib/coopy/sparse_sheet.rb
|
66
|
+
- lib/lib/coopy/report.rb
|
67
|
+
- lib/lib/coopy/table.rb
|
68
|
+
- lib/lib/coopy/viterbi.rb
|
69
|
+
- lib/lib/list.rb
|
70
|
+
- lib/lib/sys/io/file_output.rb
|
71
|
+
- lib/lib/sys/io/file.rb
|
72
|
+
- lib/lib/sys/io/file_handle.rb
|
73
|
+
- lib/lib/string_buf.rb
|
74
|
+
- lib/lib/haxe/io/eof.rb
|
75
|
+
- lib/lib/haxe/io/bytes.rb
|
76
|
+
- lib/lib/haxe/io/error.rb
|
77
|
+
- lib/lib/haxe/io/output.rb
|
78
|
+
- lib/lib/haxe/log.rb
|
79
|
+
- lib/lib/haxe/ds/int_map.rb
|
80
|
+
- lib/lib/haxe/ds/string_map.rb
|
81
|
+
- lib/lib/haxe/format/json_parser.rb
|
82
|
+
- lib/lib/haxe/format/json_printer.rb
|
83
|
+
- lib/lib/sys.rb
|
84
|
+
- bin/daff.rb
|
85
|
+
homepage: https://github.com/paulfitz/daff
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.23
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: ! 'daff: data diff =============== This is a library for comparing tables,
|
110
|
+
producing a summary of their differences, and using such a summary as a patch file. It
|
111
|
+
is optimized for comparing tables that share a common origin, in other words multiple
|
112
|
+
versions of the "same" table. For a live demo, see: > http://paulfitz.github.com/daff/ Get
|
113
|
+
the core library for your preferred language here: > https://github.com/paulfitz/daff/releases Or
|
114
|
+
with node: ````sh npm install daff ```` Or with pip: ````sh pip3 install daff #
|
115
|
+
currently needs python3 ```` Or use the library to view csv diffs on github via
|
116
|
+
a chrome extension: > https://github.com/theodi/csvhub The diff format used by
|
117
|
+
`daff` is specified here: > http://dataprotocols.org/tabular-diff-format/ This
|
118
|
+
library is a stripped down version of the coopy toolbox (see http://share.find.coop). To
|
119
|
+
compare tables from different origins, or with automatically generated IDs, or
|
120
|
+
other complications, check out the coopy toolbox. The program ----------- There
|
121
|
+
is a commandline utility wrapping the core functions of the library: ```` $ daff
|
122
|
+
daff can produce and apply tabular diffs. Call as: daff [--output OUTPUT.csv] a.csv
|
123
|
+
b.csv daff [--output OUTPUT.csv] parent.csv a.csv b.csv daff [--output OUTPUT.jsonbook]
|
124
|
+
a.jsonbook b.jsonbook daff patch [--output OUTPUT.csv] source.csv patch.csv daff
|
125
|
+
trim [--output OUTPUT.csv] source.csv daff render [--output OUTPUT.html] diff.csv If
|
126
|
+
you need more control, here is the full list of flags: daff diff [--output OUTPUT.csv]
|
127
|
+
[--context NUM] [--all] [--act ACT] a.csv b.csv --context NUM: show NUM rows of
|
128
|
+
context --all: do not prune unchanged rows --act ACT: show only a certain
|
129
|
+
kind of change (update, insert, delete) daff render [--output OUTPUT.html] [--css
|
130
|
+
CSS.css] [--fragment] [--plain] diff.csv --css CSS.css: generate a suitable css
|
131
|
+
file to go with the html --fragment: generate just a html fragment rather than
|
132
|
+
a page --plain: do not use fancy utf8 characters to make arrows prettier ```` The
|
133
|
+
library ----------- To use this library from Javascript, first include `daff.js`
|
134
|
+
on a webpage: ```html <script src="daff.js"></script> ``` Or with nodejs: ```js
|
135
|
+
var daff = require(''daff''); ``` For concreteness, assume we have two versions
|
136
|
+
of a table, `data1` and `data2`: ```js var data1 = [ [''Country'',''Capital''],
|
137
|
+
[''Ireland'',''Dublin''], [''France'',''Paris''], [''Spain'',''Barcelona''] ]; var
|
138
|
+
data2 = [ [''Country'',''Code'',''Capital''], [''Ireland'',''ie'',''Dublin''], [''France'',''fr'',''Paris''],
|
139
|
+
[''Spain'',''es'',''Madrid''], [''Germany'',''de'',''Berlin''] ]; ``` To make those
|
140
|
+
tables accessible to the library, we wrap them in `daff.TableView`: ```js var table1
|
141
|
+
= new daff.TableView(data1); var table2 = new daff.TableView(data2); ``` We can
|
142
|
+
now compute the alignment between the rows and columns in the two tables: ```js
|
143
|
+
var alignment = daff.compareTables(table1,table2).align(); ``` To produce a diff
|
144
|
+
from the alignment, we first need a table for the output: ```js var data_diff =
|
145
|
+
[]; var table_diff = new daff.TableView(data_diff); ``` Using default options for
|
146
|
+
the diff: ```js var flags = new daff.CompareFlags(); var highlighter = new daff.TableDiff(alignment,flags);
|
147
|
+
highlighter.hilite(table_diff); ``` The diff is now in `data_diff` in highlighter
|
148
|
+
format, see specification here: > http://share.find.coop/doc/spec_hilite.html ```js
|
149
|
+
[ [ ''!'', '''', ''+++'', '''' ], [ ''@@'', ''Country'', ''Code'', ''Capital'' ],
|
150
|
+
[ ''+'', ''Ireland'', ''ie'', ''Dublin'' ], [ ''+'', ''France'', ''fr'', ''Paris''
|
151
|
+
], [ ''->'', ''Spain'', ''es'', ''Barcelona->Madrid'' ], [ ''+++'', ''Germany'',
|
152
|
+
''de'', ''Berlin'' ] ] ``` For visualization, you may want to convert this to a
|
153
|
+
HTML table with appropriate classes on cells so you can color-code inserts, deletes,
|
154
|
+
updates, etc. You can do this with: ```js var diff2html = new daff.DiffRender();
|
155
|
+
diff2html.render(table_diff); var table_diff_html = diff2html.html(); ``` For 3-way
|
156
|
+
differences (that is, comparing two tables given knowledge of a common ancestor)
|
157
|
+
use `daff.compareTables3` (give ancestor table as the first argument). Here is
|
158
|
+
how to apply that difference as a patch: ```js var patcher = new daff.HighlightPatch(table1,table_diff);
|
159
|
+
patcher.apply(); // table1 should now equal table2 ``` Other languages --------------- The
|
160
|
+
`daff` library is written in [Haxe](http://haxe.org/), which can be translated reasonably
|
161
|
+
well into at least the following languages: * Javascript * PHP * Python * Java
|
162
|
+
* C# * C++ The Javascript translation is available via npm. PHP and C++ translations
|
163
|
+
are posted on the [Releases](https://github.com/paulfitz/daff/releases) page. To
|
164
|
+
make another translation, follow the [Haxe getting started tutorial](http://haxe.org/doc/start)
|
165
|
+
for the language you care about, then do one of: ``` make js make php make py make
|
166
|
+
java make cs make cpp ``` [@Floppy](https://github.com/Floppy) has made a lovingly-hand-written
|
167
|
+
[native Ruby port](https://github.com/theodi/coopy-ruby) that covers core functionality. I''ve
|
168
|
+
made a brutally-machine-converted [Ruby port](https://github.com/paulfitz/coopy-ruby)
|
169
|
+
that is a full translation but may include utter gibberish. For each language,
|
170
|
+
the `daff` library expects to be handed an interface to tables you create, rather
|
171
|
+
than creating them itself. This is to avoid inefficient copies from one format
|
172
|
+
to another. You''ll find a `SimpleTable` class you can use if you find this awkward. Reading
|
173
|
+
material ---------------- * http://dataprotocols.org/tabular-diff-format/ : a specification
|
174
|
+
of the diff format we use. * http://theodi.org/blog/csvhub-github-diffs-for-csv-files
|
175
|
+
: using this library with github. * http://theodi.org/blog/adapting-git-simple-data
|
176
|
+
: using this library with gitlab. * http://okfnlabs.org/blog/2013/08/08/diffing-and-patching-data.html
|
177
|
+
: a summary of where the library came from. * http://blog.okfn.org/2013/07/02/git-and-github-for-data/
|
178
|
+
: a post about storing small data in git/github. * http://blog.ouseful.info/2013/08/27/diff-or-chop-github-csv-data-files-and-openrefine/
|
179
|
+
: counterpoint - a post discussing tracked-changes rather than diffs. ## License daff
|
180
|
+
is distributed under the MIT License.'
|
181
|
+
test_files: []
|