1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use std::mem::replace;
use std::str::FromStr;
use std::string::ToString;
use std::collections::HashMap;
use fastobo::ast::ClassIdent;
use fastobo::ast::HeaderFrame;
use fastobo::ast::HeaderClause;
use fastobo::ast::NaiveDateTime;
use fastobo::ast::EntityFrame;
use fastobo::ast::Ident;
use fastobo::ast::QuotedString;
use fastobo::ast::Synonym;
use fastobo::ast::OboDoc;
use fastobo::ast::SynonymScope;
use fastobo::ast::TermClause;
use fastobo::ast::TypedefClause;
use fastobo::ast::InstanceClause;
use fastobo::ast::TermFrame;
use fastobo::ast::IsoDateTime;
use fastobo::ast::InstanceFrame;
use fastobo::ast::TypedefFrame;
use fastobo::ast::NamespaceIdent;
use fastobo::ast::Line;
use fastobo::ast::UnquotedString;
use fastobo::ast::Xref;
use fastobo::ast::XrefList;
use fastobo::ast::RelationIdent;
use fastobo::ast::PrefixedIdent;
use fastobo::ast::SubsetIdent;
use fastobo::ast::InstanceIdent;
use fastobo::ast::PropertyValue;
use fastobo::ast::Url;
use fastobo::semantics::Identified;
use fastobo::semantics::Orderable;
use crate::constants::property::dc;
use crate::constants::property::iao;
use crate::constants::property::obo_in_owl;
use crate::constants::property::rdfs;
use crate::model::Graph;
use crate::model::Meta;
use crate::model::Node;
use crate::model::NodeType;
use crate::model::BasicPropertyValue;
use crate::model::DefinitionPropertyValue;
use crate::model::SynonymPropertyValue;
use crate::model::XrefPropertyValue;
use crate::error::Error;
use crate::error::Result;
use super::FromGraph;
impl FromGraph<Meta> for HeaderFrame {
fn from_graph(meta: Meta) -> Result<Self> {
let mut frame = Self::new();
if let Some(ref def) = meta.definition {}
for comment in meta.comments {
frame.push(HeaderClause::Remark(UnquotedString::new(comment)));
}
for pv in meta.basic_property_values {
frame.push(HeaderClause::from_graph(pv)?);
}
Ok(frame)
}
}
impl FromGraph<BasicPropertyValue> for HeaderClause {
fn from_graph(pv: BasicPropertyValue) -> Result<Self> {
match pv.pred.as_str() {
obo_in_owl::AUTO_GENERATED_BY => {
Ok(HeaderClause::AutoGeneratedBy(UnquotedString::new(pv.val)))
}
obo_in_owl::CREATION_DATE | dc::DATE | obo_in_owl::HAS_DATE => {
let dt = NaiveDateTime::from_str(&pv.val)?;
Ok(HeaderClause::Date(dt))
}
obo_in_owl::HAS_DEFAULT_NAMESPACE => {
let ns_id = NamespaceIdent::from_str(&pv.val)?;
Ok(HeaderClause::DefaultNamespace(ns_id))
}
obo_in_owl::HAS_OBO_FORMAT_VERSION => {
Ok(HeaderClause::FormatVersion(UnquotedString::new(pv.val)))
}
obo_in_owl::NAMESPACE_ID_RULE => {
Ok(HeaderClause::NamespaceIdRule(UnquotedString::new(pv.val)))
}
obo_in_owl::SAVED_BY => {
Ok(HeaderClause::SavedBy(UnquotedString::new(pv.val)))
}
rdfs::COMMENT => {
Ok(HeaderClause::Remark(UnquotedString::new(pv.val)))
}
other => {
let rel = RelationIdent::from_str(&other)?;
let pv = match Ident::from_str(&pv.val) {
Ok(id) => PropertyValue::Resource(rel, id),
Err(_) => PropertyValue::Literal(
rel,
QuotedString::new(pv.val),
Ident::from(PrefixedIdent::new("xsd", "string"))
)
};
Ok(HeaderClause::PropertyValue(pv))
},
}
}
}