Documentation ¶
Overview ¶
Implements parsing and searching of the anime-titles.dat database.
Index ¶
- Constants
- type AID
- type Anime
- type Name
- type ResultComparer
- type ResultFilter
- type ResultSet
- func (rs ResultSet) Filter(filter ResultFilter) ResultSet
- func (rs ResultSet) FilterByTitles(cmp TitleComparer) ResultSet
- func (rs ResultSet) ResultsByAID() (res Results)
- func (rs ResultSet) ResultsByFunc(f ResultComparer) (res Results)
- func (rs ResultSet) ResultsByPrimaryTitle() (res Results)
- func (rs ResultSet) ReverseResultsByAID() (res Results)
- func (rs ResultSet) ReverseResultsByFunc(f ResultComparer) (res Results)
- func (rs ResultSet) ReverseResultsByPrimaryTitle() (res Results)
- type Results
- type SearchMatch
- type SearchMatches
- type TitleComparer
- type TitleMap
- type TitlesDatabase
- func (db *TitlesDatabase) ExactSearch(s string) (m SearchMatch)
- func (db *TitlesDatabase) ExactSearchAll(s string) (matches SearchMatches)
- func (db *TitlesDatabase) ExactSearchFold(s string) (m SearchMatch)
- func (db *TitlesDatabase) ExactSearchFoldAll(s string) (matches SearchMatches)
- func (db *TitlesDatabase) ExactSearchFoldN(s string, n int) (matches SearchMatches)
- func (db *TitlesDatabase) ExactSearchN(s string, n int) (matches SearchMatches)
- func (db *TitlesDatabase) FuzzySearch(s string) (rs ResultSet)
- func (db *TitlesDatabase) FuzzySearchFold(s string) (rs ResultSet)
- func (db *TitlesDatabase) LoadDB(r io.Reader)
- func (db *TitlesDatabase) PrefixSearch(s string) (m SearchMatch)
- func (db *TitlesDatabase) PrefixSearchAll(s string) (matches SearchMatches)
- func (db *TitlesDatabase) PrefixSearchFold(s string) (m SearchMatch)
- func (db *TitlesDatabase) PrefixSearchFoldAll(s string) (matches SearchMatches)
- func (db *TitlesDatabase) PrefixSearchFoldN(s string, n int) (matches SearchMatches)
- func (db *TitlesDatabase) PrefixSearchN(s string, n int) (matches SearchMatches)
- func (db *TitlesDatabase) RegexpSearch(re *regexp.Regexp) (m SearchMatch)
- func (db *TitlesDatabase) RegexpSearchAll(re *regexp.Regexp) (matches SearchMatches)
- func (db *TitlesDatabase) RegexpSearchN(re *regexp.Regexp, n int) (matches SearchMatches)
- func (db *TitlesDatabase) SuffixSearch(s string) (m SearchMatch)
- func (db *TitlesDatabase) SuffixSearchAll(s string) (matches SearchMatches)
- func (db *TitlesDatabase) SuffixSearchFold(s string) (m SearchMatch)
- func (db *TitlesDatabase) SuffixSearchFoldAll(s string) (matches SearchMatches)
- func (db *TitlesDatabase) SuffixSearchFoldN(s string, n int) (matches SearchMatches)
- func (db *TitlesDatabase) SuffixSearchN(s string, n int) (matches SearchMatches)
Constants ¶
const (
DataDumpURL = "http://anidb.net/api/anime-titles.dat.gz"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ResultComparer ¶
Returns true if the first parameter should sort before the second parameter
func (ResultComparer) ReverseSort ¶
func (cmp ResultComparer) ReverseSort(res Results)
type ResultFilter ¶
Returns true if the given *Anime should be included in the final ResultSet
type ResultSet ¶
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 ¶
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 ¶
Returns the results sorted by Primary Title
func (ResultSet) ReverseResultsByAID ¶
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 ¶
Returns the results in inverse Primary Title sort
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 ¶
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)