10 releases
Uses new Rust 2021
new 0.0.12 | Jan 23, 2023 |
---|---|
0.0.11 | Jan 5, 2023 |
0.0.8 | Dec 22, 2022 |
0.0.5 | Nov 30, 2022 |
0.0.0 |
|
#90 in Compression
208 downloads per month
Used in rickview
115KB
2K
SLoC
HDT
A Rust library for the Header Dictionary Triples compressed RDF format, including:
- loading the HDT default format as created by hdt-cpp
- efficient querying by triple patterns
- serializing into other formats like RDF Turtle and N-Triples using the Sophia adapter
However it cannot:
- load other RDF formats
- load other HDT variants
For this functionality and acknowledgement of all the original authors, please look at the reference implementations in C++ and Java by the https://github.com/rdfhdt organisation.
It also cannot:
- swap data to disk
- modify the RDF graph in memory
- run SPARQL queries
If you need any of the those features, consider using a SPARQL endpoint instead.
Examples
[dependencies]
hdt = "0.0.12"
use hdt::Hdt;
let file = std::fs::File::open("example.hdt").expect("error opening file");
let hdt = Hdt::Rc<str>::new(std::io::BufReader::new(file)).expect("error loading HDT");
// query
let majors = hdt.triples_with_sp("http://dbpedia.org/resource/Leipzig", "http://dbpedia.org/ontology/major");
println!("{:?}", majors.collect::<Vec<_>>());
You can also use the Sophia adapter to load HDT files and reduce memory consumption of an existing application based on Sophia:
use hdt::{Hdt,HdtGraph};
use sophia::term::BoxTerm;
use sophia::graph::Graph;
let file = std::fs::File::open("dbpedia.hdt").expect("error opening file");
let hdt = Hdt::<std::rc::Rc<str>>::new(std::io::BufReader::new(file)).expect("error loading HDT");
let graph = HdtGraph::new(hdt);
let s = BoxTerm::new_iri_unchecked("http://dbpedia.org/resource/Leipzig");
let p = BoxTerm::new_iri_unchecked("http://dbpedia.org/ontology/major");
let majors = graph.triples_with_sp(&s,&p);
If you don't want to pull in the Sophia dependency, you can exclude the adapter:
[dependencies]
hdt = { version = "0.0.12", default-features = false }
Dependencies
~4.5MB
~104K SLoC