Aprovechando Clases

Principios de ingeniería de software en Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Extender clase Document

class Document:
    def __init__(self, text):
        self.text = text

Tokenizar Documento

Principios de ingeniería de software en Python

Clase Document actual

class Document:
    def __init__(self, text):
        self.text = text

Inicializar Tokenización del Documento

Principios de ingeniería de software en Python

Revisar __init__

class Document:
    def __init__(self, text):
        self.text = text
        self.tokens = self._tokenize()

doc = Document('test doc') print(doc.tokens)
['test', 'doc']
Principios de ingeniería de software en Python

Añadir método _tokenize()

# Importar función para realizar tokenización
from .token_utils import tokenize

class Document: def __init__(self, text, token_regex=r'[a-zA-Z]+'): self.text = text self.tokens = self._tokenize()
def _tokenize(self): return tokenize(self.text)
Principios de ingeniería de software en Python

Métodos no públicos

Inicializar Tokenización del Documento

Señal de Propiedad Privada

Principios de ingeniería de software en Python

Riesgos de métodos no públicos

  • Falta de documentación

  • Imprevisibilidad

Señal de Propiedad Privada

Principios de ingeniería de software en Python

¡Vamos a practicar!

Principios de ingeniería de software en Python

Preparing Video For Download...