Function rdf_canon::api::relabel_quads
source · pub fn relabel_quads(
input_quads: &[Quad],
issued_identifiers_map: &HashMap<String, String>
) -> Result<Vec<Quad>, CanonicalizationError>
Expand description
Re-label blank node identifiers in the input quads according to the issued identifiers map.
§Examples
use oxrdf::Quad;
use oxttl::NQuadsParser;
use rdf_canon::relabel_quads;
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 issued_identifiers_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 expected = r#"
_:c14n1 <http://example.org/vocab#next> _:c14n2 _:c14n0 .
_:c14n1 <http://example.org/vocab#prev> _:c14n3 _:c14n0 .
_:c14n2 <http://example.org/vocab#next> _:c14n3 _:c14n0 .
_:c14n2 <http://example.org/vocab#prev> _:c14n1 _:c14n0 .
_:c14n3 <http://example.org/vocab#next> _:c14n1 _:c14n0 .
_:c14n3 <http://example.org/vocab#prev> _:c14n2 _:c14n0 .
"#;
let input_quads: Vec<Quad> = NQuadsParser::new()
.parse_read(Cursor::new(input))
.map(|x| x.unwrap())
.collect();
let labeled_quads = relabel_quads(&input_quads, &issued_identifiers_map).unwrap();
let expected_quads: Vec<Quad> = NQuadsParser::new()
.parse_read(Cursor::new(expected))
.map(|x| x.unwrap())
.collect();
assert_eq!(labeled_quads, expected_quads);