triplify 0.2.0__tar.gz → 0.2.1__tar.gz
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.
- {triplify-0.2.0 → triplify-0.2.1}/Cargo.lock +6 -14
- {triplify-0.2.0 → triplify-0.2.1}/Cargo.toml +7 -2
- {triplify-0.2.0 → triplify-0.2.1}/PKG-INFO +1 -1
- {triplify-0.2.0 → triplify-0.2.1}/README.md +11 -3
- {triplify-0.2.0 → triplify-0.2.1}/src/emit.rs +28 -1
- {triplify-0.2.0 → triplify-0.2.1}/src/main.rs +13 -1
- {triplify-0.2.0 → triplify-0.2.1}/src/reader/csv.rs +2 -1
- {triplify-0.2.0 → triplify-0.2.1}/src/reader/mod.rs +26 -12
- {triplify-0.2.0 → triplify-0.2.1}/src/reader/parquet.rs +2 -2
- {triplify-0.2.0 → triplify-0.2.1}/src/reader/spreadsheet.rs +2 -1
- {triplify-0.2.0 → triplify-0.2.1}/src/triplify.rs +13 -2
- {triplify-0.2.0 → triplify-0.2.1}/src/writer.rs +2 -1
- {triplify-0.2.0 → triplify-0.2.1}/LICENSE +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/packaging/PYPI_README.md +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/pyproject.toml +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/encode.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/formula.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/git.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/iri.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/lib.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/location.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/profile.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/s3.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/source.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/vocab.rs +0 -0
- {triplify-0.2.0 → triplify-0.2.1}/src/walk.rs +0 -0
|
@@ -1513,7 +1513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
1513
1513
|
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
|
|
1514
1514
|
dependencies = [
|
|
1515
1515
|
"crc32fast",
|
|
1516
|
-
"libz-sys",
|
|
1516
|
+
"libz-ng-sys",
|
|
1517
1517
|
"miniz_oxide",
|
|
1518
1518
|
"zlib-rs",
|
|
1519
1519
|
]
|
|
@@ -2421,7 +2421,7 @@ dependencies = [
|
|
|
2421
2421
|
"core_affinity",
|
|
2422
2422
|
"flate2",
|
|
2423
2423
|
"flume 0.11.1",
|
|
2424
|
-
"libz-sys",
|
|
2424
|
+
"libz-ng-sys",
|
|
2425
2425
|
"log",
|
|
2426
2426
|
"num_cpus",
|
|
2427
2427
|
"thiserror",
|
|
@@ -3053,15 +3053,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
3053
3053
|
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
|
3054
3054
|
|
|
3055
3055
|
[[package]]
|
|
3056
|
-
name = "libz-sys"
|
|
3056
|
+
name = "libz-ng-sys"
|
|
3057
3057
|
version = "1.1.33"
|
|
3058
3058
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3059
|
-
checksum = "
|
|
3059
|
+
checksum = "922f69da893772fd14ea9118138d1111f89830a9753438ddf69987f24600cb63"
|
|
3060
3060
|
dependencies = [
|
|
3061
|
-
"
|
|
3061
|
+
"cmake",
|
|
3062
3062
|
"libc",
|
|
3063
|
-
"pkg-config",
|
|
3064
|
-
"vcpkg",
|
|
3065
3063
|
]
|
|
3066
3064
|
|
|
3067
3065
|
[[package]]
|
|
@@ -4384,7 +4382,7 @@ dependencies = [
|
|
|
4384
4382
|
|
|
4385
4383
|
[[package]]
|
|
4386
4384
|
name = "triplify"
|
|
4387
|
-
version = "0.2.
|
|
4385
|
+
version = "0.2.1"
|
|
4388
4386
|
dependencies = [
|
|
4389
4387
|
"anyhow",
|
|
4390
4388
|
"arrow-array",
|
|
@@ -4533,12 +4531,6 @@ version = "0.1.1"
|
|
|
4533
4531
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
4534
4532
|
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|
4535
4533
|
|
|
4536
|
-
[[package]]
|
|
4537
|
-
name = "vcpkg"
|
|
4538
|
-
version = "0.2.15"
|
|
4539
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
4540
|
-
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
|
4541
|
-
|
|
4542
4534
|
[[package]]
|
|
4543
4535
|
name = "version_check"
|
|
4544
4536
|
version = "0.9.5"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "triplify"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.1"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.92"
|
|
6
6
|
description = "Triplify turns any tabular data dump (CSV, XLSX, Parquet, ...) into raw RDF using the EKGF Raw Data Ontology, with DCAT, PROV and git provenance, without any mapping"
|
|
@@ -10,6 +10,11 @@ repository = "https://github.com/EKGF/triplify"
|
|
|
10
10
|
include = ["/src/**", "/Cargo.toml", "/Cargo.lock", "/LICENSE", "/README.md"]
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
|
|
13
|
+
[package.metadata.binstall]
|
|
14
|
+
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }.{ archive-format }"
|
|
15
|
+
bin-dir = "{ bin }{ binary-ext }"
|
|
16
|
+
pkg-fmt = "zip"
|
|
17
|
+
|
|
13
18
|
[dependencies]
|
|
14
19
|
anyhow = "1"
|
|
15
20
|
arrow-array = "60.1"
|
|
@@ -29,7 +34,7 @@ csv-async = { version = "1.3", features = ["tokio"] }
|
|
|
29
34
|
flume = "0.12.0"
|
|
30
35
|
futures = "0.3"
|
|
31
36
|
gix = { version = "0.90", default-features = false, features = ["sha1", "revision"] }
|
|
32
|
-
gzp = { version = "2.0.4", default-features = false, features = ["
|
|
37
|
+
gzp = { version = "2.0.4", default-features = false, features = ["deflate_zlib_ng"] }
|
|
33
38
|
hex = "0.4"
|
|
34
39
|
ignore = "0.4.34"
|
|
35
40
|
itoa = "1.0.19"
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Triplify
|
|
2
2
|
|
|
3
|
+
[](https://github.com/EKGF/triplify/actions/workflows/ci.yml)
|
|
4
|
+
[](https://crates.io/crates/triplify)
|
|
5
|
+
[](https://pypi.org/project/triplify/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
3
8
|
Turn CSV files and spreadsheets into RDF, preserving their original structure and values.
|
|
4
9
|
|
|
5
10
|
Capture your source data without defining a mapping first. Use SPARQL and SHACL
|
|
@@ -34,9 +39,12 @@ Install the native executable with uv:
|
|
|
34
39
|
uv tool install triplify
|
|
35
40
|
```
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
On macOS and Linux you can also use `brew install ekgf/tap/triplify`.
|
|
43
|
+
|
|
44
|
+
Alternatively, use `pipx install triplify` or `pip install triplify`, or
|
|
45
|
+
`cargo binstall triplify` for the prebuilt executable through Cargo. Wheels
|
|
46
|
+
and prebuilt executables cover Linux and Windows (x86-64, ARM64) and macOS on
|
|
47
|
+
Apple silicon. On an Intel Mac, use `cargo install triplify --locked`. See [Install](https://ekgf.github.io/triplify/install/)
|
|
40
48
|
for platform support and source builds.
|
|
41
49
|
|
|
42
50
|
## License
|
|
@@ -263,17 +263,33 @@ impl GraphEmitter {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
/// Whether a table's first row names its columns.
|
|
267
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
268
|
+
pub enum Header {
|
|
269
|
+
/// The first row holds column names (`rdfs:label`), not data.
|
|
270
|
+
#[default]
|
|
271
|
+
FirstRow,
|
|
272
|
+
/// Every row is data; columns have no labels (`--no-header`).
|
|
273
|
+
Absent,
|
|
274
|
+
}
|
|
275
|
+
|
|
266
276
|
/// Emits one source graph: the source, its views, columns, rows and values.
|
|
267
277
|
#[derive(Debug)]
|
|
268
278
|
pub struct SourceEmitter {
|
|
269
279
|
iris: SourceIris,
|
|
270
280
|
out: GraphEmitter,
|
|
271
281
|
profile: bool,
|
|
282
|
+
header: Header,
|
|
272
283
|
}
|
|
273
284
|
|
|
274
285
|
impl SourceEmitter {
|
|
275
286
|
pub fn new(iris: SourceIris, out: GraphEmitter) -> Self {
|
|
276
|
-
Self {
|
|
287
|
+
Self {
|
|
288
|
+
iris,
|
|
289
|
+
out,
|
|
290
|
+
profile: false,
|
|
291
|
+
header: Header::FirstRow,
|
|
292
|
+
}
|
|
277
293
|
}
|
|
278
294
|
|
|
279
295
|
/// Profile every column (`--profile`).
|
|
@@ -282,6 +298,12 @@ impl SourceEmitter {
|
|
|
282
298
|
self
|
|
283
299
|
}
|
|
284
300
|
|
|
301
|
+
/// How readers of header-optional formats treat the first row.
|
|
302
|
+
pub fn with_header(mut self, header: Header) -> Self {
|
|
303
|
+
self.header = header;
|
|
304
|
+
self
|
|
305
|
+
}
|
|
306
|
+
|
|
285
307
|
pub fn iris(&self) -> &SourceIris { &self.iris }
|
|
286
308
|
|
|
287
309
|
pub fn out(&mut self) -> &mut GraphEmitter { &mut self.out }
|
|
@@ -317,6 +339,7 @@ impl SourceEmitter {
|
|
|
317
339
|
ViewEmitter {
|
|
318
340
|
iris,
|
|
319
341
|
view,
|
|
342
|
+
header: self.header,
|
|
320
343
|
out,
|
|
321
344
|
columns: Vec::new(),
|
|
322
345
|
row: None,
|
|
@@ -330,6 +353,7 @@ impl SourceEmitter {
|
|
|
330
353
|
pub struct ViewEmitter<'a> {
|
|
331
354
|
iris: ViewIris,
|
|
332
355
|
view: Node,
|
|
356
|
+
header: Header,
|
|
333
357
|
out: &'a mut GraphEmitter,
|
|
334
358
|
/// Declared columns; index `c - 1` holds column `c`.
|
|
335
359
|
columns: Vec<Node>,
|
|
@@ -339,6 +363,9 @@ pub struct ViewEmitter<'a> {
|
|
|
339
363
|
}
|
|
340
364
|
|
|
341
365
|
impl ViewEmitter<'_> {
|
|
366
|
+
/// The configured header mode, for formats where it is optional.
|
|
367
|
+
pub fn header(&self) -> Header { self.header }
|
|
368
|
+
|
|
342
369
|
pub fn out(&mut self) -> &mut GraphEmitter { self.out }
|
|
343
370
|
|
|
344
371
|
fn column_count(&self) -> u32 { self.columns.len() as u32 }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
use {
|
|
2
2
|
clap::Parser,
|
|
3
|
-
triplify::{Triplify, location::Location, writer::Output},
|
|
3
|
+
triplify::{Triplify, emit::Header, location::Location, writer::Output},
|
|
4
4
|
};
|
|
5
5
|
|
|
6
6
|
/// Turn every CSV/TSV/XLSX/XLS/ODS/Parquet file under the given paths or S3
|
|
@@ -29,6 +29,11 @@ struct Cli {
|
|
|
29
29
|
#[arg(long)]
|
|
30
30
|
profile: bool,
|
|
31
31
|
|
|
32
|
+
/// CSV/TSV files and worksheets have no header row: the first row is
|
|
33
|
+
/// data and columns get no labels. Parquet always uses its schema.
|
|
34
|
+
#[arg(long)]
|
|
35
|
+
no_header: bool,
|
|
36
|
+
|
|
32
37
|
#[command(flatten)]
|
|
33
38
|
verbose: clap_verbosity_flag::Verbosity<clap_verbosity_flag::WarnLevel>,
|
|
34
39
|
}
|
|
@@ -57,6 +62,13 @@ async fn main() -> anyhow::Result<()> {
|
|
|
57
62
|
};
|
|
58
63
|
let summary = Triplify::new(cli.paths, output)
|
|
59
64
|
.with_profile(cli.profile)
|
|
65
|
+
.with_header(
|
|
66
|
+
if cli.no_header {
|
|
67
|
+
Header::Absent
|
|
68
|
+
} else {
|
|
69
|
+
Header::FirstRow
|
|
70
|
+
},
|
|
71
|
+
)
|
|
60
72
|
.run()
|
|
61
73
|
.await?;
|
|
62
74
|
tracing::info!(?summary, "done");
|
|
@@ -23,7 +23,8 @@ pub async fn read(
|
|
|
23
23
|
let mut records = reader.byte_records();
|
|
24
24
|
{
|
|
25
25
|
let mut view = emitter.view(ViewNumber(1), None);
|
|
26
|
-
let
|
|
26
|
+
let header = view.header();
|
|
27
|
+
let mut table = TableBuilder::new(&mut view, header);
|
|
27
28
|
let mut row: u64 = 0;
|
|
28
29
|
while let Some(record) = records.next().await {
|
|
29
30
|
let record = record?;
|
|
@@ -7,7 +7,7 @@ mod spreadsheet;
|
|
|
7
7
|
|
|
8
8
|
use {
|
|
9
9
|
crate::{
|
|
10
|
-
emit::{CellValue, SourceEmitter, ViewEmitter},
|
|
10
|
+
emit::{CellValue, Header, SourceEmitter, ViewEmitter},
|
|
11
11
|
formula::{Formula, R1C1},
|
|
12
12
|
iri::{ColumnNumber, ContentDigest, RowNumber},
|
|
13
13
|
s3::{S3Store, S3Url},
|
|
@@ -145,6 +145,7 @@ impl<R: AsyncRead + Unpin> AsyncRead for Verified<R> {
|
|
|
145
145
|
/// Turns a row-major stream of `(physical row, physical column, cell)` into
|
|
146
146
|
/// raw columns, rows and values. The first physical row seen is the header.
|
|
147
147
|
pub(crate) struct TableBuilder<'v, 'e> {
|
|
148
|
+
header_mode: Header,
|
|
148
149
|
view: &'v mut ViewEmitter<'e>,
|
|
149
150
|
header_row: Option<u64>,
|
|
150
151
|
header: BTreeMap<u32, String>,
|
|
@@ -154,12 +155,14 @@ pub(crate) struct TableBuilder<'v, 'e> {
|
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
impl<'v, 'e> TableBuilder<'v, 'e> {
|
|
157
|
-
pub fn new(view: &'v mut ViewEmitter<'e
|
|
158
|
+
pub fn new(view: &'v mut ViewEmitter<'e>, header: Header) -> Self {
|
|
158
159
|
Self {
|
|
159
160
|
view,
|
|
161
|
+
header_mode: header,
|
|
160
162
|
header_row: None,
|
|
161
163
|
header: BTreeMap::new(),
|
|
162
|
-
|
|
164
|
+
// Without a header row there is nothing to wait for.
|
|
165
|
+
header_done: header == Header::Absent,
|
|
163
166
|
current_row: None,
|
|
164
167
|
column_formulas: BTreeMap::new(),
|
|
165
168
|
}
|
|
@@ -192,17 +195,28 @@ impl<'v, 'e> TableBuilder<'v, 'e> {
|
|
|
192
195
|
cell: CellValue,
|
|
193
196
|
formula: Option<Formula>,
|
|
194
197
|
) {
|
|
195
|
-
|
|
198
|
+
// The first physical row seen: the header row, or data row 0.
|
|
199
|
+
let first = *self.header_row.get_or_insert(row);
|
|
196
200
|
let physical = (row, column);
|
|
197
201
|
let column = ColumnNumber(column + 1);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
let row = match self.header_mode {
|
|
203
|
+
Header::FirstRow => {
|
|
204
|
+
if row <= first {
|
|
205
|
+
if row == first {
|
|
206
|
+
self.header.insert(column.0, cell.header_text());
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
self.finish_header();
|
|
211
|
+
RowNumber(row - first - 1)
|
|
212
|
+
},
|
|
213
|
+
Header::Absent => {
|
|
214
|
+
if row < first {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
RowNumber(row - first)
|
|
218
|
+
},
|
|
219
|
+
};
|
|
206
220
|
if self.current_row != Some(row.0) {
|
|
207
221
|
self.current_row = Some(row.0);
|
|
208
222
|
self.view.row(row);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
use {
|
|
9
9
|
super::TableBuilder,
|
|
10
10
|
crate::{
|
|
11
|
-
emit::{CellValue, SourceEmitter},
|
|
11
|
+
emit::{CellValue, Header, SourceEmitter},
|
|
12
12
|
iri::ViewNumber,
|
|
13
13
|
s3::{S3ObjectMeta, S3Store, S3Url},
|
|
14
14
|
},
|
|
@@ -77,7 +77,7 @@ fn read_blocking<T: ChunkReader + 'static>(
|
|
|
77
77
|
let schema = reader.schema();
|
|
78
78
|
{
|
|
79
79
|
let mut view = emitter.view(ViewNumber(1), None);
|
|
80
|
-
let mut table = TableBuilder::new(&mut view);
|
|
80
|
+
let mut table = TableBuilder::new(&mut view, Header::FirstRow);
|
|
81
81
|
for (c, field) in schema.fields().iter().enumerate() {
|
|
82
82
|
table.cell(
|
|
83
83
|
0,
|
|
@@ -103,7 +103,8 @@ fn read_blocking<RS: Read + Seek>(
|
|
|
103
103
|
let number = ViewNumber(u32::try_from(index + 1)?);
|
|
104
104
|
let mut view = emitter.view(number, Some(name));
|
|
105
105
|
let mut formulas = formulas(&mut workbook, name);
|
|
106
|
-
let
|
|
106
|
+
let header = view.header();
|
|
107
|
+
let mut table = TableBuilder::new(&mut view, header);
|
|
107
108
|
match &mut workbook {
|
|
108
109
|
// XLSX: true streaming, one cell at a time.
|
|
109
110
|
Sheets::Xlsx(xlsx) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
use {
|
|
4
4
|
crate::{
|
|
5
|
-
emit::{GraphEmitter, QuadSender, SourceEmitter},
|
|
5
|
+
emit::{GraphEmitter, Header, QuadSender, SourceEmitter},
|
|
6
6
|
iri::{ContentDigest, RunIri, SourceIris},
|
|
7
7
|
location::Location,
|
|
8
8
|
s3::S3Store,
|
|
@@ -41,6 +41,7 @@ pub struct Triplify {
|
|
|
41
41
|
store: Arc<S3Store>,
|
|
42
42
|
concurrency: usize,
|
|
43
43
|
profile: bool,
|
|
44
|
+
header: Header,
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
enum Outcome {
|
|
@@ -63,9 +64,17 @@ impl Triplify {
|
|
|
63
64
|
store: Arc::new(S3Store::default()),
|
|
64
65
|
concurrency,
|
|
65
66
|
profile: false,
|
|
67
|
+
header: Header::FirstRow,
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
/// Whether CSV/TSV files and worksheets start with a header row.
|
|
72
|
+
/// Parquet column names always come from its schema.
|
|
73
|
+
pub fn with_header(mut self, header: Header) -> Self {
|
|
74
|
+
self.header = header;
|
|
75
|
+
self
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
/// Compute column profiles (counts, inferred datatype, statistics).
|
|
70
79
|
pub fn with_profile(mut self, profile: bool) -> Self {
|
|
71
80
|
self.profile = profile;
|
|
@@ -190,7 +199,9 @@ impl Triplify {
|
|
|
190
199
|
source.describe(&iris, &mut out);
|
|
191
200
|
let emitter = crate::reader::read(
|
|
192
201
|
&source,
|
|
193
|
-
SourceEmitter::new(iris.clone(), out)
|
|
202
|
+
SourceEmitter::new(iris.clone(), out)
|
|
203
|
+
.with_profile(self.profile)
|
|
204
|
+
.with_header(self.header),
|
|
194
205
|
&self.store,
|
|
195
206
|
)
|
|
196
207
|
.await?;
|
|
@@ -297,7 +297,8 @@ impl Output {
|
|
|
297
297
|
};
|
|
298
298
|
let threads =
|
|
299
299
|
std::thread::available_parallelism().map_or(4, |n| n.get());
|
|
300
|
-
// Level 6, as gzip and the single-threaded encoder default to.
|
|
300
|
+
// Level 6, as gzip and the single-threaded encoder default to. With
|
|
301
|
+
// zlib-ng it costs half the CPU of zlib at a slightly better ratio.
|
|
301
302
|
let mut gz: ParCompress<Gzip, _> = ParCompressBuilder::new()
|
|
302
303
|
.compression_level(gzp::Compression::new(6))
|
|
303
304
|
.num_threads(threads)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|