From c24a6521d71c2943b8b9cf3ed569b433c1fa750c Mon Sep 17 00:00:00 2001 From: Gerhard Fobe Date: Fri, 14 Sep 2012 19:57:11 +0200 Subject: [PATCH] use double instead of float --- ActionTendency.cs | 4 ++-- Appraisal.cs | 4 ++-- Category.cs | 4 ++-- Dimension.cs | 6 +++--- Emotion.cs | 16 +++++++-------- Helper.cs | 24 +++++++++++------------ Parser.cs | 50 ++++++++++++++++++++++------------------------- Part.cs | 12 ++++++------ 8 files changed, 58 insertions(+), 62 deletions(-) diff --git a/ActionTendency.cs b/ActionTendency.cs index 46bc02d..bcfc804 100644 --- a/ActionTendency.cs +++ b/ActionTendency.cs @@ -40,10 +40,10 @@ public class ActionTendency : Part public ActionTendency(string name) : base(name) {} - public ActionTendency(string name, float? value) : base(name, value) + public ActionTendency(string name, double? value) : base(name, value) {} - public ActionTendency(string name, float? value, float? confidence) : base (name, value, confidence) + public ActionTendency(string name, double? value, double? confidence) : base (name, value, confidence) {} } } \ No newline at end of file diff --git a/Appraisal.cs b/Appraisal.cs index 0c74dd8..b790ac8 100644 --- a/Appraisal.cs +++ b/Appraisal.cs @@ -42,10 +42,10 @@ public class Appraisal : Part public Appraisal(string name) : base(name) {} - public Appraisal(string name, float? value) : base(name, value) + public Appraisal(string name, double? value) : base(name, value) {} - public Appraisal(string name, float? value, float? confidence) : base (name, value, confidence) + public Appraisal(string name, double? value, double? confidence) : base (name, value, confidence) {} } } \ No newline at end of file diff --git a/Category.cs b/Category.cs index 119fb53..b3046a3 100644 --- a/Category.cs +++ b/Category.cs @@ -45,10 +45,10 @@ public class Category : Part public Category(string name) : base(name) {} - public Category(string name, float? value) : base(name, value) + public Category(string name, double? value) : base(name, value) {} - public Category(string name, float? value, float? confidence) : base (name, value, confidence) + public Category(string name, double? value, double? confidence) : base (name, value, confidence) {} } } \ No newline at end of file diff --git a/Dimension.cs b/Dimension.cs index e278344..ad0723d 100644 --- a/Dimension.cs +++ b/Dimension.cs @@ -40,7 +40,7 @@ public class Dimension : Part public const string DIMENSION_INTENSITY = "http://www.w3.org/TR/emotion-voc/xml#intensity-dimension"; - public new float? Value + public new double? Value { get { return this.value; } set @@ -81,10 +81,10 @@ public class Dimension : Part public Dimension(string name) : base(name) {} - public Dimension(string name, float? value) : base(name, value) + public Dimension(string name, double? value) : base(name, value) {} - public Dimension(string name, float? value, float? confidence) : base (name, value, confidence) + public Dimension(string name, double? value, double? confidence) : base (name, value, confidence) {} } } \ No newline at end of file diff --git a/Emotion.cs b/Emotion.cs index da42ae8..5b48392 100644 --- a/Emotion.cs +++ b/Emotion.cs @@ -887,7 +887,7 @@ public XmlDocument ToDom() catNode.SetAttribute("name", cat.Name); if (cat.Value != null) { - catNode.SetAttribute("value", Helper.float2string(cat.Value)); + catNode.SetAttribute("value", Helper.double2string(cat.Value)); } else if (cat.Trace != null) { @@ -896,7 +896,7 @@ public XmlDocument ToDom() } if (cat.Confidence != null) { - catNode.SetAttribute("confidence", Helper.float2string(cat.Confidence)); + catNode.SetAttribute("confidence", Helper.double2string(cat.Confidence)); } emotion.AppendChild(catNode); }; @@ -912,7 +912,7 @@ public XmlDocument ToDom() dimNode.SetAttribute("name", dim.Name); if (dim.Value != null) { - dimNode.SetAttribute("value", Helper.float2string(dim.Value)); + dimNode.SetAttribute("value", Helper.double2string(dim.Value)); } else if (dim.Trace != null) { @@ -921,7 +921,7 @@ public XmlDocument ToDom() } if (dim.Confidence != null) { - dimNode.SetAttribute("confidence", Helper.float2string(dim.Confidence)); + dimNode.SetAttribute("confidence", Helper.double2string(dim.Confidence)); } emotion.AppendChild(dimNode); }); @@ -937,7 +937,7 @@ public XmlDocument ToDom() aprNode.SetAttribute("name", apr.Name); if (apr.Value != null) { - aprNode.SetAttribute("value", Helper.float2string(apr.Value)); + aprNode.SetAttribute("value", Helper.double2string(apr.Value)); } else if (apr.Trace != null) { @@ -946,7 +946,7 @@ public XmlDocument ToDom() } if (apr.Confidence != null) { - aprNode.SetAttribute("confidence", Helper.float2string(apr.Confidence)); + aprNode.SetAttribute("confidence", Helper.double2string(apr.Confidence)); } emotion.AppendChild(aprNode); }); @@ -962,7 +962,7 @@ public XmlDocument ToDom() actNode.SetAttribute("name", act.Name); if (act.Value != null) { - actNode.SetAttribute("value", Helper.float2string(act.Value)); + actNode.SetAttribute("value", Helper.double2string(act.Value)); } else if (act.Trace != null) { @@ -972,7 +972,7 @@ public XmlDocument ToDom() if (act.Confidence != null) { - actNode.SetAttribute("confidence", Helper.float2string(act.Confidence)); + actNode.SetAttribute("confidence", Helper.double2string(act.Confidence)); } emotion.AppendChild(actNode); }); diff --git a/Helper.cs b/Helper.cs index bfb4766..95539b8 100644 --- a/Helper.cs +++ b/Helper.cs @@ -150,11 +150,11 @@ public static string loadInternalResource(string resourceName) { } /// - /// converts float to string without localisation + /// converts double to string without localisation /// - /// float + /// double /// string - public static string float2string(float number) + public static string double2string(double number) { if (null == number) { @@ -165,11 +165,11 @@ public static string float2string(float number) } /// - /// usupport null + /// support null for double2string() /// - /// - /// - public static string float2string(float? number) + /// double + /// string + public static string double2string(double? number) { if (null == number) { @@ -177,18 +177,18 @@ public static string float2string(float? number) } else { - return float2string((float)number); + return double2string((double)number); } } /// - /// converts a string to float without localisation + /// converts a string to double without localisation /// /// string - /// float - public static float string2float(string number) + /// double + public static double string2double(string number) { - return float.Parse(number, System.Globalization.CultureInfo.InvariantCulture.NumberFormat); + return double.Parse(number, System.Globalization.CultureInfo.InvariantCulture.NumberFormat); } } } diff --git a/Parser.cs b/Parser.cs index 40658d4..a8794c4 100644 --- a/Parser.cs +++ b/Parser.cs @@ -335,15 +335,16 @@ protected Emotion parseEmotion(XmlNode emotionNode) //add time ralted stuff if (emotionNode.Attributes["start"] != null) { - emotion.Start = Convert.ToInt32(emotionNode.Attributes["start"].Value); + emotion.Start = Convert.ToInt64(emotionNode.Attributes["start"].Value); + } if (emotionNode.Attributes["end"] != null) { - emotion.End = Convert.ToInt32(emotionNode.Attributes["end"].Value); + emotion.End = Convert.ToInt64(emotionNode.Attributes["end"].Value); } if (emotionNode.Attributes["duration"] != null) { - emotion.Duration = Convert.ToInt32(emotionNode.Attributes["end"].Value); + emotion.Duration = Convert.ToInt64(emotionNode.Attributes["duration"].Value); } if (emotionNode.Attributes["time-ref-uri"] != null) { @@ -351,11 +352,11 @@ protected Emotion parseEmotion(XmlNode emotionNode) } if (emotionNode.Attributes["time-ref-anchor-point"] != null) { - emotion.TimeRefAnchorPoint = Convert.ToInt32(emotionNode.Attributes["time-ref-anchor-point"].Value); + emotion.TimeRefAnchorPoint = Convert.ToInt64(emotionNode.Attributes["time-ref-anchor-point"].Value); } if (emotionNode.Attributes["offset-to-start"] != null) { - emotion.OffsetToStart = Convert.ToInt32(emotionNode.Attributes["offset-to-start"].Value); + emotion.OffsetToStart = Convert.ToInt64(emotionNode.Attributes["offset-to-start"].Value); } @@ -429,16 +430,16 @@ protected Emotion parseEmotion(XmlNode emotionNode) foreach (XmlNode cat in categoryTags) { string categoryName = cat.Attributes["name"].InnerText; - float? categoryValue = null; - float? categoryConfidence = null; + double? categoryValue = null; + double? categoryConfidence = null; if (cat.Attributes["value"] != null) { - categoryValue = Helper.string2float(cat.Attributes["value"].InnerText); + categoryValue = Helper.string2double(cat.Attributes["value"].InnerText); } if (cat.Attributes["confidence"] != null) { - categoryConfidence = Helper.string2float(cat.Attributes["confidence"].InnerText); + categoryConfidence = Helper.string2double(cat.Attributes["confidence"].InnerText); } categories.Add(new Category(categoryName, categoryValue, categoryConfidence)); @@ -456,16 +457,16 @@ protected Emotion parseEmotion(XmlNode emotionNode) foreach (XmlNode dim in dimensionTags) { string dimensionName = dim.Attributes["name"].InnerText; - float? dimensionValue = null; - float? dimensionConfidence = null; + double? dimensionValue = null; + double? dimensionConfidence = null; if (dim.Attributes["value"] != null) { - dimensionValue = Helper.string2float(dim.Attributes["value"].InnerText); + dimensionValue = Helper.string2double(dim.Attributes["value"].InnerText); } if (dim.Attributes["confidence"] != null) { - dimensionConfidence = Helper.string2float(dim.Attributes["confidence"].InnerText); + dimensionConfidence = Helper.string2double(dim.Attributes["confidence"].InnerText); } dimensions.Add(new Dimension(dimensionName, dimensionValue, dimensionConfidence)); @@ -483,16 +484,16 @@ protected Emotion parseEmotion(XmlNode emotionNode) foreach (XmlNode apr in appraisalTags) { string appraisalName = apr.Attributes["name"].InnerText; - float? appraisalValue = null; - float? appraisalConfidence = null; + double? appraisalValue = null; + double? appraisalConfidence = null; if (apr.Attributes["value"] != null) { - appraisalValue = Helper.string2float(apr.Attributes["value"].InnerText); + appraisalValue = Helper.string2double(apr.Attributes["value"].InnerText); } if (apr.Attributes["confidence"] != null) { - appraisalConfidence = Helper.string2float(apr.Attributes["confidence"].InnerText); + appraisalConfidence = Helper.string2double(apr.Attributes["confidence"].InnerText); } appraisals.Add(new Appraisal(appraisalName, appraisalValue, appraisalConfidence)); @@ -510,16 +511,16 @@ protected Emotion parseEmotion(XmlNode emotionNode) foreach (XmlNode act in actionTendencyTags) { string actionTendencyName = act.Attributes["name"].InnerText; - float? actionTendencyValue = null; - float? actionTendencyConfidence = null; + double? actionTendencyValue = null; + double? actionTendencyConfidence = null; if (act.Attributes["value"] != null) { - actionTendencyValue = Helper.string2float(act.Attributes["value"].InnerText); + actionTendencyValue = Helper.string2double(act.Attributes["value"].InnerText); } if (act.Attributes["confidence"] != null) { - actionTendencyConfidence = Helper.string2float(act.Attributes["confidence"].InnerText); + actionTendencyConfidence = Helper.string2double(act.Attributes["confidence"].InnerText); } actionTendencies.Add(new ActionTendency(actionTendencyName, actionTendencyValue, actionTendencyConfidence)); @@ -569,7 +570,7 @@ protected Trace parseTrace(XmlNode traceNode) { string samples = traceNode.Attributes["samples"].Value; //FIXME: Parse Hz - float frequency = Helper.string2float(traceNode.Attributes["freq"].Value); + double frequency = Helper.string2double(traceNode.Attributes["freq"].Value); return new Trace(frequency, samples); } @@ -610,11 +611,6 @@ protected Info parseInfo(XmlNode infoNode) { infoArea.Id = infoNode.Attributes["id"].Value; } - XmlNode textnode = infoNode.SelectSingleNode("text()"); - if (textnode != null) - { - infoArea.Plaintext = textnode.InnerText; - } return infoArea; } diff --git a/Part.cs b/Part.cs index 23b3aa2..99c8d7c 100644 --- a/Part.cs +++ b/Part.cs @@ -48,11 +48,11 @@ public abstract class Part /// the value [0.0, 1.0] /// dimension MUST have a value or a trace, the other MAY //TODO: /// - protected float? value = null; + protected double? value = null; /// /// confidence when we recognise the emotion [0.0, 1.0] /// - protected float? confidence = null; + protected double? confidence = null; /// /// trace if we want have a value over time /// @@ -66,13 +66,13 @@ public Part(string name) } //OPTIMIZE: shorter with :this(name) - public Part(string name, float? value) + public Part(string name, double? value) { this.name = name; this.value = value; } - public Part(string name, float? value, float? confidence) + public Part(string name, double? value, double? confidence) { this.name = name; this.value = value; @@ -94,7 +94,7 @@ public string Name } } - public float? Value + public double? Value { get { return this.value; } set { @@ -112,7 +112,7 @@ public float? Value } } - public float? Confidence + public double? Confidence { get { return confidence; } set {