Skip to content

Commit

Permalink
refactor, deps: update Sophia to 0.9 and mownstr to 0.3 and refactor …
Browse files Browse the repository at this point in the history
…Hdt_Graph accordingly, release 0.2.2
  • Loading branch information
KonradHoeffner committed Nov 22, 2024
1 parent 48a264b commit 63723ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hdt"
version = "0.2.1"
version = "0.2.2"
repository = "https://github.com/konradhoeffner/hdt"
authors = ["Tim Baccaert <tbaccaer@vub.be>", "Konrad Höffner"]
license = "MIT"
Expand All @@ -18,11 +18,11 @@ crc = "3"
iref = "3"
langtag = "0.4"
ntriple = "0.1"
sophia = { version = "0.8.0", optional = true }
sophia = { version = "0.9", optional = true }
sucds = "0.8"
thiserror = "2"
log = "0.4"
mownstr = "0.2"
mownstr = "0.3"
lazy_static = "1"
eyre = "0.6"

Expand Down
13 changes: 8 additions & 5 deletions src/hdt_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::four_sect_dict::IdKind;
use crate::hdt::Hdt;
use crate::triples::{Id, ObjectIter, PredicateIter, PredicateObjectIter, SubjectIter, TripleId};
use log::debug;
use sophia::api::graph::{GTripleSource, Graph};
use sophia::api::graph::Graph;
use sophia::api::term::{matcher::TermMatcher, BnodeId, IriRef, LanguageTag, Term};
use std::convert::Infallible;
use std::io::{self, Error, ErrorKind};
Expand Down Expand Up @@ -134,11 +134,11 @@ impl Graph for HdtGraph {
/// println!("{:?}", graph.triples().next().expect("no triple in the graph"));
/// }
/// ```
fn triples(&self) -> GTripleSource<Self> {
fn triples(&self) -> impl Iterator<Item = Result<Self::Triple<'_>, Self::Error>> {
debug!("Iterating through ALL triples in the HDT Graph. This can be inefficient for large graphs.");
Box::new(self.hdt.triples().map(move |(s, p, o)| {
self.hdt.triples().map(move |(s, p, o)| {
Ok([auto_term(&s).unwrap(), HdtTerm::Iri(IriRef::new_unchecked(p)), auto_term(&o).unwrap()])
}))
})
}

/// Only supports constant and "any" matchers.
Expand All @@ -156,7 +156,10 @@ impl Graph for HdtGraph {
/// let persons = dbpedia.triples_matching(Any, Some(birth_place), Some(leipzig));
/// }
/// ```
fn triples_matching<'s, S, P, O>(&'s self, sm: S, pm: P, om: O) -> GTripleSource<'s, Self>
#[allow(refining_impl_trait)]
fn triples_matching<'s, S, P, O>(
&'s self, sm: S, pm: P, om: O,
) -> Box<dyn Iterator<Item = Result<Self::Triple<'s>, Self::Error>> + 's>
where
S: TermMatcher + 's,
P: TermMatcher + 's,
Expand Down
8 changes: 4 additions & 4 deletions src/hdt_graph/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ impl Term for HdtTerm {

fn iri(&self) -> Option<sophia::api::term::IriRef<mownstr::MownStr>> {
match self {
HdtTerm::Iri(iri) => Some(iri.as_ref().map_unchecked(MownStr::from_str)),
HdtTerm::Iri(iri) => Some(iri.as_ref().map_unchecked(MownStr::from_ref)),
_ => None,
}
}

fn bnode_id(&self) -> Option<BnodeId<mownstr::MownStr>> {
match self {
HdtTerm::BlankNode(bnid) => Some(bnid.as_ref().map_unchecked(MownStr::from_str)),
HdtTerm::BlankNode(bnid) => Some(bnid.as_ref().map_unchecked(MownStr::from_ref)),
_ => None,
}
}
Expand All @@ -86,15 +86,15 @@ impl Term for HdtTerm {

fn datatype(&self) -> Option<sophia::api::term::IriRef<mownstr::MownStr>> {
match self {
HdtTerm::LiteralDatatype(_, datatype) => Some(datatype.as_ref().map_unchecked(MownStr::from_str)),
HdtTerm::LiteralDatatype(_, datatype) => Some(datatype.as_ref().map_unchecked(MownStr::from_ref)),
HdtTerm::LiteralLanguage(..) => rdf::langString.iri(),
_ => None,
}
}

fn language_tag(&self) -> Option<LanguageTag<mownstr::MownStr>> {
match self {
HdtTerm::LiteralLanguage(_, tag) => Some(tag.as_ref().map_unchecked(MownStr::from_str)),
HdtTerm::LiteralLanguage(_, tag) => Some(tag.as_ref().map_unchecked(MownStr::from_ref)),
_ => None,
}
}
Expand Down

0 comments on commit 63723ba

Please sign in to comment.