クラスを活用する

Pythonで学ぶSoftware Engineeringの原則

Adam Spannbauer

Machine Learning Engineer at Eastman

Document クラスを拡張する

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

トークン化された Document

Pythonで学ぶSoftware Engineeringの原則

現在の Document クラス

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

Tokenize Document の初期化

Pythonで学ぶSoftware Engineeringの原則

__init__ の見直し

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

doc = Document('test doc') print(doc.tokens)
['test', 'doc']
Pythonで学ぶSoftware Engineeringの原則

_tokenize() メソッドの追加

# トークン化用の関数をインポート
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)
Pythonで学ぶSoftware Engineeringの原則

非公開メソッド

Tokenize Document の初期化

立入禁止(Private Property)サイン

Pythonで学ぶSoftware Engineeringの原則

非公開メソッドのリスク

  • ドキュメント不足

  • 予測不能

立入禁止(Private Property)サイン

Pythonで学ぶSoftware Engineeringの原則

¡Vamos a practicar!

Pythonで学ぶSoftware Engineeringの原則

Preparing Video For Download...