Skip to content

Commit

Permalink
more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pchampin committed Oct 15, 2024
1 parent 48c8462 commit ffb3944
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion isomorphism/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn make_map<'a, T: Term>(

fn make_equivalence_classes(map: &HashMap<&str, u64>) -> HashMap<u64, usize> {
let mut ret = HashMap::new();
for (_, v) in map {
for v in map.values() {
let n = ret.entry(*v).or_insert(0);
*n += 1;
}
Expand Down
8 changes: 5 additions & 3 deletions resource/src/loader/_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use sophia_iri::Iri;
use sophia_jsonld::loader_factory::ClosureLoaderFactory;
use sophia_turtle::parser::{nt, turtle};
use std::borrow::Borrow;
use std::convert::Into;
use std::io;
use std::string::ToString;
use std::sync::Arc;

/// A loader resolves URLs into [`Resource`]s.
Expand All @@ -38,7 +40,7 @@ pub trait Loader: Sync + Sized {
let bufread = io::BufReader::new(&data[..]);
match &ctype[..] {
"text/turtle" => turtle::TurtleParser {
base: Some(iri.as_ref().map_unchecked(std::string::ToString::to_string)),
base: Some(iri.as_ref().map_unchecked(ToString::to_string)),
}
.parse(bufread)
.collect_triples()
Expand All @@ -54,7 +56,7 @@ pub trait Loader: Sync + Sized {
use sophia_api::prelude::{Quad, QuadParser, QuadSource};
use sophia_jsonld::{loader::ClosureLoader, JsonLdOptions, JsonLdParser};
let options = JsonLdOptions::new()
.with_base(iri.as_ref().map_unchecked(std::convert::Into::into))
.with_base(iri.as_ref().map_unchecked(Into::into))
.with_document_loader_factory(ClosureLoaderFactory::new(|| {
ClosureLoader::new(|url| {
async move {
Expand All @@ -79,7 +81,7 @@ pub trait Loader: Sync + Sized {

#[cfg(feature = "xml")]
"application/rdf+xml" => sophia_xml::parser::RdfXmlParser {
base: Some(iri.as_ref().map_unchecked(std::string::ToString::to_string)),
base: Some(iri.as_ref().map_unchecked(ToString::to_string)),
}
.parse(bufread)
.collect_triples()
Expand Down
15 changes: 7 additions & 8 deletions sophia/examples/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() {
.to_string();
}

let base = Some(if let Some(iri) = std::env::var_os("SOPHIA_BASE") {
let base = if let Some(iri) = std::env::var_os("SOPHIA_BASE") {
let iri = iri
.into_string()
.expect("Invalid UTF-8 data in SOPHIA_BASE");
Expand All @@ -72,19 +72,18 @@ fn main() {
Iri::new(url.into()).expect("Invalid file: IRI")
} else {
Iri::new_unchecked("x-stdin://localhost/".into())
});
};
let input = Input::new(path);
let res = match &format[..] {
"ntriples" | "nt" => dump_triples(input, NTriplesParser {}),
"turtle" | "ttl" => dump_triples(input, TurtleParser { base }),
"turtle" | "ttl" => dump_triples(input, TurtleParser { base: Some(base) }),
"nquads" | "nq" => dump_quads(input, NQuadsParser {}),
"trig" => dump_quads(input, TriGParser { base }),
"trig" => dump_quads(input, TriGParser { base: Some(base) }),
"gnq" => dump_quads(input, GNQuadsParser {}),
"gtrig" => dump_quads(input, GTriGParser { base }),
"gtrig" => dump_quads(input, GTriGParser { base: Some(base) }),
#[cfg(feature = "jsonld")]
"json-ld" | "jsonld" => {
let options =
JsonLdOptions::new().with_base(base.unwrap().map_unchecked(std::sync::Arc::from));
let options = JsonLdOptions::new().with_base(base.map_unchecked(std::sync::Arc::from));
let loader_factory = sophia::jsonld::loader::FileUrlLoader::default;
#[cfg(feature = "http_client")]
let loader_factory = || {
Expand All @@ -97,7 +96,7 @@ fn main() {
dump_quads(input, JsonLdParser::new_with_options(options))
}
#[cfg(feature = "xml")]
"rdfxml" | "rdf" => dump_triples(input, RdfXmlParser { base }),
"rdfxml" | "rdf" => dump_triples(input, RdfXmlParser { base: Some(base) }),
_ => {
eprintln!("Unrecognized format: {format}");
std::process::exit(-1);
Expand Down
5 changes: 3 additions & 2 deletions turtle/src/serializer/trig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! [`BufWriter`]: https://doc.rust-lang.org/std/io/struct.BufWriter.html
use rio_turtle::TriGFormatter;
use sophia_api::prelude::Term;
use sophia_api::quad::Quad;
use sophia_api::serializer::{QuadSerializer, Stringifier};
use sophia_api::source::{QuadSource, SinkError, SourceError, StreamResult};
Expand Down Expand Up @@ -66,8 +67,8 @@ where
source
.for_each_quad(|t| {
let (spo, g) = t.spog();
let spo = spo.map(sophia_api::prelude::Term::into_term);
let g = g.map(sophia_api::prelude::Term::into_term);
let spo = spo.map(Term::into_term);
let g = g.map(Term::into_term);
dataset.insert((g, spo));
})
.map_err(SourceError)?;
Expand Down

0 comments on commit ffb3944

Please sign in to comment.