https://github.com/securisec/go-keywords
Keyword extraction using go
https://github.com/securisec/go-keywords
extract go keyword-extraction keywords
Last synced: about 1 year ago
JSON representation
Keyword extraction using go
- Host: GitHub
- URL: https://github.com/securisec/go-keywords
- Owner: securisec
- License: gpl-3.0
- Created: 2020-06-13T21:56:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-19T13:59:56.000Z (about 6 years ago)
- Last Synced: 2025-05-28T14:03:11.300Z (about 1 year ago)
- Topics: extract, go, keyword-extraction, keywords
- Language: Go
- Size: 37.1 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# go-keywords
`go-keywords` is an attempt to port over the npm package `keyword-extractor`. It is not as in depth as its npm package, but gets the work done. `go-keywords` works with both regular strings, and html data.
**Why?** While in search for a simple keyword extractor, i came across a few packages that uses the RAKE concept, but for my use case to simply extract individual keywords, it wasnt sufficient.
## Install
```go
go get github.com/securisec/go-keywords
```
## Use
### keywords.ExtractOptions
The `Extract` functions default behavior can be altered passing the `ExtractOptions` struct. The options and their default values are:
```go
type ExtractOptions struct {
RemoveDigits bool // Remove digits from found words. Defaults to true
RemoveDuplicates bool // Remove duplications from found words. Defaults to true
Lowercase bool // Change all found words to lowercase. Defaults to true
Language string // Language to use for keywords extraction. Defaults to "en"
AddStopwords []string // Append additional stopwords to ignore. Defaults to empty array
IgnorePattern string // Ignore matches for the specified regex pattern. Defaults to ""
StripTags bool // Strip HTML tags. Defaults to false
}
```
### Simple use case
```go
package main
import (
"fmt"
"github.com/securisec/go-keywords"
)
func main() {
data := " How to solve a GeeTest 1 123 “slider CAPTCHA” with JS "
k, _ := keywords.Extract(data)
fmt.Println(k)
}
// [solve geetest slider captcha js]
```
### Get keywords from html
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/securisec/go-keywords"
)
func main() {
req, _ := http.Get("http://example.com")
data, _ := ioutil.ReadAll(req.Body)
k, _ := keywords.Extract(string(data), keywords.ExtractOptions{
StripTags: true,
RemoveDuplicates: true,
IgnorePattern: "<.+>",
Lowercase: true,
})
fmt.Println(k)
}
// [illustrative examples documents information domain literature prior coordination permission]
```