Beispiel #1
0
        /// <summary>
        /// Con este metodos almacenamos un nuevo simbolo en la base de
        /// datos.
        ///
        /// Lanza <c>DuplicateSymbolException</c> si ya existe un simbolo
        /// con la misma etiqueta y caracteristicas binarias en la base de datos.
        /// </summary>
        /// <param name="bitmap">
        /// La imagen cuyas caracteristicas aprenderemos.
        /// </param>
        /// <param name="symbol">
        /// El simbolo que representa a la imagen.
        ///</param>
        public override bool Learn(MathTextBitmap bitmap, MathSymbol symbol)
        {
            if (characteristics == null)
            {
                characteristics = CharacteristicFactory.CreateCharacteristicList();
            }

            CharacteristicNode node = rootNode;
            bool characteristicValue;

            FloatBitmap processedBitmap = bitmap.LastProcessedImage;

            // Recorremos las caracteristicas, y vamos creando el arbol segun
            // vamos necesitando nodos.
            foreach (BinaryCharacteristic bc in characteristics)
            {
                if (characteristicValue = bc.Apply(processedBitmap))
                {
                    if (node.TrueTree == null)
                    {
                        node.TrueTree = new CharacteristicNode();
                    }

                    node = node.TrueTree;
                }
                else
                {
                    if (node.FalseTree == null)
                    {
                        node.FalseTree = new CharacteristicNode();
                    }
                    node = node.FalseTree;
                }

                StepDoneArgs a =
                    CreateStepDoneArgs(bc, characteristicValue, null);

                this.StepDoneInvoker(a);
            }

            return(node.AddSymbol(symbol));
        }
		/// <summary>
		/// Constructor de <c>CharacteristicDatabase</c>. Crea una base de datos
		/// vacia, sin ningun simbolo aprendido.
		/// </summary>
		public CharacteristicTreeDatabase() : base()
		{	
			rootNode=new CharacteristicNode();
		}
Beispiel #3
0
 /// <summary>
 /// Constructor de <c>CharacteristicDatabase</c>. Crea una base de datos
 /// vacia, sin ningun simbolo aprendido.
 /// </summary>
 public CharacteristicTreeDatabase() : base()
 {
     rootNode = new CharacteristicNode();
 }
Beispiel #4
0
        /// <summary>
        /// Este metodo intenta recuperar los simbolos de la base de datos
        /// correspondiente a una imagen.
        /// </summary>
        /// <param name="image">
        /// La imagen cuyos simbolos asociados queremos encontrar.
        /// </param>
        /// <returns>
        /// Los simbolos que se puedieron asociar con la imagen.
        /// </returns>
        public override List <MathSymbol> Match(MathTextBitmap image)
        {
            if (characteristics == null)
            {
                characteristics = CharacteristicFactory.CreateCharacteristicList();
            }

            List <MathSymbol>    res  = new List <MathSymbol>();
            CharacteristicNode   nodo = rootNode;
            BinaryCharacteristic bc;

            bool exists = true;
            bool characteristicValue;

            List <bool> vector = new List <bool>();

            FloatBitmap processedImage = image.LastProcessedImage;

            for (int i = 0; i < characteristics.Count && exists; i++)
            {
                bc = (BinaryCharacteristic)(characteristics[i]);

                if (characteristicValue = bc.Apply(processedImage))
                {
                    if (nodo.TrueTree == null)
                    {
                        exists = false;
                    }
                    nodo = nodo.TrueTree;
                }
                else
                {
                    if (nodo.FalseTree == null)
                    {
                        exists = false;
                    }
                    nodo = nodo.FalseTree;
                }

                StepDoneArgs args;
                //Avisamos de que hemos dado un paso
                if (nodo != null)
                {
                    args = CreateStepDoneArgs(bc,
                                              characteristicValue,
                                              nodo.ChildrenSymbols);
                }
                else
                {
                    args = CreateStepDoneArgs(bc,
                                              characteristicValue,
                                              null);
                }

                StepDoneInvoker(args);
            }

            if (exists)
            {
                res = nodo.Symbols;
            }

            return(res);
        }