Skip to content

Commit 7f52be6

Browse files
committed
update README with examples
1 parent 6784ad5 commit 7f52be6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,58 @@ Library for converting CSV files into RDF
33

44
This Rust-based tool converts CSV data into RDF format, utilizing the `oxrdf` crate for RDF graph handling and `csv` for efficient CSV parsing. Generated triples can either be added to an `oxrdf::Graph` or written directly to file.
55

6+
## Using the xml2rdf CLI
7+
8+
This library includes a CLI utility for parsing CSV and generating N-Triple RDF using the `convert` subcommand. The binary can be built using `cargo build`.
9+
10+
```bash
11+
$ csv2rdf convert --help
12+
Convert CSV to RDF format.
13+
14+
The `convert` command parses a CSV file, converts it to RDF triples using `csv` for parsing and `oxrdf` to construct the graph, and saves the output.
15+
16+
Usage: csv2rdf convert [OPTIONS]
17+
18+
Options:
19+
-n, --namespace <NAMESPACE>
20+
Namespace for RDF graph generation.
21+
22+
A custom namespace to prefix RDF resources created from CSV columns and rows.
23+
24+
[default: https://decisym.ai/csv2rdf/data]
25+
26+
-i, --input <INPUT>...
27+
Path to input CSV file(s).
28+
29+
Provide the path to one or more CSV files that will be parsed and converted.
30+
31+
-o, --output <OUTPUT>
32+
Path to output file.
33+
34+
Optional: Specify the path to save the generated RDF data. If not provided, data will be written to stdout
35+
36+
-h, --help
37+
Print help (see a summary with '-h')
38+
```
39+
40+
## Using the convert library
41+
42+
The conversion functionality can be also be called directly in Rust. The library supports writing results to a file or building an in-memory `oxrdf::Graph`.
43+
44+
```rust
45+
use csv2rdf::convert::parse_csv;
46+
use csv2rdf::writer;
47+
use oxrdf::Graph;
48+
49+
// capture conversion results to file
50+
let mut w = writer::FileWriter::to_file("output.nt".to_string()).unwrap();
51+
parse_csv(vec!["data.csv".to_string()], &mut w, "https://decisym.ai/csv2rdf/data");
52+
53+
// capture conversion results to an oxrdf::Graph
54+
let mut g = Graph::new();
55+
let mut w = writer::GraphWriter::new(&mut g);
56+
parse_csv(vec!["data.csv".to_string()], &mut w, "https://decisym.ai/csv2rdf/data");
57+
```
58+
659
## License
760
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)