use std::mem::replace;
use fastobo::ast::OboDoc;
use fastobo::ast::HeaderFrame;
use crate::error::Result;
use crate::model::Graph;
use crate::model::GraphDocument;
use super::Context;
use super::IntoGraph;
use super::IntoGraphCtx;
impl IntoGraphCtx<GraphDocument> for OboDoc {
fn into_graph_ctx(mut self, ctx: &mut Context) -> Result<GraphDocument> {
self.treat_xrefs();
let header = replace(self.header_mut(), HeaderFrame::default());
let entities = replace(self.entities_mut(), Vec::new());
let mut graph = Graph {
nodes: Vec::new(),
edges: Vec::new(),
id: ctx.ontology_iri.to_string(),
label: None,
meta: header.into_graph_ctx(ctx).map(Box::new)?,
equivalent_nodes_sets: Vec::new(),
logical_definition_axioms: Vec::new(),
domain_range_axioms: Vec::new(),
property_chain_axioms: Vec::new(),
};
for entity in entities.into_iter() {
let entity_graph = entity.into_graph_ctx(ctx)?;
graph.extend(entity_graph);
}
Ok(GraphDocument::from(graph))
}
}
impl IntoGraph for OboDoc {
#[inline]
fn into_graph(self) -> Result<GraphDocument> {
let mut ctx = Context::from(&self);
self.into_graph_ctx(&mut ctx)
}
}