Skip to content

Commit

Permalink
refactor: rio parsing (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdoret authored and supermaxiste committed Jun 24, 2024
1 parent be3c2ac commit 126f7db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_yml;
use std::{
boxed::Box,
fs::File,
io::{stdin, stdout, BufRead, BufReader, BufWriter, Write},
io::{BufRead, BufReader},
path::Path,
};

Expand All @@ -27,8 +27,7 @@ pub fn get_writer(path: &Path) -> Box<dyn Write> {
}

// Parse RDF triples.
// This function takes ownership of a generic type which implements `BufRead`.
pub fn parse_ntriples(reader: impl BufRead) -> NTriplesParser<impl BufRead> {
pub fn parse_ntriples(reader: Box<dyn BufRead>) -> NTriplesParser<Box<dyn BufRead>> {
return NTriplesParser::new(reader);
}

Expand Down
3 changes: 3 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ bitflags::bitflags! {
}
}


impl TripleMask {

// Checks if bit from another mask are all set in this mask
pub fn is_set(&self, other: &TripleMask) -> bool {
return (*other - *self).bits() != 0;
}

}

// Pseudonymize parts of a triple set by its mask
Expand Down
14 changes: 14 additions & 0 deletions src/pass_second.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ use crate::{
model::{pseudonymize_triple, TripleMask},
};

// mask and encode input triple
// NOTE: This will need the type-map to perform masking
fn process_triple(triple: &Triple) -> Result<(), TurtleError> {
let mask = TripleMask::SUBJECT;
println!("{}", pseudonymize_triple(&triple, mask).to_string());
Ok(())
}

fn mask_triple(triple: &Triple) -> TripleMask {
return TripleMask::SUBJECT;
}
Expand Down Expand Up @@ -46,13 +54,19 @@ pub fn pseudonymize_graph(log: &Logger, input: &Path, output: &Path, index: &Pat
let buf_index = io::get_reader(index);
let mut buf_output = io::get_writer(output);
let config = io::parse_config(config);
<<<<<<< HEAD

let node_to_type: HashMap<String, String> = load_type_map(buf_index);
let mut triples = io::parse_ntriples(buf_input);
while !triples.is_end() {
triples
.parse_step(&mut |t| process_triple(&t, &mut buf_output))
.unwrap();
=======
let mut triples = io::parse_ntriples(buffer);
while !triples.is_end() {
triples.parse_step(&mut |t| process_triple(&t)).unwrap();
>>>>>>> cb9b7eb (refactor: rio parsing (#13))
}
}
#[cfg(test)]
Expand Down

0 comments on commit 126f7db

Please sign in to comment.