[][src]Crate sophia

This crate aims to provide a comprehensive toolkit for working with RDF and Linked Data in Rust.

RDF is a data model designed to exchange knowledge on the Web in an interoperable way. Each piece of knowledge in RDF (a statement) is represented by a triple, made of three terms. A set of triples forms an RDF graph. Finally, several graphs can be grouped in a collection called a dataset, where each graph is identified by a unique name.

Generalized vs. Strict RDF model

The data model supported by this crate is in fact a superset of the RDF data model as defined by the W3C. When the distinction matters, they will be called, respectively, the generalized RDF model, and the strict RDF model.

Getting Started

Following a short example how to build a graph, mutate it and serialize it back.

use sophia::graph::{*, inmem::LightGraph};
use sophia::ns::Namespace;
use sophia::parser;
use sophia::serializer::*;
use sophia::serializer::nt::NtSerializer;
use sophia::triple::stream::TripleSource;

let example = r#"
    @prefix : <http://example.org/>.
    @prefix foaf: <http://xmlns.com/foaf/0.1/>.

    :alice foaf:name "Alice";
           foaf:mbox <mailto:alice@work.example> .

    :bob foaf:name "Bob".
"#;
let mut graph = LightGraph::new();
parser::turtle::parse_str(example).in_graph(&mut graph);

let ex = Namespace::new("http://example.org/").unwrap();
let foaf = Namespace::new("http://xmlns.com/foaf/0.1/").unwrap();
let bob = ex.get("bob").unwrap();
let knows = foaf.get("known").unwrap();
let alice = ex.get("alice").unwrap();
graph.insert(&bob, &knows, &alice).unwrap();

let mut nt_stringifier = NtSerializer::new_stringifier();
let example2 = nt_stringifier.serialize_graph(&mut graph).unwrap().as_str();
println!("The resulting graph\n{}", example2);

Modules

dataset

An RDF dataset is composed of a default graph, and zero or more named graphs, each associated with a graph name.

graph

An RDF graph, the central notion of the RDF data model, is a collection of triples.

ns

Standard and custom namespaces.

parser

API for parsing RDF syntaxes.

quad

A quad expresses a single fact within a context. Quads are like RDF triples(../triple/index.html) augmented with an optional graph name.

query

Query processing over RDF graphs and datasets.

serializer

API for serializing RDF syntaxes.

term

Terms are the building blocks of an RDF graph. There are four types of terms: IRIs, blank nodes (BNode for short), literals and variables.

triple

An RDF triple expresses a single fact. Its formed of three terms called subject, predicate and object.

Macros

def_mod_functions_for_bufread_parser

Define convenience module-level functions for a parser implementation supporting BufRead.

impl_dataset_for_wrapper

Defines the implementation of Dataset for DatasetWrapper.

impl_graph_for_wrapper

Defines the implementation of Graph for GraphWrapper.

impl_indexed_dataset_for_wrapper

Defines the implementation of IndexedDataset for DatasetWrapper around another IndexedDataset.

impl_indexed_graph_for_wrapper

Defines the implementation of IndexedGraph for GraphWrapper around another IndexedGraph.

impl_mutable_dataset_for_indexed_dataset

Defines the implementation of MutableDataset for IndexedDataset.

impl_mutable_graph_for_indexed_graph

Defines the implementation of MutableGraph for IndexedGraph.

namespace

Helper for creating a "namespace module" defining a set of terms within a given IRI space.

ns_term

Helper for creating a term in a "namespace module". In general, you should use the namespace! macro instead.