Struct hdt::hdt::Hdt

source ·
pub struct Hdt {
    pub dict: FourSectDict,
    pub triples: TriplesBitmap,
}
Expand description

In-memory representation of an RDF graph loaded from an HDT file. Allows queries by triple patterns.

Fields§

§dict: FourSectDict

in-memory representation of dictionary

§triples: TriplesBitmap

in-memory representation of triples

Implementations§

source§

impl Hdt

source

pub fn new<R: BufRead>(reader: R) -> Result<Self, Box<dyn Error>>

Creates an immutable HDT instance containing the dictionary and triples from the given reader. The reader must point to the beginning of the data of an HDT file as produced by hdt-cpp. FourSectionDictionary with DictionarySectionPlainFrontCoding and SPO order is the only supported implementation. The format is specified at https://www.rdfhdt.org/hdt-binary-format/, however there are some deviations. The initial HDT specification at http://www.w3.org/Submission/2011/03/ is outdated and not supported.

§Example
let file = std::fs::File::open("tests/resources/snikmeta.hdt").expect("error opening file");
let hdt = hdt::Hdt::new(std::io::BufReader::new(file)).unwrap();
source

pub fn size_in_bytes(&self) -> usize

Recursive size in bytes on the heap.

source

pub fn triples( &self ) -> impl Iterator<Item = (Arc<str>, Arc<str>, Arc<str>)> + '_

An iterator visiting all triples as strings in order. Using this method with a filter can be inefficient for large graphs, because the strings are stored in compressed form and must be decompressed and allocated. Whenever possible, use Hdt::triples_with_pattern instead.

§Example
fn print_first_triple(hdt: hdt::Hdt) {
    println!("{:?}", hdt.triples().next().expect("no triple in the graph"));
}
source

pub fn subjects_with_po( &self, p: &str, o: &str ) -> Box<dyn Iterator<Item = String> + '_>

Get all subjects with the given property and object (?PO pattern). Use this over triples_with_pattern(None,Some(p),Some(o)) if you don’t need whole triples.

§Example

Who was born in Leipzig?

fn query(dbpedia: hdt::Hdt) {
    for person in dbpedia.subjects_with_po(
      "http://dbpedia.org/ontology/birthPlace", "http://dbpedia.org/resource/Leipzig") {
      println!("{person:?}");
    }
}
source

pub fn triples_with_pattern<'a>( &'a self, sp: Option<&'a str>, pp: Option<&'a str>, op: Option<&'a str> ) -> Box<dyn Iterator<Item = (Arc<str>, Arc<str>, Arc<str>)> + '_>

Get all triples that fit the given triple patterns, where None stands for a variable. For example, triples_with_pattern(Some(s), Some(p), None) answers an SP? pattern.

§Example

What is the capital of the United States of America?

fn query(dbpedia: hdt::Hdt) {
  println!("{:?}", dbpedia.triples_with_pattern(
    Some("http://dbpedia.org/resource/United_States"), Some("http://dbpedia.org/ontology/capital"), None)
    .next().expect("no capital found").2);
}

Trait Implementations§

source§

impl Debug for Hdt

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Hdt

§

impl !RefUnwindSafe for Hdt

§

impl Send for Hdt

§

impl Sync for Hdt

§

impl Unpin for Hdt

§

impl !UnwindSafe for Hdt

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.