Tận dụng lớp

Nguyên tắc Kỹ thuật Phần mềm với Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Mở rộng lớp Document

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

Tách từ tài liệu

Nguyên tắc Kỹ thuật Phần mềm với Python

Lớp Document hiện tại

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

Khởi tạo tách từ tài liệu

Nguyên tắc Kỹ thuật Phần mềm với Python

Sửa __init__

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

doc = Document('test doc') print(doc.tokens)
['test', 'doc']
Nguyên tắc Kỹ thuật Phần mềm với Python

Thêm phương thức _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)
Nguyên tắc Kỹ thuật Phần mềm với Python

Phương thức không công khai

Khởi tạo tách từ tài liệu

Biển báo tài sản riêng

Nguyên tắc Kỹ thuật Phần mềm với Python

Rủi ro của phương thức không công khai

  • Thiếu tài liệu

  • Khó lường

Biển báo tài sản riêng

Nguyên tắc Kỹ thuật Phần mềm với Python

¡Vamos a practicar!

Nguyên tắc Kỹ thuật Phần mềm với Python

Preparing Video For Download...