Crate grdf

Source
Expand description

The Resource Description Framework (RDF) is a powerful method for modeling data and knowledge defined by the World Wide Web Consortium (W3C). A RDF dataset consists in a collection of graphs connecting nodes, values and predicates. This crate provides traits and implementations of Generalized RDF (gRDF) where nodes, values and predicates have the same representation.

Note that this crates requires rust compiler version 1.65 or later. It needs Generic Associated Typed (GAT) to work properly.

§Basic usage

§Exploring a dataset

Each Dataset implementation provides many iterators to explore the data. One simple way is to iterate through the quad of the dataset:

for Quad(subject, predicate, object, graph) in dataset {
  // do something
}

Another way is to access each graph individually using Dataset::graph. For a given graph, it is then possible to iterate through the triples of the graph:

let graph = dataset.graph(id).unwrap();

for Triple(subject, predicate, object) in graph {
  // do something
}

It is also possible to explore the graph logically, subject by subject, predicate by predicate, object by object:

// for each subject of the graph...
for (subject, predicates) in graph.subjects() {
  // for each predicate it is subject...
  for (predicate, objects) in predicates {
    // for each triple (subject, predicate, object)...
    for object in objects {
      // do something
    }
  }
}

§Inserting new data

Insertion can be done on MutableDataset implementations using MutableDataset::insert:

let mut dataset: HashDataset<Term> = HashDataset::new();
dataset.insert(Quad(subject, predicate, object, graph));

Again it is possible to access each graph of the dataset mutably:

let mut graph = dataset.graph_mut(id).unwrap();
graph.insert(Triple(subject, predicate, object));

§Custom RDF types

The types used to represent RDF subjects, predicate and objects are parameters of the dataset. Anything can be used although they default to the rdf_types::Term type that represents generic RDF nodes (blank nodes, IRI-named nodes and literal values).

Modules§

btree_dataset
Dataset implementation based on BTreeMap and BTreeSet.
hash_dataset
Dataset implementation based on HashMap and HashSet.
macros
utils

Macros§

reflect_dataset_impl
reflect_graph_impl
reflect_mutable_dataset_impl
reflect_sized_dataset_impl

Structs§

BTreeDataset
BTreeGraph
Graph implementation based on BTreeMap and BTreeSet.
GraphView
View a graph from the perspective of a single subject resource.
HashDataset
HashGraph
Graph implementation based on HashMap and HashSet.
IdentityAccess
Simple GraphAccess implementation for graphs such that Subject = Object.
Quad
RDF quad.
Triple
RDF triple.
View
View a dateset from the perspective of a single graph subject resource.

Traits§

Dataset
gRDF dataset.
DatasetAccess
Specifies how to access a dataset and reinterpret triples subjects as graph labels.
DatasetTake
Graph
gRDF graph.
GraphAccess
Specifies how to access a graph and reinterpret triples objects as subjects.
GraphTake
MutableDataset
Mutable dataset.
MutableGraph
Mutable gRDF graph.
SizedDataset
Sized gRDF dataset that can be converted into iterators.
SizedGraph
Sized gRDF graph that can be converted into iterators.