Skip to content

Commit 3433405

Browse files
committed
documentation
1 parent c382457 commit 3433405

2 files changed

Lines changed: 54 additions & 17 deletions

File tree

src/convert.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
//! # CSV2RDF Converter Library
2+
//!
3+
//! This library provides functionality for converting CSV data into RDF format.
4+
//! It uses `csv` for XML parsing and `oxrdf` to build and manage RDF graphs.
5+
//!
6+
//! ## Overview
7+
//! - Converts CSV data structures into RDF triples, generating a graph representation.
8+
//!
9+
//! ## Features
10+
//! - Converts nested CSV Objects into RDF triples.
11+
//! - Allows specifying a custom RDF namespace for generated predicates and objects.
12+
//! - Outputs the RDF data to a specified file.
13+
114
use std::collections::HashMap;
215

316
use crate::writer::RdfWriter;
@@ -9,6 +22,30 @@ use uuid::Uuid;
922

1023
const C2R: &'static str = "https://decisym.ai/csv2rdf/model#";
1124

25+
/// Converts CSV data to RDF format.
26+
///
27+
/// This function reads CSV data from the specified file, processes it into RDF triples,
28+
/// and outputs the RDF graph. Users can specify a namespace to use for RDF predicates and
29+
/// an output file for saving the generated RDF data.
30+
///
31+
/// # Arguments
32+
/// - `files`: Path to the CSV files.
33+
/// - `namespace`: Optional custom namespace for RDF predicates.
34+
/// - `output`: use RdfWriter trait to add generated triples to desired format (File or Graph)
35+
///
36+
/// # Example
37+
/// ```rust
38+
/// use csv2rdf::convert::parse_csv;
39+
/// use csv2rdf::writer;
40+
/// use oxrdf::Graph;
41+
///
42+
/// let mut w = writer::FileWriter::to_file("output.nt".to_string()).unwrap();
43+
/// parse_csv(vec!["data.csv".to_string()], &mut w, "https://decisym.ai/csv2rdf/data");
44+
///
45+
/// let mut g = Graph::new();
46+
/// let mut w = writer::GraphWriter::new(&mut g);
47+
/// parse_csv(vec!["data.csv".to_string()], &mut w, "https://decisym.ai/csv2rdf/data");
48+
/// ```
1249
pub fn parse_csv(
1350
files: Vec<String>,
1451
output: &mut dyn RdfWriter,

src/main.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
//! # XML2RDF Converter
1+
//! # CSV2RDF Converter
22
//!
3-
//! This is a Rust-based tool that converts XML data into RDF format. It uses the `xml-rs` crate
4-
//! for XML parsing and the `oxrdf` crate to construct RDF triples and graphs.
3+
//! This is a Rust-based tool that converts CSV data into RDF format. It uses the `csv` crate
4+
//! for CSV parsing and the `oxrdf` crate to construct RDF triples and graphs.
55
//!
66
//! ## Features
7-
//! - Parses XML input and converts it to RDF triples
7+
//! - Parses CSV input and converts it to RDF triples
88
//! - Supports specifying a custom namespace for generated RDF nodes
99
//! - Outputs RDF data to a specified file, oxrdf::Graph or stdout
1010
//!
1111
//! ## Usage
12-
//! Run the XML2RDF converter from the command line. For detailed usage information, run:
12+
//! Run the CSV2RDF converter from the command line. For detailed usage information, run:
1313
//! ```
14-
//! xml2rdf --help
14+
//! csv2rdf --help
1515
//! ```
1616
//!
1717
//! ## Example
18-
//! To convert a XML file to RDF format with a specified namespace and output file:
18+
//! To convert a CSV file to RDF format with a specified namespace and output file:
1919
//! ```
20-
//! xml2rdf convert --namespace http://example.com/ns# --xml data.xml --output-file output.nt
20+
//! csv2rdf convert --namespace http://example.com/ns# --input data.xml --output output.nt
2121
//! ```
22-
//! This will take `data.xml`, apply the specified namespace, and save the RDF output in `output.nt`.
22+
//! This will take `data.csv`, apply the specified namespace, and save the RDF output in `output.nt`.
2323
2424
use clap::{Parser, Subcommand};
2525
use csv2rdf::*;
2626

27-
/// Command-line interface for XML2RDF Converter
27+
/// Command-line interface for CSV2RDF Converter
2828
///
29-
/// This struct defines the command-line interface (CLI) for interacting with the XML2RDF converter.
29+
/// This struct defines the command-line interface (CLI) for interacting with the CSV2RDF converter.
3030
#[derive(Parser)]
31-
#[command(version, about = "Converts XML data into RDF format.")]
31+
#[command(version, about = "Converts CSV data into RDF format.")]
3232
struct Cli {
3333
/// CLI command selection
3434
#[command(subcommand)]
@@ -37,12 +37,12 @@ struct Cli {
3737

3838
/// Supported Commands
3939
///
40-
/// Contains the available commands for the XML2RDF converter.
40+
/// Contains the available commands for the CSV2RDF converter.
4141
#[derive(Subcommand)]
4242
enum Commands {
43-
/// Convert XML to RDF format.
43+
/// Convert CSV to RDF format.
4444
///
45-
/// The `convert` command parses a XML file, converts it to RDF triples using `xml-rs` for parsing
45+
/// The `convert` command parses a CSV file, converts it to RDF triples using `csv` for parsing
4646
/// and `oxrdf` to construct the graph, and saves the output.
4747
Convert {
4848
/// Namespace for RDF graph generation.
@@ -51,9 +51,9 @@ enum Commands {
5151
#[arg(short, long, default_value = "https://decisym.ai/csv2rdf/data")]
5252
namespace: String,
5353

54-
/// Path to input XML file(s).
54+
/// Path to input CSV file(s).
5555
///
56-
/// Provide the path to one or more XML files that will be parsed and converted.
56+
/// Provide the path to one or more CSV files that will be parsed and converted.
5757
#[arg(short, long, num_args = 1..)]
5858
input: Vec<String>,
5959

0 commit comments

Comments
 (0)