Skip to content

Commit

Permalink
feat(cognitarium): implement rdf parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jun 1, 2023
1 parent 7c25908 commit 1f8c0d0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions contracts/okp4-cognitarium/src/rdf.rs
Original file line number Diff line number Diff line change
@@ -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<E, T, MF, UF>(input: DataInput, map_fn: MF, use_fn: UF) -> Result<(), E>
where
MF: FnMut(Triple<'_>) -> Result<T, E>,
UF: FnMut(Result<T, E>) -> Result<(), E>,
E: From<RdfXmlError> + From<TurtleError>,
{
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 ['#', '/'] {
Expand Down

0 comments on commit 1f8c0d0

Please sign in to comment.