예제 #1
0
        private static void TestInkMLReading()
        {
            KSvc.Service serv = new KSvc.Service();

            //don't show metadata
            serv.ShowMetaData = false;

            //starting service
            PointLoadObserver plso   = new PointLoadObserver();
            ThreadStart       tStart = delegate { serv.Run(plso); };
            Thread            t      = new Thread(tStart);

            t.Start();

            //starting mirror GUI
            F.Application.EnableVisualStyles();
            F.Application.SetCompatibleTextRenderingDefault(false);

            //initialise viewing area
            MirrorArea    ma      = new MirrorArea(plso);
            List <Stroke> strokes = new List <Stroke>();

            //strokes = InkMLReader.ReadInkMLFile("char02211.inkml");
            //strokes = InkMLReader.ReadInkMLFile("char00846.inkml");
            //strokes = InkMLReader.ReadInkMLFile("char00555.inkml");
            //strokes = InkMLReader.ReadInkMLFile("char00117.inkml");
            //strokes = InkMLReader.ReadInkMLFile("char00935.inkml");
            strokes = InkMLReader.ReadInkMLFile("char00117vs935hybrid.inkml");


            //go through all the strokes in the file
            //fill viewing area
            foreach (Stroke dbStroke in strokes)
            {
                plso.ReveivePoints(dbStroke.AllPoints);
            }

            //show viewing area
            ma.ShowDialog();
            ma.Hide();
            ma.Close();
            ma.Dispose();
            t.Abort();
        }
예제 #2
0
        /// <summary>
        /// Tests the hash table.
        /// </summary>
        private static void TestHashTable()
        {
            /* Concept:
             * The "database" dictionary holds all the strokes from the DB (once)
             * stored under the name of their md5-hash
             *
             * The "inputlist" List<Stroke> contains all the
             * strokes that come in from the user.
             *
             * The value is a dictionary with keys: md5hash of input
             * and value: input stroke
             *
             * Open question:
             * where are the real strokes stored?
             * proposal: in a second dictionary
             * Dictionary<byte[], Stroke> database = new Dictionary<byte[], Stroke>();
             */

            Dictionary <byte[], Dictionary <byte[], double> > matchingscores =
                new Dictionary <byte[], Dictionary <byte[], double> >();

            List <Character> characterdatabase =
                UPXReader.ParseUPXFile(
                    File.Open("C:\\Diplom\\kanjiteacher\\data\\exampleFormat.upx", FileMode.Open));

            //Dictionary<byte[], Stroke> database = new Dictionary<byte[], Stroke>();

            List <Stroke> inputlist = null;

            //take random strokes as inputlist
            inputlist = new List <Stroke>()
            {
                GetAlmostRandomStroke(0), GetAlmostRandomStroke(1)
            };
            //takes strokes of the same character from inputlist
            inputlist = InkMLReader.ReadInkMLFile("char00255.inkml");

            ////fill the stroke database with the strokes from all the characters
            ////stored under their hash codes
            //foreach (Character c in characterdatabase)
            //    foreach (Stroke s in c.StrokeList)
            //        database.Add(s.Hash(false), s);

            //go through all the strokes in the database
            foreach (Character c in characterdatabase)
            {
                //go through all the strokes in the list of input strokes
                foreach (Stroke s in inputlist)
                {
                    foreach (Stroke dbStroke in c.StrokeList)
                    {
                        //calculate the matching score
                        double score = dbStroke.MatchingScore(s, new TWStrokeMatcher());

                        //store the score in big matrix of stroke match values
                        if (!matchingscores.Keys.Contains(dbStroke.Hash()))
                        {
                            //add the score under the correct key in a new dictionary
                            //under the current strokes key
                            matchingscores.Add(
                                dbStroke.Hash(),
                                new Dictionary <byte[], double>()
                            {
                                { s.Hash(false), score }
                            });
                        }
                        else
                        {
                            //add new score for the input stroke to the
                            //existing matching dict at the entry of the current database stroke
                            matchingscores[dbStroke.Hash()].Add(s.Hash(), score);
                        }
                    }
                }
            }

            MatrixPrinter m = new MatrixPrinter(matchingscores);

            Console.WriteLine(m.print());

            Console.WriteLine(
                "Now find total minimum of these scores" +
                "i.e. go ahead and do some matrix operation in order to find" +
                "the minimum of each row." +
                "if stroke number is identical, consider position within matrix" +
                "each row can only have one best matching column" +
                "each column can only have one best matching row" +
                "find total minimum and return it"
                );
        }