Crate rdftk_io[][src]

Expand description

io This crate provides traits for reading and writing Statements and Graphs as well as implementations of these for common representations.

The following are some well-known formats (see Wikipedia for a description of different serializations), support is indicated in the final column with an R for read support and W for write support. One additional module, dot allows for the creation of GraphViz dot files for a visualization of a graph’s structure.

ModuleNameMIME TypeR/W
ntRDF 1.1 N-Triples; A line-based syntax for an RDF graphapplication/n-triplesR+W
nqRDF 1.1 N-Quads; A line-based syntax for RDF datasetsapplication/n-quadsW
turtleRDF 1.1 Turtle; Terse RDF Triple Languagetext/turtleW
trigRDF 1.1 TriG; RDF Dataset Languageapplication/trig
xmlRDF 1.1 XML Syntaxapplication/rdf+xmlW
jsonRDF 1.1 JSON Alternate Serializationapplication/rdf+jsonW
n3Notation3 (N3): A readable RDF syntaxtext/rdf+n3W
TBDBinary RDF Representation for Publication and Exchange (HDT)N/A
TBDRDF Binary using Apache Thriftapplication/x-binary-rdf
TBDJSON-LD 1.1; A JSON-based Serialization for Linked Dataapplication/ld+json
TBDRDFa Core 1.1 - Third Editiontext/html

Each module will also provide public constants NAME, FILE_EXTENSION, and MIME_TYPE.

Example

An example, reading an existing NTriple file.

use rdftk_io::nt::reader::NTriplesReader;
use rdftk_io::GraphReader;
use rdftk_core::simple::graph_factory;
use std::fs::File;
use std::path::PathBuf;

let file_path = PathBuf::from("tests/w3c/nt/literal.nt");
let mut file = File::open(file_path).unwrap();
let reader = NTriplesReader::default();
let graph = reader.read(&mut file, graph_factory()).unwrap();

Modules

json

Provides for writing a Graph instance in the W3C RDF 1.1 JSON Alternate Serialization (RDF/JSON) format.

nq

Provides for reading and writing a Graph instance in the W3C RDF 1.1 N-Quads, a line-based syntax for RDF datasets, format.

nt

Provides for reading and writing a Graph instance in the W3C RDF 1.1 N-Triples, a line-based syntax for an RDF graph format.

xml

Provides for writing out in the RDF 1.1 XML Syntax format.

Traits

DataSetWriter

Write all Graphs in the DataSet using the provided implementation of Write.

GraphReader

Read an entire Graph from the provided implementation of Read.

GraphWriter

Write all Statements in the Graph using the provided implementation of Write.

Functions

write_data_set_to_string

A convenience function that will return a String containing the output of the NamedGraphWriter for the given NamedGraph instance.

write_graph_to_string

A convenience function that will return a String containing the output of the GraphWriter for the given Graph instance.