Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wamuir/enchant
Go bindings for the Enchant-2 spellcheck library. A fork of https://github.com/hermanschaaf/enchant
https://github.com/wamuir/enchant
enchant golang spelling
Last synced: 18 days ago
JSON representation
Go bindings for the Enchant-2 spellcheck library. A fork of https://github.com/hermanschaaf/enchant
- Host: GitHub
- URL: https://github.com/wamuir/enchant
- Owner: wamuir
- License: mit
- Created: 2021-07-11T16:35:33.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-28T14:31:25.000Z (over 1 year ago)
- Last Synced: 2024-10-30T08:20:05.779Z (2 months ago)
- Topics: enchant, golang, spelling
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go-Enchant
==========[![Go Reference](https://pkg.go.dev/badge/github.com/wamuir/enchant.svg)](https://pkg.go.dev/github.com/wamuir/enchant)
[![Build Status](https://github.com/wamuir/enchant/actions/workflows/go.yml/badge.svg?branch=master&event=push)](https://github.com/wamuir/enchant/actions/workflows/go.yml?query=event%3Apush+branch%3Amaster)
[![codecov](https://codecov.io/gh/wamuir/enchant/branch/master/graph/badge.svg)](https://codecov.io/gh/wamuir/enchant)
[![Go Report Card](https://goreportcard.com/badge/github.com/wamuir/enchant)](https://goreportcard.com/report/github.com/wamuir/enchant)Go-Enchant provides bindings for the C [Enchant2 Spellcheck Library](http://www.abisource.com/projects/enchant/) in Go. Instead of offering direct mappings to the Enchant functions, it abstracts away some complexity and makes it easier to do resource management in Go. Go-Enchant is a fork of [hermanschaaf/enchant](https://github.com/hermanschaaf/enchant) with only minimal modification.
### Installation
First off, you will need to have the [`libenchant-2`](https://packages.debian.org/search?keywords=libenchant-2-dev) development files installed, along with any dictionaries you might want to use (aspell, hunspell, etc):
```bash
sudo apt-get install libenchant-2-dev
```Then install this package with `go get`:
```bash
go get github.com/wamuir/enchant
```### Usage
Basic usage is illustrated by the following example program:
```go
package mainimport (
"fmt"
"github.com/wamuir/enchant"
)func main() {
// create a new enchant instance
enchant, err := enchant.NewEnchant()
if err != nil {
panic("Enchant error: " + err.Error())
}// defer freeing memory to the end of this program
defer enchant.Free()// check whether a certain dictionary exists on the system
has_en := enchant.DictExists("en_GB")// load the english dictionary:
if has_en {
enchant.LoadDict("en_GB")// see if a word is in the dictionary:
fmt.Println("hallo:", enchant.Check("hallo"))// and one that won't be in there:
fmt.Println("wollo:", enchant.Check("wollo"))// now let's get some suggestions for "wollo":
fmt.Println(enchant.Suggest("wollo"))
}
}
```1. First, we create a new Enchant instance using the `NewEnchant` function.
2. We defer a call to `enchant.Free()` to free memory allocation when our program ends. `Free()` handles the freeing of both the Enchant broker and loaded dictionaries.
3. Next, we check whether a certain dictionary is installed on the system using a call to `enc.DictExists()`.
4. We know the dictionary exists now, so we load it into our Enchant instance with a call to `LoadDict()`.
5. Now we are free to make any calls to Enchant that we want. We call `Check`, which returns whether the given word is contained in the dictionary or not. We expect `"hallo"` to be in the dictionary, and `"wollo"` not to be. Indeed, our program output confirms this:
```
hallo: true
wollo: false
[Rollo woolly hollow follow woollen would worldly]
```The final line is the result of our call to `enc.Suggest("wollo")`: it returns a slice of spelling suggestions for the given word.
### Documentation
Full documentation can be found at [godoc.org/github.com/hermanschaaf/enchant](http://godoc.org/github.com/hermanschaaf/enchant)