Function rdf_canon::api::issue_with

source ·
pub fn issue_with<D: Digest>(
    input_dataset: &Dataset,
    options: &CanonicalizationOptions
) -> Result<HashMap<String, String>, CanonicalizationError>
Expand description

Given some options (e.g., call limit), assigns deterministic identifiers to any blank nodes in the input dataset and returns the assignment result as a map.

§Examples

use oxrdf::Dataset;
use oxttl::NQuadsParser;
use rdf_canon::{issue_with, CanonicalizationOptions};
use sha2::Sha256;
use std::collections::HashMap;
use std::io::Cursor;

let input = r#"
_:e0 <http://example.org/vocab#next> _:e1 _:g .
_:e0 <http://example.org/vocab#prev> _:e2 _:g .
_:e1 <http://example.org/vocab#next> _:e2 _:g .
_:e1 <http://example.org/vocab#prev> _:e0 _:g .
_:e2 <http://example.org/vocab#next> _:e0 _:g .
_:e2 <http://example.org/vocab#prev> _:e1 _:g .
"#;
let expected_map = HashMap::from([
    ("g".to_string(), "c14n0".to_string()),
    ("e0".to_string(), "c14n1".to_string()),
    ("e1".to_string(), "c14n2".to_string()),
    ("e2".to_string(), "c14n3".to_string()),
]);

let input_quads = NQuadsParser::new()
    .parse_read(Cursor::new(input))
    .map(|x| x.unwrap());
let input_dataset = Dataset::from_iter(input_quads);
let options = CanonicalizationOptions {
    hndq_call_limit: Some(10000),
};

let issued_identifiers_map = issue_with::<Sha256>(&input_dataset, &options).unwrap();

assert_eq!(issued_identifiers_map, expected_map);