parent
9da26c6f95
commit
7fe055d2b4
@ -0,0 +1,25 @@ |
|||||||
|
//! Implements data structures for [RDF 1.1 Concepts](https://www.w3.org/TR/rdf11-concepts/) using [OxRDF](https://crates.io/crates/oxrdf).
|
||||||
|
//!
|
||||||
|
//! Usage example:
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! use oxigraph::model::*;
|
||||||
|
//!
|
||||||
|
//! let mut graph = Graph::default();
|
||||||
|
//!
|
||||||
|
//! // insertion
|
||||||
|
//! let ex = NamedNodeRef::new("http://example.com").unwrap();
|
||||||
|
//! let triple = TripleRef::new(ex, ex, ex);
|
||||||
|
//! graph.insert(triple);
|
||||||
|
//!
|
||||||
|
//! // simple filter
|
||||||
|
//! let results: Vec<_> = graph.triples_for_subject(ex).collect();
|
||||||
|
//! assert_eq!(vec![triple], results);
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
pub use oxrdf::{ |
||||||
|
dataset, graph, vocab, BlankNode, BlankNodeIdParseError, BlankNodeRef, Dataset, Graph, |
||||||
|
GraphName, GraphNameRef, IriParseError, LanguageTagParseError, Literal, LiteralRef, NamedNode, |
||||||
|
NamedNodeRef, NamedOrBlankNode, NamedOrBlankNodeRef, Quad, QuadRef, Subject, SubjectRef, Term, |
||||||
|
TermParseError, TermRef, Triple, TripleRef, |
||||||
|
}; |
@ -0,0 +1,47 @@ |
|||||||
|
//! Utilities to read and write RDF results formats using [sparesults](https://crates.io/crates/sparesults).
|
||||||
|
//!
|
||||||
|
//! It supports [SPARQL Query Results XML Format (Second Edition)](https://www.w3.org/TR/rdf-sparql-XMLres/), [SPARQL 1.1 Query Results JSON Format](https://www.w3.org/TR/sparql11-results-json/) and [SPARQL 1.1 Query Results CSV and TSV Formats](https://www.w3.org/TR/sparql11-results-csv-tsv/).
|
||||||
|
//!
|
||||||
|
//! Usage example converting a JSON result file into a TSV result file:
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! use oxigraph::sparql::results::{QueryResultsFormat, QueryResultsParser, QueryResultsReader, QueryResultsSerializer};
|
||||||
|
//! use std::io::Result;
|
||||||
|
//!
|
||||||
|
//! fn convert_json_to_tsv(json_file: &[u8]) -> Result<Vec<u8>> {
|
||||||
|
//! let json_parser = QueryResultsParser::from_format(QueryResultsFormat::Json);
|
||||||
|
//! let tsv_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Tsv);
|
||||||
|
//! // We start to read the JSON file and see which kind of results it is
|
||||||
|
//! match json_parser.read_results(json_file)? {
|
||||||
|
//! QueryResultsReader::Boolean(value) => {
|
||||||
|
//! // it's a boolean result, we copy it in TSV to the output buffer
|
||||||
|
//! tsv_serializer.write_boolean_result(Vec::new(), value)
|
||||||
|
//! },
|
||||||
|
//! QueryResultsReader::Solutions(solutions_reader) => {
|
||||||
|
//! // it's a set of solutions, we create a writer and we write to it while reading in streaming from the JSON file
|
||||||
|
//! let mut solutions_writer = tsv_serializer.solutions_writer(Vec::new(), solutions_reader.variables().to_vec())?;
|
||||||
|
//! for solution in solutions_reader {
|
||||||
|
//! solutions_writer.write(&solution?)?;
|
||||||
|
//! }
|
||||||
|
//! solutions_writer.finish()
|
||||||
|
//! }
|
||||||
|
//! }
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! // Let's test with a boolean
|
||||||
|
//! assert_eq!(
|
||||||
|
//! convert_json_to_tsv(b"{\"boolean\":true}".as_slice()).unwrap(),
|
||||||
|
//! b"true"
|
||||||
|
//! );
|
||||||
|
//!
|
||||||
|
//! // And with a set of solutions
|
||||||
|
//! assert_eq!(
|
||||||
|
//! convert_json_to_tsv(b"{\"head\":{\"vars\":[\"foo\",\"bar\"]},\"results\":{\"bindings\":[{\"foo\":{\"type\":\"literal\",\"value\":\"test\"}}]}}".as_slice()).unwrap(),
|
||||||
|
//! b"?foo\t?bar\n\"test\"\t\n"
|
||||||
|
//! );
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
pub use sparesults::{ |
||||||
|
ParseError, QueryResultsFormat, QueryResultsParser, QueryResultsReader, QueryResultsSerializer, |
||||||
|
SolutionsReader, SyntaxError, |
||||||
|
}; |
Loading…
Reference in new issue