/// <summary> /// Fills the character class from a point list. /// </summary> /// <param name="ActivePoints">The active points.</param> public static void CreateFromPointList(object o) { if (!(o is Character)) { throw new Exception("Incorrect type"); } else { Character c = o as Character; for (int i = 0; i < c.ActivePoints.Count - 1; i++) { // find something smarter to split // how do you know what point belongs to what character? // if say there's a two stroke radical, how does that // claim those to strokes for itself and prevents others from taking it? // maybe split the list at any range and make it a list of lists of radicals? // how to deal with multiple splits? // the split should be based on some assumption, like for instance: // I already found a radical with a high confidence int from, to; from = 0; to = i + 1; Radical r = new Radical(c.ActivePoints.GetRange(from, to)); c.RadicalList.Add(r); } //xxx c.AppController.ReceiveCharacterModels(new List<ICharacter>() { c }); } }
/// <summary> /// Calculates a matching score between a radical and a stroke sequence /// </summary> /// <param name="radical">The radical.</param> /// <param name="stroke">The stroke.</param> /// <returns>Matching score as a double value.</returns> public double Match(IRadical radical, List <IStroke> stroke) { double r = 0; if (radical is Radical) { Radical theRadical = radical as Radical; foreach (Stroke s in theRadical.StrokeList) { } } throw new NotImplementedException(); // return r; }
/// <summary> /// Reads the upx element content as a character. /// </summary> /// <param name="xmlr">The XMLR.</param> /// <returns>An instance of the Character class</returns> public static Character ReadUPXElementContentAsCharacter(this XmlTextReader xmlr) { if (UPXReader.IsUPXhLevelCharacter(xmlr)) { Character c = new Character(); c.SHKK = XmlTools.ReadIDAttribute(xmlr); //now moving to label and reading it //then the radicals //if we're hitting and end element that is an hLevel stop reading //the ones from the Radicals should be eaten within ReadUPXElementContentAsRadical while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hLevel"))) { if (xmlr.NodeType == XmlNodeType.Element) { Radical rTemp = null; switch (xmlr.Name) { case "label": c.Value = ReadUPXElementContentAsLabel(xmlr, c.SHKK); break; case "hLevel": if (IsUPXhLevelRadical(xmlr)) { rTemp = ReadUPXElementContentAsRadical(xmlr); c.RadicalList.Add(rTemp); } break; } } } return(c); } else { throw new Exception(string.Format("Not the correct element. This was a {0}-tag", xmlr.Name)); } }
/// <summary> /// Reads the UPX element content as radical. /// </summary> /// <param name="xmlr">The XMLR.</param> /// <returns>An instance of the Radical class</returns> private static Radical ReadUPXElementContentAsRadical(XmlTextReader xmlr) { if (UPXReader.IsUPXhLevelRadical(xmlr) && (xmlr.HasAttributes)) { Radical r = new Radical(); r.ID = XmlTools.ReadIDAttribute(xmlr); //now moving to label and reading it //then the strokes //if we're hitting and end element that is a hLevel stop reading //the ones from the strokes should be eaten within ReadUPXElementContentAsStroke while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hLevel"))) { if (xmlr.NodeType == XmlNodeType.Element) { Stroke sTemp = null; switch (xmlr.Name) { case "label": r.Value = ReadUPXElementContentAsLabel(xmlr, r.ID); break; case "hLevel": if (IsUPXhLevelStroke(xmlr)) { sTemp = ReadUPXElementContentAsStroke(xmlr); r.StrokeList.Add(sTemp); } break; } } } return(r); } else { throw new Exception(string.Format("Not the correct element. This was a {0}-tag.", xmlr.Name)); } }
private static void TestRadicalHashing() { Random rand = new Random(); List<Point> p = new List<Point>(); DateTime now = DateTime.Now; int randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); p.Add(new Point(1, 1, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); p.Add(new Point(2, 2, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); p.Add(new Point(4, 2, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); p.Add(new Point(5, 3, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); p.Add(new Point(6, 2, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); p.Add(new Point(6, 3, new DateTime(now.Ticks - randNext))); List<Point> q = new List<Point>(); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(2, 4, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(3, 5, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(5, 5, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(6, 6, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(7, 5, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(7, 6, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(8, 7, new DateTime(now.Ticks - randNext))); randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5)); q.Add(new Point(9, 8, new DateTime(now.Ticks - randNext))); Stroke s = new Stroke(p); Stroke s2 = new Stroke(p); Stroke r = new Stroke(q); List<Stroke> strokelist = new List<Stroke>(); strokelist.Add(s); strokelist.Add(s2); strokelist.Add(r); Radical rad = new Radical(strokelist); BinaryWriter bw = new BinaryWriter(new FileStream("test", FileMode.Create, FileAccess.Write, FileShare.None)); bw.Write(rad.Hash(true)); bw.Close(); }
/// <summary> /// Fills the character class from a point list. /// </summary> /// <param name="ActivePoints">The active points.</param> public static void CreateFromPointList(object o) { if (! (o is Character)) { throw new Exception("Incorrect type"); } else { Character c = o as Character; for (int i = 0; i < c.ActivePoints.Count-1; i++) { // find something smarter to split // how do you know what point belongs to what character? // if say there's a two stroke radical, how does that // claim those to strokes for itself and prevents others from taking it? // maybe split the list at any range and make it a list of lists of radicals? // how to deal with multiple splits? // the split should be based on some assumption, like for instance: // I already found a radical with a high confidence int from, to; from = 0; to = i + 1; Radical r = new Radical(c.ActivePoints.GetRange(from, to)); c.RadicalList.Add(r); } //xxx c.AppController.ReceiveCharacterModels(new List<ICharacter>() { c }); } }
/// <summary> /// Reads the UPX element content as radical. /// </summary> /// <param name="xmlr">The XMLR.</param> /// <returns>An instance of the Radical class</returns> private static Radical ReadUPXElementContentAsRadical(XmlTextReader xmlr) { if (UPXReader.IsUPXhLevelRadical(xmlr) && (xmlr.HasAttributes)) { Radical r = new Radical(); r.ID = XmlTools.ReadIDAttribute(xmlr); //now moving to label and reading it //then the strokes //if we're hitting and end element that is a hLevel stop reading //the ones from the strokes should be eaten within ReadUPXElementContentAsStroke while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hLevel"))) { if (xmlr.NodeType == XmlNodeType.Element) { Stroke sTemp = null; switch (xmlr.Name) { case "label": r.Value = ReadUPXElementContentAsLabel(xmlr, r.ID); break; case "hLevel": if (IsUPXhLevelStroke(xmlr)) { sTemp = ReadUPXElementContentAsStroke(xmlr); r.StrokeList.Add(sTemp); } break; } } } return r; } else throw new Exception(string.Format("Not the correct element. This was a {0}-tag.", xmlr.Name)); }