-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
67 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
use slog::{self, o, Drain}; | ||
use slog_async; | ||
use std::{io, sync::Arc}; | ||
|
||
pub type Logger = slog::Logger; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
use rio_api::{model::Triple, parser::TriplesParser}; | ||
use rayon::prelude::*; | ||
use rio_api::parser::TriplesParser; | ||
use rio_turtle::TurtleError; | ||
use std::{ | ||
io::{stdin, BufRead, BufReader, Write}, | ||
path::Path, | ||
}; | ||
use std::{io::Write, path::Path, sync::Mutex}; | ||
|
||
use crate::io; | ||
use crate::{ | ||
io, | ||
rdf_types::{Triple, TripleView}, | ||
}; | ||
|
||
fn index_triple(t: Triple, out: &mut impl Write) -> Result<(), TurtleError> { | ||
match t.predicate.iri { | ||
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" => { | ||
let _ = out.write(&format!("{} .\n", &t.to_string()).into_bytes()); | ||
fn index_triple(t: Triple, out: &mut impl Write) { | ||
if t.predicate.iri.as_str() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" { | ||
if let Err(e) = out.write(&format!("{} .\n", &t.to_string()).into_bytes()) { | ||
panic!("Error writting to out buffer: {e}"); | ||
} | ||
_ => {} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn create_type_map(input: &Path, output: &Path) { | ||
let buf_in = io::get_reader(input); | ||
let mut buf_out = io::get_writer(output); | ||
let mut triples = io::parse_ntriples(buf_in); | ||
while !triples.is_end() { | ||
triples | ||
.parse_step(&mut |t| index_triple(t, &mut buf_out)) | ||
.unwrap(); | ||
} | ||
let buf_out = Mutex::new(io::get_writer(output)); | ||
let triples = io::parse_ntriples(buf_in); | ||
|
||
// Make a parallel triple iterator over `rdf_types::Triple`. | ||
// We have to wrap the `buf_out` with a `Mutex` to make it | ||
// writable by multiple threads. | ||
// NOTE: Weird `rio_api::into_iter` implementation, why does it use a full-blown | ||
// `Vec<T>`, this could be simpler. | ||
// | ||
let it = triples | ||
.into_iter(|t: TripleView| Result::<Triple, TurtleError>::Ok(t.into())) | ||
.par_bridge(); | ||
|
||
// Iterate in parallel over the triples. | ||
it.for_each(|t| match t { | ||
Ok(t) => { | ||
let mut guard = buf_out.lock().unwrap(); | ||
index_triple(t, guard.by_ref()) | ||
} | ||
Err(t) => panic!("Parsing error occured: {t}"), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters