public void TestXMLConversion()
        {
            const string filename = "tmp.xml";

            Domain.ShapeType testType = Domain.LogicDomain.AND;

            Sketch.Sketch sketch1 = Sketches.newValidSketch();

            foreach (Sketch.Shape shape in sketch1.Shapes)
            {
                shape.Type = testType;
            }

            ConverterXML.SaveToXML writer = new ConverterXML.SaveToXML(sketch1);
            writer.WriteXML(filename);

            ConverterXML.ReadXML reader  = new ConverterXML.ReadXML(filename);
            Sketch.Sketch        sketch2 = reader.Sketch;

            sketch2.CheckConsistency();

            Assert.IsTrue(sketch1.Equals(sketch2), "Original sketch is not equal to the loaded sketch");
            Assert.IsTrue(sketch2.Equals(sketch1), "Loaded sketch is not equal to the original");

            foreach (Sketch.Shape shape in sketch2.Shapes)
            {
                Assert.AreEqual(testType, shape.Type, "Shape types are not preserved across save/load");
            }
        }
Exemplo n.º 2
0
        public void TestXMLConversion()
        {
            const string      filename = "tmp.xml";
            RecognitionResult type     = new RecognitionResult(LogicDomain.AND, 0.9, 0.33);

            Sketch.Project project1 = new Sketch.Project(Sketches.newValidSketch());;

            foreach (Sketch.Shape shape in project1.sketch.Shapes)
            {
                type.ApplyToShape(shape);
            }

            ConverterXML.SaveToXML writer = new ConverterXML.SaveToXML(project1);
            writer.WriteXML(filename);

            ConverterXML.ReadXML reader  = new ConverterXML.ReadXML(filename);
            Sketch.Sketch        sketch2 = reader.Sketch;

            sketch2.CheckConsistency();

            Assert.IsTrue(project1.sketch.Equals(sketch2), "Original sketch is not equal to the loaded sketch");
            Assert.IsTrue(sketch2.Equals(project1.sketch), "Loaded sketch is not equal to the original");

            foreach (Sketch.Shape shape in sketch2.Shapes)
            {
                Assert.AreEqual(type.Type, shape.Type, "Shape types are not preserved across save/load");
                Assert.IsTrue(Math.Abs(type.Confidence - shape.Probability) < 0.0001, "Shape confidences are not preserved across save/load");
                Assert.IsTrue(Math.Abs(type.Orientation - shape.Orientation) < 0.0001, "Shape orientations are not preserved across save/load");
            }
        }
Exemplo n.º 3
0
 public void write()
 {
     foreach (KeyValuePair <string, List <Shape> > kvp in _sps)
     {
         int count = 0;
         foreach (Shape sp in kvp.Value)
         {
             Sketch.Sketch sketch = new Sketch.Sketch();
             sketch.AddShape(sp);
             foreach (Substroke s in sp.SubstrokesL)
             {
                 sketch.AddStroke(s.ParentStroke);
             }
             ConverterXML.SaveToXML maker = new ConverterXML.SaveToXML(sketch);
             maker.WriteXML(String.Format("{0}\\{1}_{2}.xml", _dir, kvp.Key, count));
             ++count;
         }
     }
 }
Exemplo n.º 4
0
        public override void run(Sketch.Sketch original, string filename)
        {
            _numTests++;

            foreach (RecognitionPipeline pipeline in _pipelines)
            {
                Sketch.Sketch sketch = original.Clone();
                sketch.RemoveLabelsAndGroups();
                pipeline.process(sketch);

                string sketchFilename = "sketch-" + _numTests + " pipeline-" + pipelineId(pipeline) + ".xml";
                Console.WriteLine("Saving sketch to " + sketchFilename);
                ConverterXML.SaveToXML saver = new ConverterXML.SaveToXML(new Sketch.Project(sketch));
                saver.WriteXML(sketchFilename);

                Utils.SketchComparer comparer = new Utils.SketchComparer(original, sketch);

                double cls = comparer.ClassificationQuality * 100;

                /* This grouping stat is the
                 *  (# groups found correctly / # correct groups)
                 *  Where # correct groups is the number of groups in
                 *  the correctly recognized sketch.
                 */
                double grp = comparer.GroupingQuality * 100;

                /*This recognition stat is the
                 * (# groups recognized correctly / # groups found correctly)
                 */
                double rec = comparer.RecognitionQuality * 100;

                /*This is the recognition stat that we really care about,
                 * because it portrays the recognition rate out of all the
                 * groups in the sketch
                 */
                double realRec = comparer.RecognitionQuality * comparer.GroupingQuality * 100;
                double srec    = comparer.SubstrokeRecognitionQuality * 100;

                Console.WriteLine("--------- Results ---------");
                Console.WriteLine("    Classification: " + cls + "%");
                Console.WriteLine("    Grouping:       " + grp + "%");
                Console.WriteLine("    Recognition out of correctly grouped groups:    " + rec + "%");
                Console.WriteLine("    Recognition out of all the groups:    " + realRec + "%");
                Console.WriteLine("    Substroke Rec.: " + srec + "%");

                _tables[pipeline].addResult(new string[] {
                    filename,
                    "" + cls,
                    "" + grp,
                    "" + rec,
                    "" + realRec,
                    "" + srec
                });

                _classificationConfusion[pipeline].AddResults(comparer.ClassificationConfusion);
                _recognitionConfusion[pipeline].AddResults(comparer.RecognitionConfusion);

                _cls[pipeline]     += cls;
                _grp[pipeline]     += grp;
                _rec[pipeline]     += rec;
                _realRec[pipeline] += realRec;
                _srec[pipeline]    += srec;
            }
        }