Pokemon species split: Lookup & Markdown

This commit is contained in:
Petr Viktorin 2011-04-30 02:10:57 +03:00
parent 8309b316f2
commit d0c01810be
2 changed files with 18 additions and 22 deletions

View file

@ -154,7 +154,7 @@ class PokedexLinkPattern(markdown.inlinepatterns.Pattern):
item=tables.Item, item=tables.Item,
location=tables.Location, location=tables.Location,
move=tables.Move, move=tables.Move,
pokemon=tables.Pokemon, pokemon=tables.PokemonSpecies,
type=tables.Type, type=tables.Type,
)[category] )[category]
except KeyError: except KeyError:

View file

@ -103,7 +103,7 @@ class PokedexLookup(object):
tables.Location, tables.Location,
tables.Move, tables.Move,
tables.Nature, tables.Nature,
tables.Pokemon, tables.PokemonSpecies,
tables.PokemonForm, tables.PokemonForm,
tables.Type, tables.Type,
) )
@ -193,7 +193,7 @@ class PokedexLookup(object):
# Index every name in all our tables of interest # Index every name in all our tables of interest
speller_entries = set() speller_entries = set()
for cls in self.indexed_tables.values(): for cls in self.indexed_tables.values():
q = self.session.query(cls) q = self.session.query(cls).order_by(cls.id)
for row in q.yield_per(5): for row in q.yield_per(5):
row_key = dict(table=unicode(cls.__tablename__), row_key = dict(table=unicode(cls.__tablename__),
@ -211,21 +211,17 @@ class PokedexLookup(object):
speller_entries.add(normalized_name) speller_entries.add(normalized_name)
# Add the basic English name to the index if cls == tables.PokemonForm:
if cls == tables.Pokemon: name_map = 'pokemon_name_map'
# Don't re-add alternate forms of the same Pokémon; they'll else:
# be added as Pokémon forms instead name_map = 'name_map'
if not row.is_base_form:
continue
elif cls == tables.PokemonForm:
if row.name:
add(row.pokemon_name, None, u'en', u'us')
continue
# Some things also have other languages' names seen = set([None])
# XXX other language form names..? for language, name in sorted(getattr(row, name_map, {}).items(),
seen = set() # Sort English first for now
for language, name in getattr(row, 'name_map', {}).items(): key=lambda (l, n): (l.identifier != 'en', not l.official)):
if not name:
continue
if name in seen: if name in seen:
# Don't add the name again as a different # Don't add the name again as a different
# language; no point and it makes spell results # language; no point and it makes spell results
@ -301,6 +297,11 @@ class PokedexLookup(object):
prefix = prefix.strip() prefix = prefix.strip()
if prefix: if prefix:
user_valid_types.append(prefix) user_valid_types.append(prefix)
if prefix == 'pokemon':
# When the user says 'pokemon', they really meant both
# species & form.
user_valid_types.append('pokemon_species')
user_valid_types.append('pokemon_form')
# Merge the valid types together. Only types that appear in BOTH lists # Merge the valid types together. Only types that appear in BOTH lists
# may be used. # may be used.
@ -413,9 +414,6 @@ class PokedexLookup(object):
This function currently ONLY does fuzzy matching if there are no exact This function currently ONLY does fuzzy matching if there are no exact
matches. matches.
Formes are not returned unless requested; "Shaymin" will return only
grass Shaymin.
Extraneous whitespace is removed with extreme prejudice. Extraneous whitespace is removed with extreme prejudice.
Recognizes: Recognizes:
@ -430,7 +428,6 @@ class PokedexLookup(object):
- Language restrictions. "@fr:charge" will only return Tackle, which - Language restrictions. "@fr:charge" will only return Tackle, which
is called "Charge" in French. These can be combined with type is called "Charge" in French. These can be combined with type
restrictions, e.g., "@fr,move:charge". restrictions, e.g., "@fr,move:charge".
- Alternate formes can be specified merely like "wash rotom".
`input` `input`
Name of the thing to look for. Name of the thing to look for.
@ -448,7 +445,6 @@ class PokedexLookup(object):
name = self.normalize_name(input) name = self.normalize_name(input)
exact = True exact = True
form = None
# Pop off any type prefix and merge with valid_types # Pop off any type prefix and merge with valid_types
name, merged_valid_types, type_term = \ name, merged_valid_types, type_term = \