Extract keyphrases in Go
keyphrase is a Go library that returns a few short phrases from plain text. Each phrase is copied from the text you pass in. You pass the language code.
A phrase is at most three words and contains no verbs. A single word is kept only when it is a name, written like a name, or a rare common noun.
import (
"github.com/tericcabrel/keyphrase/extractor"
_ "github.com/tericcabrel/keyphrase/lang/en"
)
text := `Offshore wind farms are becoming the backbone of Britain's energy
strategy. The government wants offshore wind capacity to reach 50
gigawatts by 2030, enough to power every home in the country.
The largest project, Dogger Bank Wind Farm, sits more than 130
kilometres off the Yorkshire coast. When complete, Dogger Bank will
use 277 turbines, each taller than the Eiffel Tower. Engineers say
the turbines can generate electricity even in moderate winds.
Grid connections remain the biggest obstacle. National Grid has
warned that some offshore wind farms may wait years before they can
connect to the transmission network. Developers also face rising
steel prices and higher interest rates, which have pushed up the
cost of building turbines at sea.`
kws, err := extractor.Extract(text, "en", 10)
The call returns these phrases.
| Phrase | Score | Bytes |
|---|---|---|
| Offshore wind | 1.0000 | 0-13 |
| Dogger Bank | 0.8017 | 309-320 |
| Britain | 0.7768 | 49-56 |
| Yorkshire | 0.7406 | 277-286 |
| turbines | 0.7376 | 334-342 |
| Eiffel Tower | 0.7371 | 365-377 |
| National Grid | 0.6649 | 502-515 |
| backbone | 0.5958 | 37-45 |
| wind capacity | 0.5389 | 106-119 |
| largest project | 0.4944 | 199-214 |
Supported languages are English, French, German, Spanish, and Italian. Requires Go 1.26.
Try the extractor on text you paste, or on a page you load. Then install the module and read the function reference.