regommend

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

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

Go to latest
Published: Aug 7, 2019 License: AGPL-3.0 Imports: 7 Imported by: 4

README

regommend

Recommendation engine for Go

Installation

Make sure you have a working Go environment (Go 1.2 or higher is required). See the install instructions.

To install regommend, simply run:

go get github.com/muesli/regommend

To compile it from source:

cd $GOPATH/src/github.com/muesli/regommend
go get -u -v
go build && go test -v

Example

package main

import (
	"github.com/muesli/regommend"
	"fmt"
)

func main() {
	// Accessing a new regommend table for the first time will create it.
	books := regommend.Table("books")

	booksChrisRead := make(map[interface{}]float64)
	booksChrisRead["1984"] = 5.0
	booksChrisRead["Robinson Crusoe"] = 4.0
	booksChrisRead["Moby-Dick"] = 3.0
	books.Add("Chris", booksChrisRead)

	booksJayRead := make(map[interface{}]float64)
	booksJayRead["1984"] = 5.0
	booksJayRead["Robinson Crusoe"] = 4.0
	booksJayRead["Gulliver's Travels"] = 4.5
	books.Add("Jay", booksJayRead)

	recs, _ := books.Recommend("Chris")
	for _, rec := range recs {
		fmt.Println("Recommending", rec.Key, "with score", rec.Distance)
	}

	neighbors, _ := books.Neighbors("Chris")
	...
}

To run this example, go to example/ and run:

go run example.go

Development

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistancePair

type DistancePair struct {
	Key      interface{}
	Distance float64
}

type DistancePairList

type DistancePairList []DistancePair

func (DistancePairList) Len

func (p DistancePairList) Len() int

func (DistancePairList) Less

func (p DistancePairList) Less(i, j int) bool

func (DistancePairList) Swap

func (p DistancePairList) Swap(i, j int)

type RegommendItem

type RegommendItem struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Structure of an item in the recommendation engine. Parameter data contains the user-set value in the engine.

func CreateRegommendItem

func CreateRegommendItem(key interface{}, data map[interface{}]float64) RegommendItem

CreateRegommendItem returns a newly created RegommendItem. Parameter key is the item's key. Parameter data is the item's value.

func (*RegommendItem) Data

func (item *RegommendItem) Data() map[interface{}]float64

Data returns the value of this item.

func (*RegommendItem) Key

func (item *RegommendItem) Key() interface{}

Key returns the key of this item.

type RegommendTable

type RegommendTable struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Structure of a table with items in the engine.

func Table

func Table(table string) *RegommendTable

Table returns the existing engine table with given name or creates a new one if the table does not exist yet.

func (*RegommendTable) Add

func (table *RegommendTable) Add(key interface{}, data map[interface{}]float64) *RegommendItem

Add adds a key/value pair to the engine. Parameter key is the item's engine-key. Parameter data is the item's value.

func (*RegommendTable) Count

func (table *RegommendTable) Count() int

Count returns how many items are currently stored in the engine.

func (*RegommendTable) Delete

func (table *RegommendTable) Delete(key interface{}) (*RegommendItem, error)

Delete an item from the engine.

func (*RegommendTable) Exists

func (table *RegommendTable) Exists(key interface{}) bool

Test whether an item exists in the engine. Unlike the Value method Exists neither tries to fetch data via the loadData callback nor does it keep the item alive in the engine.

func (*RegommendTable) Flush

func (table *RegommendTable) Flush()

Delete all items from engine.

func (*RegommendTable) Neighbors

func (table *RegommendTable) Neighbors(key interface{}) (DistancePairList, error)

func (*RegommendTable) Recommend

func (table *RegommendTable) Recommend(key interface{}) (DistancePairList, error)

func (*RegommendTable) SetAboutToDeleteItemCallback

func (table *RegommendTable) SetAboutToDeleteItemCallback(f func(*RegommendItem))

Configures a callback, which will be called every time an item is about to be removed from the engine.

func (*RegommendTable) SetAddedItemCallback

func (table *RegommendTable) SetAddedItemCallback(f func(*RegommendItem))

Configures a callback, which will be called every time a new item is added to the engine.

func (*RegommendTable) SetDataLoader

func (table *RegommendTable) SetDataLoader(f func(interface{}) *RegommendItem)

Configures a data-loader callback, which will be called when trying to use access a non-existing key.

func (*RegommendTable) SetLogger

func (table *RegommendTable) SetLogger(logger *log.Logger)

Sets the logger to be used by this engine table.

func (*RegommendTable) Value

func (table *RegommendTable) Value(key interface{}) (*RegommendItem, error)

Value gets an item from the engine and mark it to be kept alive.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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