pokecorrect 0.1.0__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.
@@ -0,0 +1,4 @@
1
+ from .corrector import PokemonCorrector
2
+
3
+ __version__ = "0.1.0"
4
+ __all__ = ["PokemonCorrector"]
@@ -0,0 +1,87 @@
1
+ import re
2
+ import difflib
3
+ import requests
4
+
5
+ class PokemonCorrector:
6
+ def __init__(self, custom_names=None):
7
+ self.pokemon_names = []
8
+ if custom_names:
9
+ self.pokemon_names = [name.strip().title() for name in custom_names]
10
+ else:
11
+ self.carregar_nomes_oficiais()
12
+
13
+ def carregar_nomes_oficiais(self):
14
+ try:
15
+ response = requests.get("https://pokeapi.co/api/v2/pokemon?limit=1500", timeout=8)
16
+ if response.status_code == 200:
17
+ results = response.json().get("results", [])
18
+ self.pokemon_names = [p["name"].replace("-", " ").title() for p in results]
19
+ except Exception:
20
+ self.pokemon_names = ["Pikachu", "Charizard", "Blastoise", "Venusaur", "Eevee", "Kricketune", "Ninetales"]
21
+
22
+ def _simplificar_fonetica(self, nome):
23
+ if not nome:
24
+ return ""
25
+ txt = nome.lower().strip()
26
+ txt = re.sub(r'[^a-z]', '', txt)
27
+ txt = txt.replace("ck", "k")
28
+ txt = txt.replace("c", "k")
29
+ txt = txt.replace("ph", "f")
30
+ txt = txt.replace("y", "i")
31
+ txt = txt.replace("sh", "x")
32
+ txt = txt.replace("w", "u")
33
+ txt = txt.replace("d", "t")
34
+
35
+ txt_limpo = ""
36
+ ultimo_char = ""
37
+ for char in txt:
38
+ if char != ultimo_char:
39
+ txt_limpo += char
40
+ ultimo_char = char
41
+ return txt_limpo
42
+
43
+ def _levenshtein(self, s1, s2):
44
+ if len(s1) > len(s2):
45
+ s1, s2 = s2, s1
46
+ distances = range(len(s1) + 1)
47
+ for i2, c2 in enumerate(s2):
48
+ distances_ = [i2+1]
49
+ for i1, c1 in enumerate(s1):
50
+ if c1 == c2:
51
+ distances_.append(distances[i1])
52
+ else:
53
+ distances_.append(1 + min((distances[i1], distances[i1 + 1], distances_[-1])))
54
+ distances = distances_
55
+ return distances[-1]
56
+
57
+ def corrigir(self, nome_detectado):
58
+ if not nome_detectado or not self.pokemon_names:
59
+ return nome_detectado, False
60
+
61
+ nome_limpo = re.sub(r'\d+', '', nome_detectado).strip().title()
62
+
63
+ if nome_limpo in self.pokemon_names:
64
+ return nome_limpo, False
65
+
66
+ fonetica_detectada = self._simplificar_fonetica(nome_limpo)
67
+ for nome_oficial in self.pokemon_names:
68
+ if self._simplificar_fonetica(nome_oficial) == fonetica_detectada:
69
+ return nome_oficial, True
70
+
71
+ melhor_nome = None
72
+ menor_distancia = 99
73
+ nome_limpo_lower = nome_limpo.lower()
74
+ for nome_oficial in self.pokemon_names:
75
+ dist = self._levenshtein(nome_limpo_lower, nome_oficial.lower())
76
+ if dist < menor_distancia:
77
+ menor_distancia = dist
78
+ melhor_nome = nome_oficial
79
+
80
+ if melhor_nome and menor_distancia <= 3:
81
+ return melhor_nome, True
82
+
83
+ correspondencias = difflib.get_close_matches(nome_limpo, self.pokemon_names, n=1, cutoff=0.25)
84
+ if correspondencias:
85
+ return correspondencias[0], True
86
+
87
+ return nome_detectado, False
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: pokecorrect
3
+ Version: 0.1.0
4
+ Summary: Um corretor ortográfico e fonético inteligente especializado em nomes de Pokémon.
5
+ Author-email: Davizig <davirediske@gmail.com>
6
+ Project-URL: Homepage, https://github.com/Davizigjojo/pokecorrect
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.7
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: requests>=2.25.0
13
+
14
+ # pokecorrect
@@ -0,0 +1,6 @@
1
+ pokecorrect/__init__.py,sha256=wATALDCgS_zOXbdMBLHDmkkTL8Fa2yvZLS1zXaEtkvY,94
2
+ pokecorrect/corrector.py,sha256=QLs4XAsekApvLmzTkWx2fx9qr930ikFARRWwObKb26E,3128
3
+ pokecorrect-0.1.0.dist-info/METADATA,sha256=OcMJ93Mh3hW4Ji2rmJ_GFl-7X6Ez618Pv9MD9ZxwPBo,517
4
+ pokecorrect-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ pokecorrect-0.1.0.dist-info/top_level.txt,sha256=HURoPH2PCg-KwkMS43_yLq_Xi5nIycfFStyn7YFaJtk,12
6
+ pokecorrect-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ pokecorrect