diff --git a/contracts/okp4-cognitarium/src/rdf.rs b/contracts/okp4-cognitarium/src/rdf.rs index aa989abc..285fbb35 100644 --- a/contracts/okp4-cognitarium/src/rdf.rs +++ b/contracts/okp4-cognitarium/src/rdf.rs @@ -1,4 +1,29 @@ +use crate::msg::DataInput; use cosmwasm_std::StdError; +use rio_api::model::Triple; +use rio_api::parser::TriplesParser; +use rio_turtle::{NTriplesParser, TurtleError, TurtleParser}; +use rio_xml::{RdfXmlError, RdfXmlParser}; +use std::io::BufReader; + +pub fn parse_triples(input: DataInput, map_fn: MF, use_fn: UF) -> Result<(), E> +where + MF: FnMut(Triple<'_>) -> Result, + UF: FnMut(Result) -> Result<(), E>, + E: From + From, +{ + match input { + DataInput::RDFXml(data) => RdfXmlParser::new(BufReader::new(data.as_slice()), None) + .into_iter(map_fn) + .try_for_each(use_fn), + DataInput::Turtle(data) => TurtleParser::new(BufReader::new(data.as_slice()), None) + .into_iter(map_fn) + .try_for_each(use_fn), + DataInput::NTriples(data) => NTriplesParser::new(BufReader::new(data.as_slice())) + .into_iter(map_fn) + .try_for_each(use_fn), + } +} pub fn explode_iri(iri: &str) -> Result<(&str, &str), StdError> { for delim in ['#', '/'] {