NeowayLabs / go-tfidf

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:MIT License


Languages

Language:Go 89.6%Language:Makefile 7.9%Language:Dockerfile 2.0%Language:Shell 0.5%