client

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Gorse Client

Go SDK for Gorse recommender system.

⚠️⚠️⚠️ This SDK is unstable currently. APIs might be changed in later versions.

Install

go get github.com/zhenghaoz/gorse/client@master

Usage

import "github.com/zhenghaoz/gorse/client"

gorse := client.NewGorseClient("http://127.0.0.1:8087", "api_key")

gorse.InsertFeedback([]client.Feedback{
    {FeedbackType: "star", UserId: "bob", ItemId: "vuejs:vue", Timestamp: "2022-02-24"},
    {FeedbackType: "star", UserId: "bob", ItemId: "d3:d3", Timestamp: "2022-02-25"},
    {FeedbackType: "star", UserId: "bob", ItemId: "dogfalo:materialize", Timestamp: "2022-02-26"},
    {FeedbackType: "star", UserId: "bob", ItemId: "mozilla:pdf.js", Timestamp: "2022-02-27"},
    {FeedbackType: "star", UserId: "bob", ItemId: "moment:moment", Timestamp: "2022-02-28"},
})

gorse.GetRecommend("bob", "", 10)

Test

In the root directory of Gorse source:

# Setup Gorse
docker-compose up -d

# Test
go test -tags='integrate_test' ./client/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorMessage

type ErrorMessage string

func (ErrorMessage) Error

func (e ErrorMessage) Error() string

type Feedback

type Feedback struct {
	FeedbackType string `json:"FeedbackType"`
	UserId       string `json:"UserId"`
	ItemId       string `json:"ItemId"`
	Timestamp    string `json:"Timestamp"`
}

type GorseClient

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

func NewGorseClient

func NewGorseClient(entryPoint, apiKey string) *GorseClient

func (*GorseClient) DeleteItem

func (c *GorseClient) DeleteItem(ctx context.Context, itemId string) (RowAffected, error)

func (*GorseClient) DeleteUser

func (c *GorseClient) DeleteUser(ctx context.Context, userId string) (RowAffected, error)

func (*GorseClient) GetItem

func (c *GorseClient) GetItem(ctx context.Context, itemId string) (Item, error)

func (*GorseClient) GetNeighbors

func (c *GorseClient) GetNeighbors(ctx context.Context, itemId string, n int) ([]Score, error)

func (*GorseClient) GetRecommend

func (c *GorseClient) GetRecommend(ctx context.Context, userId string, category string, n int) ([]string, error)

func (*GorseClient) GetUser

func (c *GorseClient) GetUser(ctx context.Context, userId string) (User, error)

func (*GorseClient) InsertFeedback

func (c *GorseClient) InsertFeedback(ctx context.Context, feedbacks []Feedback) (RowAffected, error)

func (*GorseClient) InsertItem

func (c *GorseClient) InsertItem(ctx context.Context, item Item) (RowAffected, error)

func (*GorseClient) InsertUser

func (c *GorseClient) InsertUser(ctx context.Context, user User) (RowAffected, error)

func (*GorseClient) ListFeedbacks

func (c *GorseClient) ListFeedbacks(ctx context.Context, feedbackType, userId string) ([]Feedback, error)

func (*GorseClient) SessionRecommend

func (c *GorseClient) SessionRecommend(ctx context.Context, feedbacks []Feedback, n int) ([]Score, error)

func (*GorseClient) UpdateItem added in v0.4.12

func (c *GorseClient) UpdateItem(ctx context.Context, itemId string, item ItemPatch) (RowAffected, error)

func (*GorseClient) UpdateUser added in v0.4.12

func (c *GorseClient) UpdateUser(ctx context.Context, userId string, user UserPatch) (RowAffected, error)

type Item

type Item struct {
	ItemId     string   `json:"ItemId"`
	IsHidden   bool     `json:"IsHidden"`
	Labels     []string `json:"Labels"`
	Categories []string `json:"Categories"`
	Timestamp  string   `json:"Timestamp"`
	Comment    string   `json:"Comment"`
}

type ItemPatch added in v0.4.12

type ItemPatch struct {
	IsHidden   *bool
	Categories []string
	Timestamp  *time.Time
	Labels     []string
	Comment    *string
}

type RowAffected

type RowAffected struct {
	RowAffected int `json:"RowAffected"`
}

type Score

type Score struct {
	Id    string `json:"Id"`
	Score int    `json:"Score"`
}

type User

type User struct {
	UserId    string   `json:"UserId"`
	Labels    []string `json:"Labels"`
	Subscribe []string `json:"Subscribe"`
	Comment   string   `json:"Comment"`
}

type UserPatch added in v0.4.12

type UserPatch struct {
	Labels    []string
	Subscribe []string
	Comment   *string
}

Jump to

Keyboard shortcuts

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