Ejemplo n.º 1
0
        public virtual void query(BKTreeNode node, Int32 threshold, Dictionary<BKTreeNode, Int32> collected)
        {
            Int32 distanceAtNode = calculateDistance(node);

            if (distanceAtNode == threshold)
            {
                collected.Add(this, distanceAtNode);
                return;
            }

            if (distanceAtNode < threshold)
            {
                collected.Add(this, distanceAtNode);
            }

            for (Int32 distance = (distanceAtNode - threshold); distance <= (threshold + distanceAtNode); distance++)
            {
                if (_children != null)
                {
                    if (_children.ContainsKey(distance))
                    {
                        _children[distance].query(node, threshold, collected);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /**
         * Attempts to find the closest match to the search node.
         * @param node
         * @return A match that is within the best edit distance of the search node.
         */
        public T findBestNode(BKTreeNode node)
        {
            BKTreeNode bestNode;

            _root.findBestMatch(node, Int32.MaxValue, out bestNode);
            return((T)bestNode);
        }
Ejemplo n.º 3
0
        public virtual Int32 findBestMatch(BKTreeNode node, Int32 bestDistance, out BKTreeNode bestNode)
        {
            Int32 distanceAtNode = calculateDistance(node);

            bestNode = node;

            if(distanceAtNode < bestDistance)
            {
                bestDistance = distanceAtNode;
                bestNode = this;
            }

            Int32 possibleBest = bestDistance;

            foreach (Int32 distance in _children.Keys)
            {
                if (distance < distanceAtNode + bestDistance)
                {
                    possibleBest = _children[distance].findBestMatch(node, bestDistance, out bestNode);
                    if (possibleBest < bestDistance)
                    {
                        bestDistance = possibleBest;
                    }
                }
            }

            return bestDistance;
        }
Ejemplo n.º 4
0
        public virtual void query(BKTreeNode node, Int32 threshold, Dictionary <BKTreeNode, Int32> collected)
        {
            Int32 distanceAtNode = calculateDistance(node);

            if (distanceAtNode == threshold)
            {
                collected.Add(this, distanceAtNode);
                return;
            }

            if (distanceAtNode < threshold)
            {
                collected.Add(this, distanceAtNode);
            }

            for (Int32 distance = (distanceAtNode - threshold); distance <= (threshold + distanceAtNode); distance++)
            {
                if (_children != null)
                {
                    if (_children.ContainsKey(distance))
                    {
                        _children[distance].query(node, threshold, collected);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public virtual Int32 findBestMatch(BKTreeNode node, Int32 bestDistance, out BKTreeNode bestNode)
        {
            Int32 distanceAtNode = calculateDistance(node);

            bestNode = node;

            if (distanceAtNode < bestDistance)
            {
                bestDistance = distanceAtNode;
                bestNode     = this;
            }

            Int32 possibleBest = bestDistance;

            foreach (Int32 distance in _children.Keys)
            {
                if (distance < distanceAtNode + bestDistance)
                {
                    possibleBest = _children[distance].findBestMatch(node, bestDistance, out bestNode);
                    if (possibleBest < bestDistance)
                    {
                        bestDistance = possibleBest;
                    }
                }
            }

            return(bestDistance);
        }
Ejemplo n.º 6
0
        /**
         * This method will find all the close matching Nodes within
         * a certain threshold.  For instance, to search for similar
         * strings, threshold set to 1 will return all the strings that
         * are off by 1 edit distance.
         * @param searchNode
         * @param threshold
         * @return
         */
        public Dictionary <T, Int32> query(BKTreeNode searchNode, Int32 threshold)
        {
            Dictionary <BKTreeNode, Int32> matches = new Dictionary <BKTreeNode, Int32>();

            _root.query(searchNode, threshold, matches);

            return(copyMatches(matches));
        }
Ejemplo n.º 7
0
 protected override Int32 calculateDistance(BKTreeNode node)
 {
     MemorySize.Hits++;
     double[] ceddDiscriptor1 = this.CEDDDiscriptor;
     double[] ceddDiscriptor2 = ((CEDDTreeNode)node).CEDDDiscriptor;
     double dist = CEDD_Descriptor.CEDD.Compare(ceddDiscriptor1, ceddDiscriptor2);
     return Convert.ToInt32(dist);
 }
Ejemplo n.º 8
0
        /**
         * Attempts to find the closest match to the search node.
         * @param node
         * @return A match that is within the best edit distance of the search node.
         */
        public Dictionary <T, Int32> findBestNodeWithDistance(BKTreeNode node)
        {
            BKTreeNode bestNode;
            Int32      distance = _root.findBestMatch(node, Int32.MaxValue, out bestNode);

            _matches.Clear();
            _matches.Add((T)bestNode, distance);
            return(_matches);
        }
Ejemplo n.º 9
0
        protected override Int32 calculateDistance(BKTreeNode node)
        {
            MemorySize.Hits++;
            double[] ceddDiscriptor1 = this.CEDDDiscriptor;
            double[] ceddDiscriptor2 = ((CEDDTreeNode)node).CEDDDiscriptor;
            double   dist            = CEDD_Descriptor.CEDD.Compare(ceddDiscriptor1, ceddDiscriptor2);

            return(Convert.ToInt32(dist));
        }
Ejemplo n.º 10
0
        public virtual void add(BKTreeNode node)
        {
            if (_children == null)
                _children = new SortedDictionary<Int32, BKTreeNode>();

            Int32 distance = calculateDistance(node);

            if (_children.ContainsKey(distance))
            {
                _children[distance].add(node);
            }
            else
            {
                _children.Add(distance, node);
            }
        }
Ejemplo n.º 11
0
        public virtual void add(BKTreeNode node)
        {
            if (_children == null)
            {
                _children = new SortedDictionary <Int32, BKTreeNode>();
            }

            Int32 distance = calculateDistance(node);

            if (_children.ContainsKey(distance))
            {
                _children[distance].add(node);
            }
            else
            {
                _children.Add(distance, node);
            }
        }
Ejemplo n.º 12
0
 protected abstract int calculateDistance(BKTreeNode node);
Ejemplo n.º 13
0
        /**
         * Attempts to find the closest match to the search node.
         * @param node
         * @return The edit distance of the best match
         */
        public Int32 findBestDistance(BKTreeNode node)
        {
            BKTreeNode bestNode;

            return(_root.findBestMatch(node, Int32.MaxValue, out bestNode));
        }
Ejemplo n.º 14
0
 protected abstract int calculateDistance(BKTreeNode node);