From f4bca091a43692830e0a2a12bfba3fa108b43749 Mon Sep 17 00:00:00 2001 From: Gerhard Fobe Date: Fri, 3 Aug 2012 00:28:32 +0200 Subject: [PATCH] add list of emotions and exception --- EmotionException.cs | 17 ++++++++++ EmotionList.cs | 76 +++++++++++++++++++++++++++++++++++++++++++++ EmotionML.csproj | 3 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 EmotionException.cs create mode 100644 EmotionList.cs diff --git a/EmotionException.cs b/EmotionException.cs new file mode 100644 index 0000000..358133c --- /dev/null +++ b/EmotionException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace EmotionML +{ + [Serializable()] + public class EmotionException : System.Exception + { + public EmotionException() : base() { } + public EmotionException(string message) : base(message) { } + public EmotionException(string message, System.Exception inner) : base(message, inner) { } + + protected EmotionException(System.Runtime.Serialization.StreamingContext context) { } + } +} diff --git a/EmotionList.cs b/EmotionList.cs new file mode 100644 index 0000000..ebe8bee --- /dev/null +++ b/EmotionList.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml; + +namespace EmotionML +{ + class EmotionList : List + { + /// + /// emotions categories in current emotion annotation + /// + public EmotionSet category = null; + /// + /// emotions dimensions in current emotion annotation + /// + public EmotionSet dimension = null; + /// + /// emotions appraisals in current emotion annotation + /// + public EmotionSet appraisal = null; + /// + /// emotions action tendencies in current emotion annotation + /// + EmotionSet actionTendency = null; + + /// + /// creates a DOM-list of emotions in list + /// + /// DOM of emotionml notation + public XmlDocument ToDom() + { + //init root node with attributes + XmlDocument emotionmlXml = new XmlDocument(); + XmlElement emotionml = emotionmlXml.CreateElement("emotionml"); + + if (this.category != null) + { + emotionml.SetAttribute("category-set", this.category.getEmotionsetUri().AbsoluteUri); + } + if (this.dimension != null) + { + emotionml.SetAttribute("dimension-set", this.dimension.getEmotionsetUri().AbsoluteUri); + } + if (this.appraisal != null) + { + emotionml.SetAttribute("appraisal-set", this.appraisal.getEmotionsetUri().AbsoluteUri); + } + if (this.actionTendency != null) + { + emotionml.SetAttribute("action-tendency-set", this.actionTendency.getEmotionsetUri().AbsoluteUri); + } + + //add emotions to list + for (int i = 0; i < this.Count; i++) + { + XmlDocument emotion = this.ElementAt(i).ToDom(); + emotionml.AppendChild(emotion); + } + + emotionmlXml.AppendChild(emotionml); + + return emotionmlXml; + } + + /// + /// creates EmotionML-XML for emotion list + /// + /// XML of emotions + public string ToXml() + { + return this.ToDom().ToString(); + } + } +} diff --git a/EmotionML.csproj b/EmotionML.csproj index 80d11ce..e2c15c8 100644 --- a/EmotionML.csproj +++ b/EmotionML.csproj @@ -44,9 +44,10 @@ - + +