Sfruttare le classi

Principi di Ingegneria del Software in Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Estendere la classe Document

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

Tokenizza Documento

Principi di Ingegneria del Software in Python

Classe documenti attuale

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

Tokenizza Documento init

Principi di Ingegneria del Software in Python

Revisione di __init__

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

doc = Document('test doc') print(doc.tokens)
['test', 'doc']
Principi di Ingegneria del Software in Python

Aggiunta del metodo _tokenize()

# Importa funzione per tokenizzazione
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)
Principi di Ingegneria del Software in Python

Metodi non pubblici

Tokenizza Documento init

Cartello Proprietà Privata

Principi di Ingegneria del Software in Python

I rischi dei metodi non pubblici

  • Mancanza di documentazione

  • Imprevedibilità

Cartello Proprietà Privata

Principi di Ingegneria del Software in Python

Ayo berlatih!

Principi di Ingegneria del Software in Python

Preparing Video For Download...