https://github.com/ptytb/bk-tree
Burkhard-Keller Tree implementation in pure PowerShell
https://github.com/ptytb/bk-tree
dictionary fuzzy-search spell-checker string-matching
Last synced: 8 months ago
JSON representation
Burkhard-Keller Tree implementation in pure PowerShell
- Host: GitHub
- URL: https://github.com/ptytb/bk-tree
- Owner: ptytb
- License: mit
- Created: 2018-04-10T12:31:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-21T18:09:40.000Z (over 7 years ago)
- Last Synced: 2024-12-31T16:19:48.610Z (10 months ago)
- Topics: dictionary, fuzzy-search, spell-checker, string-matching
- Language: PowerShell
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BK-tree
This is a very fast string fuzzy-matching module written in PowerShell.
It uses *Damerau-Levenshtein* distance as metric function
and *BK-tree* structure to represent a search tree.*BK-tree* can be flattened into arrays and loaded later for even faster search.
I wrote this primarily for [pips - Python package browser](https://github.com/ptytb/pips)
# Usage
```PowerShell
Import-Module .\bktree$bktree = [BKTree]::new()
# Building a BK-tree
$bktree.add('fold')
$bktree.add('mold')
$bktree.add('hold')
$bktree.add('bold')
$bktree.add('fork')
$bktree.add('beer')
$bktree.add('hole')
$bktree.add('shim')$candidates = $bktree.Search('cold', 2)
# We've built a dictionary, let's save it
$bktree.SaveArrays('dict.bin')# Load a dictionary. This is supposed to be used in your app along with SearchFast()
$bktree.LoadArrays('dict.bin')$candidates = $bktree.SearchFast('cold', 2)
```Explore and try an example `.\test.ps1` to see it with time measurements.
# Hacking
Uncomment the line `Print-Result` in the `SaveArrays` function to see the internal
structure of the flattened tree.In the arrays, node offset `-2` means it is a parent node, `-1` means node has no children.
# Todo
- [ ] Add method switch to return candidates along with distances
# License
Copyright, 2018, Ilya Pronin.
This code is released under the MIT license.