การใช้งาน Class

หลักการวิศวกรรมซอฟต์แวร์ใน Python

Adam Spannbauer

Machine Learning Engineer at Eastman

การขยาย Document class

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

Tokenize Document

หลักการวิศวกรรมซอฟต์แวร์ใน Python

Document class ปัจจุบัน

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

Tokenize Document init

หลักการวิศวกรรมซอฟต์แวร์ใน 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

เมธอดแบบ Non-public

Tokenize Document init

Private Property Sign

หลักการวิศวกรรมซอฟต์แวร์ใน Python

ความเสี่ยงของเมธอดแบบ Non-public

  • ขาดเอกสารประกอบ

  • ความไม่แน่นอน

Private Property Sign

หลักการวิศวกรรมซอฟต์แวร์ใน Python

มาฝึกกันเถอะ!

หลักการวิศวกรรมซอฟต์แวร์ใน Python

Preparing Video For Download...