too

package module
v0.0.0-...-0be5828 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2016 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Too

Build Status

Too is a simple recommendation engine built on top of Redis in Go.

Installation

Install Too using the go get command:

$ go get github.com/hjr265/too

The only dependencies are Go distribution and Redis.

Usage

te, err := too.New("redis://localhost", "movies")
if err != nil {
	log.Fatal(err)
}

te.Likes.Add("Sonic", "The Shawshank Redemption")
te.Likes.Add("Sonic", "The Godfather")
te.Likes.Add("Sonic", "The Dark Knight")
te.Likes.Add("Sonic", "Pulp Fiction")

te.Likes.Add("Mario", "The Godfather")
te.Likes.Add("Mario", "The Dark Knight")
te.Likes.Add("Mario", "The Shawshank Redemption")
te.Likes.Add("Mario", "The Prestige")
te.Likes.Add("Mario", "The Matrix")

te.Likes.Add("Peach", "The Godfather")
te.Likes.Add("Peach", "Inception")
te.Likes.Add("Peach", "Fight Club")
te.Likes.Add("Peach", "WALL·E")
te.Likes.Add("Peach", "Princess Mononoke")

te.Likes.Add("Luigi", "The Prestige")
te.Likes.Add("Luigi", "The Dark Knight")

items, _ := te.Suggestions.For("Luigi", 2)
for _, item := range items {
	fmt.Println(item)
}

// Output:
// The Shawshank Redemption
// The Matrix
Batch Operations
te, err := too.New("redis://localhost", "movies")
if err != nil {
	log.Fatal(err)
}

te.Likes.Batch([]too.BatchRaterOp{
  {
    User: "Sonic",
    Items: []too.Item{
      "The Shawshank Redemption",
      "The Godfather",
      "The Dark Knight",
      "Pulp Fiction",
    },
  },
  {
    User: "Mario",
    Items: []too.Item{
      "The Godfather",
      "The Dark Knight",
      "The Shawshank Redemption",
      "The Prestige",
      "The Matrix",
    },
  },
  {
    User: "Peach",
    Items: []too.Item{
      "The Godfather",
      "Inception",
      "Fight Club",
      "WALL·E",
      "Princess Mononoke",
    },
  },
}, true) // The last command is about auto update the similars and Suggestions table

Documentation

Contributing

Contributions are welcome.

License

Too is available under the BSD (3-Clause) License.

Inspiration

This project is inspired by the very existence of the awesome project Recommendable.

Documentation

Overview

Package too provides a recommendation engine implementation built on top of Redis

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchRaterOp

type BatchRaterOp struct {
	User  User
	Items []Item
}

type Engine

type Engine struct {
	Likes    Rater
	Dislikes Rater

	Similars    Similars
	Suggestions Suggestions
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"log"

	"github.com/hjr265/too"
)

func main() {
	te, err := too.New("redis://localhost", "movies")
	if err != nil {
		log.Fatal(err)
	}

	te.Likes.Add("Sonic", "The Shawshank Redemption")
	te.Likes.Add("Sonic", "The Godfather")
	te.Likes.Add("Sonic", "The Dark Knight")
	te.Likes.Add("Sonic", "Pulp Fiction")

	te.Likes.Add("Mario", "The Godfather")
	te.Likes.Add("Mario", "The Dark Knight")
	te.Likes.Add("Mario", "The Shawshank Redemption")
	te.Likes.Add("Mario", "The Prestige")
	te.Likes.Add("Mario", "The Matrix")

	te.Likes.Add("Peach", "The Godfather")
	te.Likes.Add("Peach", "Inception")
	te.Likes.Add("Peach", "Fight Club")
	te.Likes.Add("Peach", "WALL·E")
	te.Likes.Add("Peach", "Princess Mononoke")

	te.Likes.Add("Luigi", "The Prestige")
	te.Likes.Add("Luigi", "The Dark Knight")

	items, _ := te.Suggestions.For("Luigi", 2)
	for _, item := range items {
		fmt.Println(item)
	}

}
Output:

The Shawshank Redemption
The Matrix

func New

func New(url, class string) (*Engine, error)

New returns a new engine for given class connected to Redis server at addr.

func (*Engine) DisableAutoUpdateSimilarsAndSuggestions

func (e *Engine) DisableAutoUpdateSimilarsAndSuggestions()

func (*Engine) EnableAutoUpdateSimilarsAndSuggestions

func (e *Engine) EnableAutoUpdateSimilarsAndSuggestions()

func (Engine) Update

func (e Engine) Update(user User) error

type Item

type Item string

type Rater

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

func (Rater) Add

func (r Rater) Add(user User, item Item) error

Add adds a rating by user for item

func (Rater) Batch

func (r Rater) Batch(ops []BatchRaterOp, updateSimilarsAndSuggestions bool) error

type Similars

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

func (Similars) Jaccard

func (s Similars) Jaccard(user, other User) (float64, error)

Jaccard returns the Jaccard coefficient between user and other

func (Similars) Of

func (s Similars) Of(user User, n int) ([]User, error)

Of returns n users similar to user

type Suggestions

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

func (Suggestions) For

func (s Suggestions) For(user User, n int) ([]Item, error)

For returns n suggested items for user

type User

type User string

Jump to

Keyboard shortcuts

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