meanrecipe

package
v3.0.0-...-10ee77d Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UseTor bool

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func CreateClusters

func CreateClusters(folder string, numClusters int, requiredIngredients []string) (err error)

func DetermineIngredients

func DetermineIngredients(line string) (ingredients []string)

DetermineIngredients will look through a list of ingredients from longest name to shortest, and pick the first one that is in the line

func DownloadAll

func DownloadAll(folder string, urls []string) (err error)

func DownloadOne

func DownloadOne(folder, url string) (fname string, err error)

func GetAllRecipes

func GetAllRecipes(folder string) (err error)

GetALlRecipes will gather all recipes in a folder

func GetDirections

func GetDirections(recipe string, include []string, exclude []string) (directions []string, err error)

func GetIngredientFrequencies

func GetIngredientFrequencies(meanRecipes []Recipe) (commonIngredients []string, rareIngredients []string)

func GetIngredientLines

func GetIngredientLines(fname string) (ingredientLines []string, err error)

GetIngredientLines returns the ingredient lines

func HasRecipe

func HasRecipe(recipe string) (yes bool)

func IsIngredient

func IsIngredient(s string) (yes bool)

func ListGzFiles

func ListGzFiles(folder string) (files []string, err error)

func ListJSONFiles

func ListJSONFiles(folder string) (files []string, err error)

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func ReadGzFile

func ReadGzFile(filename string) ([]byte, error)

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SetLogLevel

func SetLogLevel(level string) (err error)

SetLogLevel determines the log level

func Singularlize

func Singularlize(line string) string

Types

type Cluster

type Cluster struct {
	Recipes             []Recipe              `json:"recipes,omitempty"`
	ID                  int                   `json:"id,omitempty"`
	NumRecipes          int                   `json:"num_recipes,omitempty"`
	IngredientRelations map[string]Collection `json:"ingredient_relations_collection,omitempty"`
	Ingredient          map[string]Collection `json:"ingredient_collection,omitempty"`
}

type Collection

type Collection struct {
	Number  int       `json:"num,omitempty"`
	All     []float64 `json:"all,omitempty"`
	Average float64   `json:"average,omitempty"`
	SD      float64   `json"sd,omitempty"`
}

func ProcessCollection

func ProcessCollection(c Collection) Collection

type Ingredient

type Ingredient struct {
	OriginalLine string  `json:"line,omitempty"`
	Ingredient   string  `json:"ingredient,omitempty"`
	Measure      string  `json:"measure,omitempty"`
	Amount       float64 `json:"amount,omitempty"`
	// the following are specific to clusters
	Cups               float64 `json:"cups,omitempty"`
	SD                 float64 `json:"sd,omitempty"`
	FrequencyInCluster float64 `json:"freq_cluster,omitempty"`
}

Ingredient species the ingredients

func ParseIngredients

func ParseIngredients(fname string) (ingredients []Ingredient, err error)

ParseIngredients will return the ingredients found in the file

func (Ingredient) String

func (p Ingredient) String() string

type Rational

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

A rational number r is expressed as the fraction p/q of two integers: r = p/q = (d*i+n)/d.

func ParseDecimal

func ParseDecimal(s string) (r Rational, err error)

func (Rational) String

func (r Rational) String() string

type Recipe

type Recipe struct {
	URL             string             `json:"url,omitempty"`
	Filename        string             `json:"filename,omitempty"`
	Ingredients     []Ingredient       `json:"ingredients,omitempty"`
	Directions      []string           `json:"directions,omitempty"`
	VolumeRelations map[string]float64 `json:"volume_relations,omitempty"`
	Title           string             `json:"title,omitempty"`
	// the following are specific to clusters
	PercentOfAll             int      `json:"percent_of_all,omitempty"`
	NumberInCluster          int      `json:"number_in_cluster,omitempty"`
	TotalRecipes             int      `json:"total_recipes,omitempty"`
	URLs                     []string `json:"urls,omitempty"`
	HasRareIngredients       []string `json:"rare_ingredients,omitempty"`
	MissingCommonIngredients []string `json:"missing_ingredients,omitempty"`
}

Recipe is the parsed recipe from a file

func AnalyzeClusters

func AnalyzeClusters(folder string) (meanRecipes []Recipe, err error)

func GenerateRecipe

func GenerateRecipe(fname string) (r Recipe, err error)

GenerateRecipe will parse the recipe from a file

func Run

func Run(recipe string, clusters int, requiredIngredients []string, determineRequiredIngredientsFromTitle bool) (meanRecipes []Recipe, err error)

func (Recipe) HasIngredient

func (p Recipe) HasIngredient(ingredient string) bool

func (Recipe) IngredientText

func (p Recipe) IngredientText() string

func (Recipe) String

func (p Recipe) String() string

Jump to

Keyboard shortcuts

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