keyphrase GitHub

Installation

The module requires Go 1.26.

go get github.com/tericcabrel/keyphrase@v0.2.0

A blank import registers a language. Import only the languages you need. Each one embeds its own part-of-speech model and rarity table.

One language:

import (
    "fmt"

    "github.com/tericcabrel/keyphrase/extractor"
    _ "github.com/tericcabrel/keyphrase/lang/en"
)

kws, _, err := extractor.Extract(text, "en", 10)
if err != nil {
    panic(err)
}
for _, kw := range kws {
    fmt.Printf(
        "The keyword %s is located between %d and %d\n",
        kw.Text, kw.StartByte, kw.EndByte,
    )
}

Two languages:

import (
    "fmt"

    "github.com/tericcabrel/keyphrase/extractor"
    _ "github.com/tericcabrel/keyphrase/lang/en"
    _ "github.com/tericcabrel/keyphrase/lang/fr"
)

kws, _, err := extractor.Extract(text, "fr", 10)
if err != nil {
    panic(err)
}
for _, kw := range kws {
    fmt.Printf(
        "The keyword %s is located between %d and %d\n",
        kw.Text, kw.StartByte, kw.EndByte,
    )
}

lang/all embeds and registers every built-in language.

import (
    "fmt"

    "github.com/tericcabrel/keyphrase/extractor"
    _ "github.com/tericcabrel/keyphrase/lang/all"
)

kws, _, err := extractor.Extract(text, "de", 10)
if err != nil {
    panic(err)
}
for _, kw := range kws {
    fmt.Printf(
        "The keyword %s is located between %d and %d\n",
        kw.Text, kw.StartByte, kw.EndByte,
    )
}

Call extractor.Extract. It returns the phrases, a count summary, and an error. Leave the ExtractOptions argument out for the defaults, or pass one value. The blank identifier in the examples is the count summary. lang, postag, and rarity are public packages. lang.Pack is how you add a language. The fields are on the reference page.

Package docs: pkg.go.dev/github.com/tericcabrel/keyphrase.