tek

package module
v0.0.0-...-a52a602 Latest Latest
Warning

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

Go to latest
Published: May 14, 2019 License: MIT Imports: 4 Imported by: 0

README

tek

A golang package to get tags of an article

GoDoc

Installation

go get github.com/JesusIslam/tek

Dependencies

None

Usage
package main

import (
	"fmt"
	"io/ioutil"
	"github.com/JesusIslam/tek"
)

func main() {
	Tb, _ := ioutil.ReadFile("../sample.txt")
	text := string(Tb)
	tek.SetLang("en")
	tags := tek.GetTags(text, 10)
	for _, tag := range tags {
		fmt.Println(tag.Term, tag.Tfidf)
	}
}
Testing

To test, just run go test, but you need to have gomega and ginkgo installed.

Benchmark

Using i3-3217U @1.8GHz with 370 total words from the sample.txt provided and command go test -bench . -benchtime=5s -cpu 4:

BenchmarkGetTagEn-4         1000          11097404 ns/op
BenchmarkGetTagId-4         1000           6295201 ns/op
License

See LICENSE file, it is MIT

Documentation

Overview

tek is an automatic tagging library for Go.

Index

Constants

View Source
const (
	VERSION = "0.1.1"
)

Variables

This section is empty.

Functions

func SetLang

func SetLang(l string) error

Set language used, defaulted to english if not called. If argument is not "id" or "en", empty stop words will be used For now only support Indonesian and English stop words

func SetStopWords

func SetStopWords(s []string)

Define your own stop words by providing a slice of string of stop words

Types

type Info

type Info struct {
	Term  string
	Idf   float64
	Tf    float64
	Tfidf float64
}

func GetTags

func GetTags(text string, num int) []*Info

The main method of this package, return a slice of *Info struct, sorted by their weight descending.

type Vocab

type Vocab struct {
	Id   int    `json:"id"`
	Word string `json:"word"`
	Type string `json:"type"`
}

Jump to

Keyboard shortcuts

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