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); } } } }
/** * 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); }
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; }
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); } } } }
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); }
/** * 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)); }
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); }
/** * 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); }
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)); }
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); } }
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); } }
protected abstract int calculateDistance(BKTreeNode node);
/** * 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)); }
protected abstract int calculateDistance(BKTreeNode node);