利用类

Python 中的软件工程原理

Adam Spannbauer

Machine Learning Engineer at Eastman

扩展 Document 类

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

分词文档

Python 中的软件工程原理

当前的 Document 类

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 中的软件工程原理

¡Vamos a practicar!

Python 中的软件工程原理

Preparing Video For Download...