textrank

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2020 License: MIT Imports: 5 Imported by: 1

README

TextRank

The TextRank algorithm implemented in Go. This particular implementation is suited for sentence extraction and is based off the paper by Rada Mihalcea and Paul Tarau (2004).

Example

package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/joshleeb/textrank"
)

func main() {
	bytes, _ := ioutil.ReadAll(os.Stdin)
	text := string(bytes)

	// Iterating 30 times was chosen based on the convergence curves in Figure 1
	// of "TextRank: Bringing Order into Texts" by Rada Mihalcea and Paul Tarau,
	// 2004 - https://web.eecs.umich.edu/~mihalcea/papers/mihalcea.emnlp04.pdf
	words := textrank.RankWords(text, 30)[:5]
	fmt.Println(words)

	// Iterating 5 times was chosen based on the convergence curves in Figure 1
	// of "TextRank: Bringing Order into Texts" by Rada Mihalcea and Paul Tarau,
	// 2004 - https://web.eecs.umich.edu/~mihalcea/papers/mihalcea.emnlp04.pdf
	sentences := textrank.RankSentences(text, 5)
	for _, sentence := range sentences[:5] {
		fmt.Println("\n" + sentence)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RankSentences

func RankSentences(text string, iterations int) []string

RankSentences ranks the sentences in the given text based on the TextRank algorithm and returned a list of the ranked sentences in descending order or score.

func RankWords

func RankWords(text string, iterations int) []string

RankWords ranks the words in the given text based on the TextRank algorithm and returned a list of the ranked words in descending order or score.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL