Skip to content

This project implements a library that computes TF-IDF and Similarity

License

Notifications You must be signed in to change notification settings

NeowayLabs/go-tfidf

Repository files navigation

go-tfidf

Build Status Go Report Card

This project implements a library that computes Tf Idf for text documents and similarity

Requirements

  • Go 1.16

Running tests

Requirements

  • Docker

Run the following command:

make check

Install

In your Go project directory, run the following command:

go get -u github.com/NeowayLabs/go-tfidf

Example

import (
	go_tfidf "github.com/NeowayLabs/go-tfidf"
	"github.com/NeowayLabs/go-tfidf/similarity"
)

func main() {
	separator := " "
	similarityFunction := "Cosine"

	inputDocuments := []string{
			"The game of life is a game of everlasting learning",
			"The unexamined life is not worth living",
			"Never stop learning",
		}
	inputQuery := "life learning"

	ti, err := go_tfidf.New(inputDocuments, separator)

	queryTfIdfDocuments, err := ti.CalculateQueryTermsTfIdfForEachDocument(inputQuery)
	queryTfIdf, err := go_tfidf.CalculateQueryTermsTfIdf(inputQuery, ti.DocumentSeparator)

	similarities, err := similarity.CalculateSimilarities(queryTfIdf, queryTfIdfDocuments, similarityFunction)
}

References: https://janav.wordpress.com/2013/10/27/tf-idf-and-cosine-similarity/

About

This project implements a library that computes TF-IDF and Similarity

Resources

License

Stars

Watchers

Forks

Packages

No packages published