public static new EntryDictionary Unmarshal(TextReader reader) { EntryDictionary dict = new OWLReact(); try { XDocument doc = XDocument.Load(reader); XElement root = doc.Root; Debug.WriteLine($"Found root element: {root.Name}"); // Extract ownNS from root element // final string ownNS = root.GetBaseURI(); string ownNS = root.Attribute("xmlns").Value; dict.NS = ownNS; Debug.WriteLine($"Found ontology namespace: {ownNS}"); // process the defined facts var entries = root.Elements(); foreach (var entry in entries) { if (entry.Name.NamespaceName.Equals(ownNS, StringComparison.Ordinal)) { EntryReact dbEntry = Unmarshal(entry, ownNS); dict.AddEntry(dbEntry); Debug.WriteLine($"Added entry: {dbEntry}"); } else { Debug.WriteLine($"Found a non-fact: {entry.Name.ToString()}"); } } } catch (XmlException ex) { Trace.TraceError($"Dictionary is not well-formed: {ex.Message}"); Debug.WriteLine($"Error at line {ex.LineNumber}, column {ex.LinePosition}"); dict = null; } catch (IOException ex) { Trace.TraceError($"Due to an IOException, the parser could not check:{ex.Message}"); Debug.WriteLine(ex); dict = null; } return(dict); }
public static EntryReact Unmarshal(XElement entry, XNamespace ownNS) { // create a new entry by ID XAttribute id = entry.Attribute(rdfNS + "ID"); Debug.WriteLine($"ID: {id.Value}"); EntryReact dbEntry = new EntryReact(id.Value); // set additional, optional data XElement label = entry.Element(rdfsNS + "label"); Debug.WriteLine($"label: {label}"); if (label != null) { dbEntry.Label = label.Value; } dbEntry.ClassName = entry.Name.LocalName; Debug.WriteLine($"class name: {dbEntry.ClassName}"); XElement definition = entry.Element(ownNS + "definition"); if (definition != null) { dbEntry.Definition = definition.Value; Debug.WriteLine($"definition name: {definition.Value}"); } XElement description = entry.Element(ownNS + "description"); if (description != null) { dbEntry.Description = description.Value; Debug.WriteLine($"description name: {description.Value}"); } var representations = entry.Elements(ownNS + "representation"); foreach (var representation in representations) { // string idRepr = representations[i].GetAttributeValue("id"); string contentRepr = representation.Attribute("content")?.Value; dbEntry.AddRepresentation(contentRepr); } var params_ = entry.Elements(ownNS + "parameters"); foreach (var p in params_) { string typeParam = p.Attribute("dataType")?.Value; typeParam = typeParam.Substring(typeParam.IndexOf(':') + 1); string nameParam = p.Attribute("resource")?.Value; string value = p.Value; dbEntry.SetParameters(nameParam, typeParam, value); } var paramsList = entry.Elements(ownNS + "parameterList"); foreach (var p in paramsList) { var params2 = p.Elements(ownNS + "parameter2"); foreach (var p2 in params2) { string paramClass = p2.FirstAttribute.Value; paramClass = paramClass.Substring(paramClass.IndexOf('#') + 1); Debug.WriteLine($"parameter class: {paramClass}"); string needsToSet = ""; string value = ""; string dataType = ""; var paramSubt1 = p2.Elements(ownNS + "IsSetParameter"); needsToSet = paramSubt1.FirstOrDefault()?.Value; if (needsToSet == null) { needsToSet = ""; } var paramSubt2 = p2.Elements(ownNS + "value"); var eparamSubt2 = paramSubt2.FirstOrDefault(); value = eparamSubt2 == null ? "" : eparamSubt2.Value; dataType = eparamSubt2.Attribute("dataType")?.Value; dataType = dataType.Substring(dataType.IndexOf(':') + 1); var pp = new List <string> { paramClass, needsToSet, dataType, value }; dbEntry.AddParameter(pp); } } var mechanismDependence = entry.Elements(ownNS + "mechanismDependence"); string mechanism = ""; foreach (var md in mechanismDependence) { mechanism = md.FirstAttribute.Value; mechanism = mechanism.Substring(mechanism.IndexOf('#') + 1); Debug.WriteLine($"mechanism name: {mechanism}"); } dbEntry.Mechanism = mechanism; var exampleReact = entry.Elements(ownNS + "example-Reactions"); foreach (var er in exampleReact) { var reaction = er.Elements(ownNS + "reaction"); foreach (var r in reaction) { dbEntry.AddExampleReaction(r.ToString(SaveOptions.DisableFormatting)); } } return(dbEntry); }