text-processing-algorithms/README.md

81 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2026-01-21 11:37:28 -08:00
# @uwuapps/algorithms
High-performance algorithms for text processing and data structures.
## Installation
```bash
npm install @uwuapps/algorithms
```
## Features
### Distance Algorithms
- **Levenshtein Distance**: Classic edit distance algorithm
- **Optimized Levenshtein**: Space-optimized O(min(n,m)) implementation
- **Damerau-Levenshtein**: Includes transpositions for better typo detection
### Phonetic Algorithms
- **Soundex**: Classic phonetic encoding
- **Metaphone**: Improved English pronunciation rules
- **Double Metaphone**: Handles multiple pronunciations
### Data Structures
- **Trie**: Efficient prefix tree with frequency tracking
## Usage
### Distance Algorithms
```typescript
import { LevenshteinDistance, DamerauLevenshtein } from '@uwuapps/algorithms/distance';
const levenshtein = new LevenshteinDistance();
const distance = levenshtein.calculate('hello', 'hallo'); // 1
const similarity = levenshtein.similarity('hello', 'hallo'); // 0.8
const damerau = new DamerauLevenshtein();
const typoDistance = damerau.calculate('teh', 'the'); // 1 (transposition)
```
### Phonetic Algorithms
```typescript
import { Soundex, Metaphone } from '@uwuapps/algorithms/phonetic';
const soundex = new Soundex();
const code = soundex.encode('Smith'); // S530
const soundsLike = soundex.soundsLike('Smith', 'Smythe'); // true
const metaphone = new Metaphone();
const phoneticCode = metaphone.encode('phone'); // FN
```
### Data Structures
```typescript
import { Trie } from '@uwuapps/algorithms/data-structures';
const trie = new Trie();
trie.insert('hello', 10);
trie.insert('help', 5);
const suggestions = trie.getSuggestions('hel'); // ['hello', 'help']
const exists = trie.search('hello'); // true
```
## Performance
All algorithms are optimized for performance:
- Caching for repeated calculations
- Early termination with max distance
- Space-optimized implementations
- Efficient data structures
## License
2026-01-30 11:59:49 -08:00
MIT