From 2a310adb2853e080b8a39d3e947465e894f1520b Mon Sep 17 00:00:00 2001 From: Cyril Matthey-Doret Date: Fri, 9 Aug 2024 13:26:29 +0000 Subject: [PATCH] refactor(cli): --config -> --rules (#48) --- README.md | 4 ++-- docs/tutorial.md | 2 +- src/io.rs | 12 ++++++------ src/main.rs | 6 +++--- src/pseudo.rs | 14 +++++++------- tests/data/{config.yaml => rules.yaml} | 0 6 files changed, 19 insertions(+), 19 deletions(-) rename tests/data/{config.yaml => rules.yaml} (100%) diff --git a/README.md b/README.md index a1dfa7b..e0aa96e 100644 --- a/README.md +++ b/README.md @@ -108,10 +108,10 @@ Indexing only requires an RDF file as input: tripsu index input.nt > index.nt ``` -Pseudonymization requires an RDF file, index and config as input: +Pseudonymization requires an RDF file, index and rules configuration as input: ```shell -tripsu pseudo --index index.nt --config rules.yaml input.nt > output.nt +tripsu pseudo --index index.nt --rules rules.yaml input.nt > output.nt ``` By default, pseudonymization uses a random key. To make the process diff --git a/docs/tutorial.md b/docs/tutorial.md index ab10218..607d7f2 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -8,7 +8,7 @@ on a large graph and we would like to pseudonymize some of the triples. This is how the flow should look like: ```shell -curl | tripsu pseudo -x index.nt -c config.yaml > pseudo.nt +curl | tripsu pseudo -x index.nt -r rules.yaml > pseudo.nt ``` For this flow to stream data instead of loading everything into memory, note diff --git a/src/io.rs b/src/io.rs index d199248..a4d05b1 100644 --- a/src/io.rs +++ b/src/io.rs @@ -43,9 +43,9 @@ pub fn parse_ntriples(reader: impl BufRead) -> NTriplesParser { } // Parse yaml configuration file. -pub fn parse_config(path: &Path) -> Rules { +pub fn parse_rules(path: &Path) -> Rules { return match File::open(path) { - Ok(file) => serde_yml::from_reader(file).expect("Error parsing config file."), + Ok(file) => serde_yml::from_reader(file).expect("Error parsing rules file."), Err(e) => panic!("Cannot open file '{:?}': '{}'.", path, e), }; } @@ -62,7 +62,7 @@ pub fn read_bytes(path: &PathBuf) -> Vec { #[cfg(test)] mod tests { - use super::{parse_config, parse_ntriples}; + use super::{parse_ntriples, parse_rules}; use rio_api::parser::TriplesParser; use std::{ io::{BufRead, BufReader}, @@ -86,8 +86,8 @@ mod tests { } // Test the parsing of a config file. #[test] - fn config_parsing() { - let config_path = Path::new("tests/data/config.yaml"); - parse_config(&config_path); + fn rules_parsing() { + let config_path = Path::new("tests/data/rules.yaml"); + parse_rules(&config_path); } } diff --git a/src/main.rs b/src/main.rs index d754fef..09cc481 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,10 +51,10 @@ struct PseudoArgs { #[arg(default_value = "-")] input: PathBuf, - /// The config file descriptor to use for defining RDF elements to pseudonymize. + /// File defining which RDF elements to pseudonymize. /// Format: yaml #[arg(short, long)] - config: PathBuf, + rules: PathBuf, /// Output file descriptor for pseudonymized triples. /// Defaults to `stdout`. @@ -94,7 +94,7 @@ fn main() { pseudonymize_graph( &log, &args.input, - &args.config, + &args.rules, &args.output, &args.index, &args.secret, diff --git a/src/pseudo.rs b/src/pseudo.rs index 1343885..6fbca0a 100644 --- a/src/pseudo.rs +++ b/src/pseudo.rs @@ -56,16 +56,16 @@ fn load_type_map(input: impl BufRead) -> HashMap { pub fn pseudonymize_graph( _: &Logger, input: &Path, - config: &Path, + rules_path: &Path, output: &Path, - index: &Path, + index_path: &Path, secret_path: &Option, ) { let buf_input = io::get_reader(input); - let buf_index = io::get_reader(index); + let buf_index = io::get_reader(index_path); let mut buf_output = io::get_writer(output); - let rules_config = io::parse_config(config); + let rules = io::parse_rules(rules_path); let node_to_type: HashMap = load_type_map(buf_index); let secret = secret_path.as_ref().map(io::read_bytes); @@ -79,7 +79,7 @@ pub fn pseudonymize_graph( .parse_step(&mut |t: TripleView| { process_triple( t.into(), - &rules_config, + &rules, &node_to_type, &mut buf_output, &pseudonymizer, @@ -107,14 +107,14 @@ mod tests { let dir = tempdir().unwrap(); let input_path = Path::new("tests/data/test.nt"); - let config_path = Path::new("tests/data/config.yaml"); + let rules_path = Path::new("tests/data/rules.yaml"); let output_path = dir.path().join("output.nt"); let type_map_path = Path::new("tests/data/type_map.nt"); let key = None; pseudonymize_graph( &logger, &input_path, - &config_path, + &rules_path, &output_path, &type_map_path, &key, diff --git a/tests/data/config.yaml b/tests/data/rules.yaml similarity index 100% rename from tests/data/config.yaml rename to tests/data/rules.yaml