pokecorrect 0.1.0__tar.gz
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.
- pokecorrect-0.1.0/PKG-INFO +14 -0
- pokecorrect-0.1.0/README.md +1 -0
- pokecorrect-0.1.0/pyproject.toml +30 -0
- pokecorrect-0.1.0/setup.cfg +4 -0
- pokecorrect-0.1.0/src/pokecorrect/__init__.py +4 -0
- pokecorrect-0.1.0/src/pokecorrect/corrector.py +87 -0
- pokecorrect-0.1.0/src/pokecorrect.egg-info/PKG-INFO +14 -0
- pokecorrect-0.1.0/src/pokecorrect.egg-info/SOURCES.txt +9 -0
- pokecorrect-0.1.0/src/pokecorrect.egg-info/dependency_links.txt +1 -0
- pokecorrect-0.1.0/src/pokecorrect.egg-info/requires.txt +1 -0
- pokecorrect-0.1.0/src/pokecorrect.egg-info/top_level.txt +1 -0
|
@@ -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 @@
|
|
|
1
|
+
# pokecorrect
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pokecorrect"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Davizig", email = "davirediske@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
description = "Um corretor ortográfico e fonético inteligente especializado em nomes de Pokémon."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"requests>=2.25.0"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
"Homepage" = "https://github.com/Davizigjojo/pokecorrect"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
package-dir = {"" = "src"}
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
@@ -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,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/pokecorrect/__init__.py
|
|
4
|
+
src/pokecorrect/corrector.py
|
|
5
|
+
src/pokecorrect.egg-info/PKG-INFO
|
|
6
|
+
src/pokecorrect.egg-info/SOURCES.txt
|
|
7
|
+
src/pokecorrect.egg-info/dependency_links.txt
|
|
8
|
+
src/pokecorrect.egg-info/requires.txt
|
|
9
|
+
src/pokecorrect.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pokecorrect
|