diff --git a/horned-bin/src/bin/horned_dump.rs b/horned-bin/src/bin/horned_dump.rs index ac32bde..3bea2e9 100644 --- a/horned-bin/src/bin/horned_dump.rs +++ b/horned-bin/src/bin/horned_dump.rs @@ -50,6 +50,11 @@ pub(crate) fn matcher(matches: &ArgMatches) -> Result<(), HornedError> { )?; match r { + horned_owl::io::ParserOutput::OFNParser(ont, map) => { + let hash_map: HashMap<&String, &String> = map.mappings().collect(); + println!("Ontology:\n{:#?}\n\nMapping:\n{:#?}", ont, hash_map); + Ok(()) + } horned_owl::io::ParserOutput::OWXParser(ont, map) => { let hash_map: HashMap<&String, &String> = map.mappings().collect(); println!("Ontology:\n{:#?}\n\nMapping:\n{:#?}", ont, hash_map); diff --git a/horned-bin/src/bin/horned_round.rs b/horned-bin/src/bin/horned_round.rs index db5c96e..7579337 100644 --- a/horned-bin/src/bin/horned_round.rs +++ b/horned-bin/src/bin/horned_round.rs @@ -45,6 +45,10 @@ pub(crate) fn matcher(matches: &ArgMatches) -> Result<(), HornedError> { )?; let rtn = match res { + horned_owl::io::ParserOutput::OFNParser(so, pm) => { + let amo: RcComponentMappedOntology = so.into(); + horned_owl::io::owx::writer::write(&mut stdout(), &amo, Some(&pm)) + } horned_owl::io::ParserOutput::OWXParser(so, pm) => { let amo: RcComponentMappedOntology = so.into(); horned_owl::io::owx::writer::write(&mut stdout(), &amo, Some(&pm)) diff --git a/horned-bin/src/lib.rs b/horned-bin/src/lib.rs index 934b32f..1336034 100644 --- a/horned-bin/src/lib.rs +++ b/horned-bin/src/lib.rs @@ -16,6 +16,7 @@ use std::{ pub fn path_type(path: &Path) -> Option { match path.extension().and_then(|s| s.to_str()) { + Some("ofn") => Some(ResourceType::OFN), Some("owx") => Some(ResourceType::OWX), Some("owl") => Some(ResourceType::RDF), _ => None, @@ -27,15 +28,20 @@ pub fn parse_path( config: ParserConfiguration ) -> Result, HornedError> { Ok(match path_type(path) { + Some(ResourceType::OFN) => { + let file = File::open(&path)?; + let mut bufreader = BufReader::new(file); + ParserOutput::ofn(horned_owl::io::ofn::reader::read(&mut bufreader, config)?) + } Some(ResourceType::OWX) => { let file = File::open(&path)?; let mut bufreader = BufReader::new(file); - horned_owl::io::owx::reader::read(&mut bufreader, config)?.into() + ParserOutput::owx(horned_owl::io::owx::reader::read(&mut bufreader, config)?) } Some(ResourceType::RDF) => { let b = Build::new(); let iri = horned_owl::resolve::path_to_file_iri(&b, path); - horned_owl::io::rdf::closure_reader::read(&iri, config)?.into() + ParserOutput::rdf(horned_owl::io::rdf::closure_reader::read(&iri, config)?) } None => { return Err(HornedError::CommandError(format!( @@ -54,12 +60,15 @@ pub fn parse_imports( let file = File::open(&path)?; let mut bufreader = BufReader::new(file); Ok(match path_type(path) { - Some(ResourceType::OWX) => horned_owl::io::owx::reader::read(&mut bufreader, config)?.into(), + Some(ResourceType::OFN) => ParserOutput::ofn(horned_owl::io::owx::reader::read(&mut bufreader, config)?), + Some(ResourceType::OWX) => ParserOutput::owx(horned_owl::io::owx::reader::read(&mut bufreader, config)?), Some(ResourceType::RDF) => { let b = Build::new(); let mut p = horned_owl::io::rdf::reader::parser_with_build(&mut bufreader, &b, config); p.parse_imports()?; - p.as_ontology_and_incomplete()?.into() + ParserOutput::rdf( + p.as_ontology_and_incomplete()? + ) } None => { return Err(HornedError::CommandError(format!( diff --git a/src/io/mod.rs b/src/io/mod.rs index 53e5cf2..ac8812a 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -15,15 +15,31 @@ use crate::{ }; pub enum ResourceType { + OFN, OWX, RDF, } pub enum ParserOutput> { + OFNParser(SetOntology, PrefixMapping), OWXParser(SetOntology, PrefixMapping), RDFParser(RDFOntology, IncompleteParse), } +impl> ParserOutput { + pub fn ofn(sop: (SetOntology, PrefixMapping)) -> ParserOutput { + ParserOutput::OFNParser(sop.0, sop.1) + } + + pub fn owx(sop: (SetOntology, PrefixMapping)) -> ParserOutput { + ParserOutput::OWXParser(sop.0, sop.1) + } + + pub fn rdf(rop: (RDFOntology, IncompleteParse)) -> ParserOutput { + ParserOutput::RDFParser(rop.0, rop.1) + } +} + #[derive(Clone, Copy, Debug, Default)] pub struct ParserConfiguration { // Shared Config will go here @@ -32,12 +48,12 @@ pub struct ParserConfiguration { } #[derive(Clone, Copy, Debug, Default)] -pub struct RDFParserConfiguration { - pub lax: bool +pub struct OWXParserConfiguration { } #[derive(Clone, Copy, Debug, Default)] -pub struct OWXParserConfiguration { +pub struct RDFParserConfiguration { + pub lax: bool } impl> ParserOutput { @@ -49,29 +65,18 @@ impl> ParserOutput { Option>, ) { match self { + ParserOutput::OFNParser(o, m) => (o, Some(m), None), ParserOutput::OWXParser(o, m) => (o, Some(m), None), ParserOutput::RDFParser(o, i) => (o.into(), None, Some(i)), } } } -impl> From<(SetOntology, PrefixMapping)> for ParserOutput { - fn from(sop: (SetOntology, PrefixMapping)) -> ParserOutput { - ParserOutput::OWXParser(sop.0, sop.1) - } -} - -impl> From<(RDFOntology, IncompleteParse)> - for ParserOutput -{ - fn from(rop: (RDFOntology, IncompleteParse)) -> ParserOutput { - ParserOutput::RDFParser(rop.0, rop.1) - } -} impl> From> for SetOntology { fn from(p: ParserOutput) -> SetOntology { match p { + ParserOutput::OFNParser(so, _) => so, ParserOutput::OWXParser(so, _) => so, ParserOutput::RDFParser(rdfo, _) => rdfo.into(), } @@ -81,6 +86,7 @@ impl> From> for SetOntology { impl> From> for ComponentMappedOntology { fn from(p: ParserOutput) -> ComponentMappedOntology { match p { + ParserOutput::OFNParser(so, _) => so.into(), ParserOutput::OWXParser(so, _) => so.into(), ParserOutput::RDFParser(rdfo, _) => rdfo.into(), }