database

package
v0.0.0-...-e4649f2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package database exposes a DataStore interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category represents a sentiment category.

type Data

type Data struct {
	Texts      map[ID]Text
	Sentiments map[Category]Sentiment
	TotalTexts int
}

Data is the main data-structure that the current implementation holds.

type DataStore

type DataStore interface {
	InsertText(t string) (Text, error)
	UpdateSentiment(catg string, tcount int) (map[Category]Sentiment, error)
	FetchSentiments() (map[Category]Sentiment, error)
	FetchCategorySentiments(catg string) (map[Category]Sentiment, error)
}

DataStore is a database interface that can be implemented by different kinds of databases.

func GetDatastore

func GetDatastore() DataStore

GetDatastore instantiates a DataStore.

type ID

type ID string

ID represents ID of a Text, it is the string form of a UUID in the current implementation.

type MemoryDB

type MemoryDB struct {
	// contains filtered or unexported fields
}

MemoryDB indicates an in-memory database.

func (*MemoryDB) FetchCategorySentiments

func (mdb *MemoryDB) FetchCategorySentiments(catg string) (map[Category]Sentiment, error)

FetchCategorySentiments returns the Sentiment details of the supplied category.

func (*MemoryDB) FetchSentiments

func (mdb *MemoryDB) FetchSentiments() (map[Category]Sentiment, error)

FetchSentiments returns the sentiment details of all the available categories.

func (*MemoryDB) InsertText

func (mdb *MemoryDB) InsertText(t string) (Text, error)

InsertText is exposed by DataStore interface. MemoryDB implements this method.

func (*MemoryDB) UpdateSentiment

func (mdb *MemoryDB) UpdateSentiment(catg string, tcount int) (map[Category]Sentiment, error)

UpdateSentiment updates the sentiment value of a supplied category as well as for other categories, based on the new texts count.

type Sentiment

type Sentiment struct {
	Value     float64
	TextCount int
}

Sentiment represents the sentiment details of a category.

type Text

type Text struct {
	ID
	TextString string
}

Text specifies the text object to be stored in the DB.

Jump to

Keyboard shortcuts

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