Created
June 28, 2020 22:04
-
-
Save pablodz/f7a687f10d5ea46187ee2d12b23a41b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 0, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| ], | |
| "source": [ | |
| "def corregir_palabras(corrector, palabras, agregarPrimero=[]): \n", | |
| " #codificacion = corrector.get_dic_encoding() # obtenemos la codificacion para usarla luego\n", | |
| "\n", | |
| " # agregamos las palabras aleatorias al diccionario\n", | |
| " for palabra in agregarPrimero:\n", | |
| " corrector.add(palabra)\n", | |
| "\n", | |
| " # autocorreccion de palabras\n", | |
| " corregida = []\n", | |
| " for p in palabras:\n", | |
| " ok = corrector.spell(p) # verificamos ortografia\n", | |
| " if not ok:\n", | |
| " sugerencias = corrector.suggest(p)\n", | |
| " if len(sugerencias) > 0: # hay sugerencias\n", | |
| " # tomamos la mejor sugerencia(decodificada a string)\n", | |
| " mejor_sugerencia = sugerencias[0] \n", | |
| " corregida.append(mejor_sugerencia)\n", | |
| " else:\n", | |
| " corregida.append(p) # no hay ninguna sugerecia para la palabra\n", | |
| " else:\n", | |
| " corregida.append(p) # esta palabra esta corregida\n", | |
| "\n", | |
| " return corregida\n", | |
| "\n", | |
| "\n", | |
| "def corregir_oracion(corrector,string):\n", | |
| " oracion_fixed=''\n", | |
| " if len(string)>0:\n", | |
| " oracion_dirty=string.split()\n", | |
| " oracion_fixed=corregir_palabras(corrector, oracion_dirty,[''])\n", | |
| " oracion_fixed=' '.join(oracion_fixed)\n", | |
| " else:\n", | |
| " print('error')\n", | |
| " return oracion_fixed" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (system-wide)", | |
| "language": "python", | |
| "metadata": { | |
| "cocalc": { | |
| "description": "Python 3 programming language", | |
| "priority": 100, | |
| "url": "https://www.python.org/" | |
| } | |
| }, | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.6.9" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 4 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment