Skip to content

Commit

Permalink
use double instead of float
Browse files Browse the repository at this point in the history
  • Loading branch information
gfobe committed Sep 14, 2012
1 parent fe18d99 commit c24a652
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 62 deletions.
4 changes: 2 additions & 2 deletions ActionTendency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}
}
}
4 changes: 2 additions & 2 deletions Appraisal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}
}
}
4 changes: 2 additions & 2 deletions Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}
}
}
6 changes: 3 additions & 3 deletions Dimension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{}
}
}
16 changes: 8 additions & 8 deletions Emotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
};
Expand All @@ -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)
{
Expand All @@ -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);
});
Expand All @@ -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)
{
Expand All @@ -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);
});
Expand All @@ -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)
{
Expand All @@ -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);
});
Expand Down
24 changes: 12 additions & 12 deletions Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ public static string loadInternalResource(string resourceName) {
}

/// <summary>
/// converts float to string without localisation
/// converts double to string without localisation
/// </summary>
/// <param name="number">float</param>
/// <param name="number">double</param>
/// <returns>string</returns>
public static string float2string(float number)
public static string double2string(double number)
{
if (null == number)
{
Expand All @@ -165,30 +165,30 @@ public static string float2string(float number)
}

/// <summary>
/// usupport null
/// support null for double2string()
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public static string float2string(float? number)
/// <param name="number">double</param>
/// <returns>string</returns>
public static string double2string(double? number)
{
if (null == number)
{
return null;
}
else
{
return float2string((float)number);
return double2string((double)number);
}
}

/// <summary>
/// converts a string to float without localisation
/// converts a string to double without localisation
/// </summary>
/// <param name="number">string</param>
/// <returns>float</returns>
public static float string2float(string number)
/// <returns>double</returns>
public static double string2double(string number)
{
return float.Parse(number, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
return double.Parse(number, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
}
}
}
50 changes: 23 additions & 27 deletions Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,27 +335,28 @@ 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)
{
emotion.TimeRefUri = new Uri(emotionNode.Attributes["time-ref-uri"].Value);
}
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);
}


Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions Part.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/// </summary>
protected float? value = null;
protected double? value = null;
/// <summary>
/// confidence when we recognise the emotion [0.0, 1.0]
/// </summary>
protected float? confidence = null;
protected double? confidence = null;
/// <summary>
/// trace if we want have a value over time
/// </summary>
Expand All @@ -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;
Expand All @@ -94,7 +94,7 @@ public string Name
}
}

public float? Value
public double? Value
{
get { return this.value; }
set {
Expand All @@ -112,7 +112,7 @@ public float? Value
}
}

public float? Confidence
public double? Confidence
{
get { return confidence; }
set {
Expand Down

0 comments on commit c24a652

Please sign in to comment.