Skip to content

umairayub79/Balochi-Spellchecker

Repository files navigation

📖 Balochi Spellchecker

npm version npm downloads MIT License

A spellchecker for the Balochi language, built using BK-trees and Levenshtein distance.

This library lets you:

  • ✅ Verify if a Balochi word is spelled correctly
  • 🔍 Generate suggestions for misspelled words
  • 📦 Use it in Node.js, web apps, or as a base for APIs/CLIs

The wordlist (~16,000 words) is sourced from the SayadGanj Dictionary, one of the most comprehensive Balochi lexicons available.


🚀 Installation

npm install balochi-spellcheck

✨ Usage

ES Modules

import SpellChecker from "balochi-spellcheck";

// Initialize spellchecker
const checker = new SpellChecker();

CommonJS

const SpellChecker = require("balochi-spellcheck");

// Initialize spellchecker
const checker = new SpellChecker();

Browser (via CDN)

<script src="https://unpkg.com/balochi-spellcheck"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/balochi-spellcheck"></script>

<script>
  const checker = new SpellChecker();

// Check correctness
console.log(checker.isCorrect("جام")); 
// → true

console.log(checker.isCorrect("جامف")); 
// → false

// Get suggestions
console.log(checker.suggest("جامف", 2, 5));
// → ["جامی", "جامگ", "جامو", "جام", "جا"]

⚙️ API Reference

new SpellChecker(customWords = [])

Creates a spellchecker instance.

  • customWords (Array) — Optional wordlist. Defaults to SayadGanj data.

.isCorrect(word: string): boolean

Returns true if word exists in the dictionary, otherwise false.


.suggest(word: string, maxDist = 2, limit = 5): string[]

Returns a ranked array of suggestions.

  • word (string) — Input word to check
  • maxDist (number) — Maximum edit distance allowed (default 2)
  • limit (number) — Maximum number of suggestions (default 5)

Ranking is done by:

  1. Lowest edit distance
  2. Closest word length

📚 Wordlist Source

This package uses ~16,000 words from the SayadGanj Dictionary. Full credit goes to the dictionary maintainers and the wider Balochi linguistic community.


🌍 Real-world Applications

  • Spellchecking for editors, keyboards, or search bars
  • Autocomplete in Balochi typing tools
  • Search improvement (catching typos in queries)
  • Language research and digital preservation of Balochi

🛠 Development

Clone and install:

git clone https://github.com/umairayub79/balochi-spellcheck.git
cd balochi-spellcheck
npm install

Run tests:

npm test

🤝 Contributing

Contributions are welcome!

  • Fork the repo
  • Add features / bugfixes
  • Submit a PR

We especially encourage contributions in:

  • Expanding/validating the wordlist
  • Improving suggestion ranking
  • Adding transliteration & grammar support

📜 License

MIT License © 2025 Umair Ayub


⭐ Acknowledgements

  • SayadGanj Dictionary — primary data source
  • Balochi language community for keeping the language alive digitally
  • Open-source libraries: fast-levenshtein