Klassen benutten

Software-engineeringprincipes in Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Documentklasse uitbreiden

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

Tokenize Document

Software-engineeringprincipes in Python

Huidige documentklasse

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

Tokenize Document init

Software-engineeringprincipes in Python

__init__ aanpassen

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

doc = Document('test doc') print(doc.tokens)
['test', 'doc']
Software-engineeringprincipes in Python

_tokenize() methode toevoegen

# Importeer functie voor tokenisatie
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)
Software-engineeringprincipes in Python

Niet-publieke methoden

Tokenize Document init

Private Property Sign

Software-engineeringprincipes in Python

Risico's van niet-publieke methoden

  • Gebrek aan documentatie

  • Onvoorspelbaarheid

Private Property Sign

Software-engineeringprincipes in Python

Laten we oefenen!

Software-engineeringprincipes in Python

Preparing Video For Download...