localdex 0.2.37__py3-none-any.whl → 0.2.39__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
localdex/core.py CHANGED
@@ -18,6 +18,7 @@ from .exceptions import (
18
18
  ItemNotFoundError, DataLoadError, SearchError
19
19
  )
20
20
  from .data_loader import DataLoader
21
+ from .name_normalizer import PokemonNameNormalizer
21
22
 
22
23
 
23
24
  class LocalDex:
@@ -169,63 +170,10 @@ class LocalDex:
169
170
  # Load from data
170
171
  pokemon_data = self.data_loader.load_pokemon_by_name(name)
171
172
  if not pokemon_data:
172
-
173
- if ' ' in name:
174
- name = name.replace(' ', '-')
175
-
176
- if '-f' in name or '-m' in name:
177
- name = name.replace('-f', '-female').replace('-m', '-male')
178
-
179
- if 'florges' in name.lower():
180
- name = 'florges'
181
-
182
- if 'maushold' in name.lower():
183
- name = 'maushold'
184
-
185
- if 'pikachu' in name.lower():
186
- name = 'pikachu'
187
-
188
- if 'ogerpon' in name.lower():
189
- if 'cornerstone' in name.lower():
190
- name = 'ogerpon-cornerstone-mask'
191
- elif 'wellspring' in name.lower():
192
- name = 'ogerpon-wellspring-mask'
193
- elif 'hearthflame' in name.lower():
194
- name = 'ogerpon-hearthflame-mask'
195
- else:
196
- name = 'ogerpon'
173
+ # Try with normalized name
174
+ normalized_name = PokemonNameNormalizer.normalize_name(name)
175
+ pokemon_data = self.data_loader.load_pokemon_by_name(normalized_name)
197
176
 
198
- if 'squawkabilly' in name.lower():
199
- if 'blue' in name.lower():
200
- name = 'squawkabilly-blue-plumage'
201
- elif 'red' in name.lower():
202
- name = 'squawkabilly-red-plumage'
203
- elif 'white' in name.lower():
204
- name = 'squawkabilly-white-plumage'
205
- else:
206
- name = 'squawkabilly-white-plumage'
207
- if 'tauros' in name.lower() and 'paldea' in name.lower():
208
- if 'blaze' in name.lower():
209
- name = 'tauros-paldea-blaze-breed'
210
- elif 'aqua' in name.lower():
211
- name = 'tauros-paldea-aqua-breed'
212
- elif 'combat' in name.lower():
213
- name = 'tauros-paldea-combat-breed'
214
- else:
215
- name = 'tauros-paldea-blaze-breed'
216
- if 'arceus' in name.lower():
217
- name = 'arceus'
218
-
219
- if 'indeedee' in name.lower():
220
- if 'f' in name.lower():
221
- name = 'indeedee-female'
222
- elif 'm' in name.lower():
223
- name = 'indeedee-male'
224
- else:
225
- name = 'indeedee-female'
226
-
227
- pokemon_data = self.data_loader.load_pokemon_by_name(name)
228
-
229
177
  if not pokemon_data:
230
178
  raise PokemonNotFoundError(name)
231
179
 
@@ -0,0 +1,142 @@
1
+ """
2
+ Pokemon name normalization and fuzzing utilities.
3
+
4
+ This module handles the normalization of Pokemon names to match the expected
5
+ data format, including handling special cases, forms, and variations.
6
+ """
7
+
8
+ from typing import Optional
9
+
10
+
11
+ class PokemonNameNormalizer:
12
+ """
13
+ Handles normalization of Pokemon names for data lookup.
14
+
15
+ This class contains logic to handle various Pokemon name variations,
16
+ special forms, and edge cases to ensure proper data retrieval.
17
+ """
18
+
19
+ @staticmethod
20
+ def normalize_name(name: str) -> str:
21
+ """
22
+ Normalize a Pokemon name for data lookup.
23
+
24
+ Args:
25
+ name: The input Pokemon name
26
+
27
+ Returns:
28
+ Normalized name that should match the data format
29
+ """
30
+ # Handle spaces and hyphens
31
+ if ' ' in name:
32
+ name = name.replace(' ', '-')
33
+
34
+
35
+
36
+ # Handle special cases
37
+ name = PokemonNameNormalizer._handle_special_cases(name)
38
+
39
+ # Convert to lowercase at the end
40
+ return name.lower()
41
+
42
+ @staticmethod
43
+ def _handle_special_cases(name: str) -> str:
44
+ """
45
+ Handle special Pokemon name cases and forms.
46
+
47
+ Args:
48
+ name: The name to process
49
+
50
+ Returns:
51
+ Processed name
52
+ """
53
+ name_lower = name.lower()
54
+ if 'urshifu' in name_lower:
55
+ if 'single' in name_lower:
56
+ return 'urshifu-single-strike'
57
+ elif 'rapid' in name_lower:
58
+ return 'urshifu-rapid-strike'
59
+ else:
60
+ return 'urshifu-single-strike'
61
+
62
+ if 'zacian' in name_lower:
63
+ if 'crowned' in name_lower:
64
+ return 'zacian-crowned'
65
+ else:
66
+ return 'zacian'
67
+
68
+ if 'zamzenta' in name_lower:
69
+ if 'crowned' in name_lower:
70
+ return 'zamzenta-crowned'
71
+ else:
72
+ return 'zamzenta'
73
+
74
+ if 'necrozma' in name_lower:
75
+ if 'dawn' in name_lower:
76
+ return 'necrozma-dawn'
77
+ elif 'dusk' in name_lower:
78
+ return 'necrozma-dusk'
79
+ elif 'ultra' in name_lower:
80
+ return 'necrozma-ultra'
81
+ else:
82
+ return 'necrozma'
83
+
84
+ # Florges forms
85
+ if 'florges' in name_lower:
86
+ return 'florges'
87
+
88
+ # Maushold forms
89
+ if 'maushold' in name_lower:
90
+ return 'maushold'
91
+
92
+ # Pikachu forms
93
+ if 'pikachu' in name_lower:
94
+ return 'pikachu'
95
+
96
+ # Ogerpon forms
97
+ if 'ogerpon' in name_lower:
98
+ if 'cornerstone' in name_lower:
99
+ return 'ogerpon-cornerstone-mask'
100
+ elif 'wellspring' in name_lower:
101
+ return 'ogerpon-wellspring-mask'
102
+ elif 'hearthflame' in name_lower:
103
+ return 'ogerpon-hearthflame-mask'
104
+ else:
105
+ return 'ogerpon'
106
+
107
+ # Squawkabilly forms
108
+ if 'squawkabilly' in name_lower:
109
+ if 'blue' in name_lower:
110
+ return 'squawkabilly-blue-plumage'
111
+ elif 'red' in name_lower:
112
+ return 'squawkabilly-red-plumage'
113
+ elif 'white' in name_lower:
114
+ return 'squawkabilly-white-plumage'
115
+ else:
116
+ return 'squawkabilly-white-plumage'
117
+
118
+ # Tauros Paldea forms
119
+ if 'tauros' in name_lower and 'paldea' in name_lower:
120
+ if 'blaze' in name_lower:
121
+ return 'tauros-paldea-blaze-breed'
122
+ elif 'aqua' in name_lower:
123
+ return 'tauros-paldea-aqua-breed'
124
+ elif 'combat' in name_lower:
125
+ return 'tauros-paldea-combat-breed'
126
+ else:
127
+ return 'tauros-paldea-blaze-breed'
128
+
129
+ # Arceus forms
130
+ if 'arceus' in name_lower:
131
+ return 'arceus'
132
+
133
+ # Indeedee forms
134
+ if 'indeedee' in name_lower:
135
+ if 'f' in name_lower:
136
+ return 'indeedee-female'
137
+ elif 'm' in name_lower:
138
+ return 'indeedee-male'
139
+ else:
140
+ return 'indeedee-female'
141
+
142
+ return name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localdex
3
- Version: 0.2.37
3
+ Version: 0.2.39
4
4
  Summary: A local Pokemon data repository/Pokedex with fast offline access
5
5
  Author-email: LocalDex Team <localdex@example.com>
6
6
  License: MIT
@@ -1,9 +1,10 @@
1
1
  localdex/__init__.py,sha256=TTeh9Eys8nLtcw7Dg2equDqnouthIUyfsqvABtzR2vA,403
2
2
  localdex/cli.py,sha256=WqBCyA0akAFJNrYa8jCA3zoZgYEptDYDMGfAGkvKyZc,19317
3
- localdex/core.py,sha256=OTM3UmswgE9-jYRJWSD-mtKLGW5XuqZt-n1CJyvw4L0,22400
3
+ localdex/core.py,sha256=0kjuL388OniX7hRG6c5fT72nCC76LolpAB2UFrNXPns,20480
4
4
  localdex/data_loader.py,sha256=hi9aSTto5Ti-OBGOgrQ-XwD5hmivsUwS1uC4rulhwQI,11366
5
5
  localdex/download_data.py,sha256=T4A3OliGe2RsrRV1glyCqRcFhQIRt29KcY1K1-IqTuU,21597
6
6
  localdex/exceptions.py,sha256=Z02-8Kci6jFDk2nnGdVSHZJMDDWE9vuwuASs4VM3To8,2777
7
+ localdex/name_normalizer.py,sha256=36PK1txN3P8CGUUIr_tGkKD1yLLMbCmfGmryCdwYblI,4285
7
8
  localdex/data/abilities/adaptability.json,sha256=FGEEZmL80YVcIXHV-h287Wu-UJycM1QEJxiOHK2I4mY,289
8
9
  localdex/data/abilities/aerilate.json,sha256=KRZOVH2KGdEQ_3UktFoXoagUOaC8jIPZ6Ti-YGzW44s,301
9
10
  localdex/data/abilities/aftermath.json,sha256=Awv_8jquu3pM4CemD5ylS1v83ABrqGtrgMEkL-1ldBk,285
@@ -4825,8 +4826,8 @@ localdex/models/ability.py,sha256=AQzv3XUHHl4sustMJjPDDjJOjXu2GMLTfcM3-tqQ_1w,30
4825
4826
  localdex/models/item.py,sha256=zXao8F-jBPUGq_YLeGeYeK_dZVI7aZMXtWOPwR3qusY,4677
4826
4827
  localdex/models/move.py,sha256=hfgcWI4ziz5MMvc9ddmkotxzYYdrSUqZZQ72IU5tucs,7629
4827
4828
  localdex/models/pokemon.py,sha256=glnOiEhkFc25U54hJHwUkT-okUgtL2prg3269YXI3w0,5422
4828
- localdex-0.2.37.dist-info/METADATA,sha256=_XTETQDl9yYeVkxFrHxykvnIu-sTdXyeWMwEDDq83z8,8016
4829
- localdex-0.2.37.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4830
- localdex-0.2.37.dist-info/entry_points.txt,sha256=n5GxSeQo-MRuvrT2wVk7hOzEFFsWf6tkBjkzmGIYJe4,47
4831
- localdex-0.2.37.dist-info/top_level.txt,sha256=vtupDMH-IaxVCoEZrmE0QzdTwhaKzngVJbTA1NkR_MY,9
4832
- localdex-0.2.37.dist-info/RECORD,,
4829
+ localdex-0.2.39.dist-info/METADATA,sha256=uQCeAUZtWDcb_vVwiH4zeer0h9_TrXpVVzIo9RCR7rE,8016
4830
+ localdex-0.2.39.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4831
+ localdex-0.2.39.dist-info/entry_points.txt,sha256=n5GxSeQo-MRuvrT2wVk7hOzEFFsWf6tkBjkzmGIYJe4,47
4832
+ localdex-0.2.39.dist-info/top_level.txt,sha256=vtupDMH-IaxVCoEZrmE0QzdTwhaKzngVJbTA1NkR_MY,9
4833
+ localdex-0.2.39.dist-info/RECORD,,