クラスの活用

Python におけるソフトウェアエンジニアリングの原則

Adam Spannbauer

Machine Learning Engineer at Eastman

ドキュメントクラスの拡張

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

ドキュメントをトークン化

Python におけるソフトウェアエンジニアリングの原則

現在のドキュメントクラス

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

ドキュメントのトークン化の初期化

Python におけるソフトウェアエンジニアリングの原則

__init__ の修正

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

doc = Document('test doc') print(doc.tokens)
['test', 'doc']
Python におけるソフトウェアエンジニアリングの原則

_tokenize() メソッドの追加

# Import function to perform tokenization
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 におけるソフトウェアエンジニアリングの原則

非公開メソッド

ドキュメントのトークン化の初期化

私有地の標識

Python におけるソフトウェアエンジニアリングの原則

非公開メソッドのリスク

  • ドキュメント不足

  • 予測が不可能

私有地の標識

Python におけるソフトウェアエンジニアリングの原則

練習しましょう!

Python におけるソフトウェアエンジニアリングの原則

Preparing Video For Download...