titles

package
v0.0.0-...-57d0119 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2014 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Implements parsing and searching of the anime-titles.dat database.

http://wiki.anidb.info/w/API#Anime_Titles

Index

Constants

View Source
const (
	DataDumpURL = "http://anidb.net/api/anime-titles.dat.gz"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AID

type AID int

Anime ID

type Anime

type Anime struct {
	AID          AID
	PrimaryTitle string // The primary title ("x-jat main" title in the HTTP API)

	OfficialNames map[string][]Name
	Synonyms      map[string][]Name
	ShortNames    map[string][]Name
}

type Name

type Name struct {
	Language string // ISO-ish language string
	Title    string
}

type ResultComparer

type ResultComparer func(*Anime, *Anime) bool

Returns true if the first parameter should sort before the second parameter

func (ResultComparer) ReverseSort

func (cmp ResultComparer) ReverseSort(res Results)

func (ResultComparer) Sort

func (cmp ResultComparer) Sort(res Results)

Sorts the given Results.

type ResultFilter

type ResultFilter func(*Anime) bool

Returns true if the given *Anime should be included in the final ResultSet

type ResultSet

type ResultSet map[AID]Anime // Mapping of AIDs to Anime

func (ResultSet) Filter

func (rs ResultSet) Filter(filter ResultFilter) ResultSet

Filters a ResultSet according to the given ResultFilter; returns the filtered ResultSet

func (ResultSet) FilterByTitles

func (rs ResultSet) FilterByTitles(cmp TitleComparer) ResultSet

Filters a ResultSet according to the given TitleComparer; returns the filtered ResultSet

func (ResultSet) ResultsByAID

func (rs ResultSet) ResultsByAID() (res Results)

Returns the results sorted by AID

func (ResultSet) ResultsByFunc

func (rs ResultSet) ResultsByFunc(f ResultComparer) (res Results)

Returns the results sorted according to the given ResultComparer

func (ResultSet) ResultsByPrimaryTitle

func (rs ResultSet) ResultsByPrimaryTitle() (res Results)

Returns the results sorted by Primary Title

func (ResultSet) ReverseResultsByAID

func (rs ResultSet) ReverseResultsByAID() (res Results)

Returns the results in inverse AID sort

func (ResultSet) ReverseResultsByFunc

func (rs ResultSet) ReverseResultsByFunc(f ResultComparer) (res Results)

Returns the results sorted inversely according to the given ResultComparer

func (ResultSet) ReverseResultsByPrimaryTitle

func (rs ResultSet) ReverseResultsByPrimaryTitle() (res Results)

Returns the results in inverse Primary Title sort

type Results

type Results []Anime

func (Results) AIDList

func (res Results) AIDList() (aid []AID)

Returns a slice with the AIDs of all anime in the Results.

type SearchMatch

type SearchMatch struct {
	Matched string // The title that was matched
	AID     AID    // The AID the Matched title belongs to
}

An arbitrary search match

type SearchMatches

type SearchMatches []SearchMatch

func (SearchMatches) ToResultSet

func (matches SearchMatches) ToResultSet(db *TitlesDatabase) (rs ResultSet)

Converts the SearchMatches (which usually contains various duplicates) into a ResultSet. Needs the same TitlesDatabase as was used to generate the SearchMatches.

type TitleComparer

type TitleComparer func(string) bool

Returns true if the Anime with the given title should be included in the final ResultSet

type TitleMap

type TitleMap struct {
	Language string // ISO-ish language string

	OfficialMap map[string]AID
	SynonymMap  map[string]AID
	ShortMap    map[string]AID
}

Maps titles in the given language to AIDs

type TitlesDatabase

type TitlesDatabase struct {
	sync.RWMutex
	UpdateTime time.Time
	Languages  []string // List of all the languages present in the database

	LanguageMap map[string]*TitleMap // Per-language map (key is ISO-ish language string)
	PrimaryMap  map[string]AID       // Primary title to AID map (language is always "x-jat")

	AnimeMap map[AID]*Anime
}

func (*TitlesDatabase) ExactSearch

func (db *TitlesDatabase) ExactSearch(s string) (m SearchMatch)

Exact string search, returns first match (nondeterministic)

func (*TitlesDatabase) ExactSearchAll

func (db *TitlesDatabase) ExactSearchAll(s string) (matches SearchMatches)

Exact string search (nondeterministic order)

func (*TitlesDatabase) ExactSearchFold

func (db *TitlesDatabase) ExactSearchFold(s string) (m SearchMatch)

String search with case folding, returns first match (nondeterministic)

func (*TitlesDatabase) ExactSearchFoldAll

func (db *TitlesDatabase) ExactSearchFoldAll(s string) (matches SearchMatches)

String search with case folding (nondeterministic order)

func (*TitlesDatabase) ExactSearchFoldN

func (db *TitlesDatabase) ExactSearchFoldN(s string, n int) (matches SearchMatches)

String search with case folding, returns first N matches (nondeterministic)

func (*TitlesDatabase) ExactSearchN

func (db *TitlesDatabase) ExactSearchN(s string, n int) (matches SearchMatches)

Exact string search, returns first N matches (nondeterministic)

func (*TitlesDatabase) FuzzySearch

func (db *TitlesDatabase) FuzzySearch(s string) (rs ResultSet)

Fuzzy string search with algorithm similar to the official Chii[AR] IRC bot.

First attempts an exact search. Otherwise, uses strings.Fields to split the string into words and tries, in order, the following alternate matches:

* Initial words (prefix, but ending at word boundary)

* Final words (suffix, but starting at word boundary)

* Infix words

* Prefix

* Suffix

* Initial words in the given order, but with possible words between them

* Final words in the given order

* Infix words in the given order

* Initial strings in the given order, but with other possible strings between them

* Final strings in the given order

* Any match with strings in the given order

Failing all those cases, the search returns a nil ResultSet.

func (*TitlesDatabase) FuzzySearchFold

func (db *TitlesDatabase) FuzzySearchFold(s string) (rs ResultSet)

Version with case folding of FuzzySearch.

See the FuzzySearch documentation for details.

func (*TitlesDatabase) LoadDB

func (db *TitlesDatabase) LoadDB(r io.Reader)

Loads the database from the given io.Reader.

The Reader must point to a file or stream with the contents of anime-titles.dat, which can be obtained from the DataDumpURL. LoadDB will automatically try to un-gzip, so the file can be stored in gzip format.

Note: LoadDB will read the entire contents of the given io.Reader.

func (*TitlesDatabase) PrefixSearch

func (db *TitlesDatabase) PrefixSearch(s string) (m SearchMatch)

Prefix exact string search, returns first match (nondeterministic)

func (*TitlesDatabase) PrefixSearchAll

func (db *TitlesDatabase) PrefixSearchAll(s string) (matches SearchMatches)

Prefix exact string search (nondeterministic order)

func (*TitlesDatabase) PrefixSearchFold

func (db *TitlesDatabase) PrefixSearchFold(s string) (m SearchMatch)

Prefix string search with case folding, returns first match (nondeterministic)

func (*TitlesDatabase) PrefixSearchFoldAll

func (db *TitlesDatabase) PrefixSearchFoldAll(s string) (matches SearchMatches)

Prefix string search with case folding (nondeterministic order)

func (*TitlesDatabase) PrefixSearchFoldN

func (db *TitlesDatabase) PrefixSearchFoldN(s string, n int) (matches SearchMatches)

Prefix string search with case folding, returns first N matches (nondeterministic)

func (*TitlesDatabase) PrefixSearchN

func (db *TitlesDatabase) PrefixSearchN(s string, n int) (matches SearchMatches)

Prefix exact string search, returns first N matches (nondeterministic)

func (*TitlesDatabase) RegexpSearch

func (db *TitlesDatabase) RegexpSearch(re *regexp.Regexp) (m SearchMatch)

Regular expression search, returns first match (nondeterministic)

func (*TitlesDatabase) RegexpSearchAll

func (db *TitlesDatabase) RegexpSearchAll(re *regexp.Regexp) (matches SearchMatches)

Regular expression search (nondeterministic order)

func (*TitlesDatabase) RegexpSearchN

func (db *TitlesDatabase) RegexpSearchN(re *regexp.Regexp, n int) (matches SearchMatches)

Regular expression search, returns first N matches (nondeterministic)

func (*TitlesDatabase) SuffixSearch

func (db *TitlesDatabase) SuffixSearch(s string) (m SearchMatch)

Suffix exact string search, returns first match (nondeterministic)

func (*TitlesDatabase) SuffixSearchAll

func (db *TitlesDatabase) SuffixSearchAll(s string) (matches SearchMatches)

Suffix exact string search (nondeterministic order)

func (*TitlesDatabase) SuffixSearchFold

func (db *TitlesDatabase) SuffixSearchFold(s string) (m SearchMatch)

Suffix string search with case folding, returns first match (nondeterministic)

func (*TitlesDatabase) SuffixSearchFoldAll

func (db *TitlesDatabase) SuffixSearchFoldAll(s string) (matches SearchMatches)

Suffix string search with case folding (nondeterministic order)

func (*TitlesDatabase) SuffixSearchFoldN

func (db *TitlesDatabase) SuffixSearchFoldN(s string, n int) (matches SearchMatches)

Suffix string search with case folding, returns first N matches (nondeterministic)

func (*TitlesDatabase) SuffixSearchN

func (db *TitlesDatabase) SuffixSearchN(s string, n int) (matches SearchMatches)

Suffix exact string search, returns first N matches (nondeterministic)

Jump to

Keyboard shortcuts

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