예제 #1
0
        float StrokeCost(int strokeIndex, out StrokeMatch bestMatch)
        {
            StrokeTemplate     template         = Template[strokeIndex];
            List <StrokeMatch> candidateMatches = InputMatches[strokeIndex];
            float bestCost = float.PositiveInfinity;

            bestMatch = null;
            foreach (StrokeMatch match in candidateMatches)
            {
                if (match.Parts.Count != template.Parts.Count)
                {
                    continue;
                }
                float cost = 0;
                for (int partIndex = 0; partIndex < match.Parts.Count; partIndex++)
                {
                    StrokePartMatch    partMatch    = match.Parts[partIndex];
                    StrokePartTemplate partTemplate = template.Parts[partIndex];
                    cost += partTemplate.MatchCost(partMatch);
                }
                cost += match.Cost * 30;
                if (cost < bestCost)
                {
                    bestCost  = cost;
                    bestMatch = match;
                }
            }
            return(bestCost);
        }
예제 #2
0
        public Form1()
        {
            InitializeComponent();
            clear_Click(null, null);
            using (StreamReader reader = new StreamReader("../../../data/kanjidb.txt"))
            {
                string s;
                while (true)
                {
                    string name = reader.ReadLine();
                    if (name == null)
                    {
                        break;
                    }
                    s = reader.ReadLine();
                    List <StrokeTemplate> template = new List <StrokeTemplate>();
                    while (!string.IsNullOrEmpty(s))
                    {
                        template.Add(StrokeTemplate.Parse(s));
                        s = reader.ReadLine();
                    }
                    templates.Add(template);
                }
            }

            /*TreeDoc td = TreeDoc.Load("KanjiDb.txt");
             * foreach (var kanjiTd in td.Children)
             * {
             *      if (kanjiTd.Name != "Wa")
             *              continue;
             *      var template = new List<StrokeTemplate>();
             *      foreach (var strokeTd in kanjiTd.Children)
             *      {
             *              template.Add(StrokeTemplate.FromTreeDoc(strokeTd));
             *      }
             *      templates.Add(template);
             * }*/
            matchedTemplate = templates.Skip(6).First();
        }