Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/josuerhea/tfidf

TFIDF implementation in Go
https://github.com/josuerhea/tfidf

go golang

Last synced: about 2 months ago
JSON representation

TFIDF implementation in Go

Awesome Lists containing this project

README

        

# tfidf
An package for my search engine using tfidf

## Example

```go
package main

import (
"fmt"
"log"
"tfidf/tfidf"
"tfidf/util"

"github.com/goccy/go-json"
)

func main() {
fileContent, err := util.ReadFileToString("test-data.json")
if err != nil {
log.Fatal("Error reading the file", err)
}

var parsedData []map[string]interface{}

json.Unmarshal([]byte(fileContent), &parsedData)
t := tfidf.New()
t.AddDocs(parsedData)
{
stopWordsFilePath := "stopwords-en.txt"
error := t.AddStopWordsFile(stopWordsFilePath)
if error != nil {
log.Printf("Cannot add %s because %s", stopWordsFilePath, error.Error())
}
}
{
stopWordsFilePath := "stopwords-es.txt"
error := t.AddStopWordsFile(stopWordsFilePath)
if error != nil {
log.Printf("Cannot add %s because %s", stopWordsFilePath, error.Error())
}
}
t.AddStopWordsFile("stopwords-es.txt")
search := t.CalculateTFIDF("marvel")
fmt.Println(len(search))
for _, value := range search {
fmt.Printf("id: %s -> %f\n", value.ID, value.Rank)
fmt.Printf("value.Data: %v\n", value.Data["description"])
}
}

```