def cut(self, text):
        """分词

        :param text: 待分词的文本
        :yield: 单个词语
        """
        remain = text
        while remain:
            matched = ''
            # 一次加一个字的匹配
            for index in range(len(remain)):
                word = remain[:index + 1]
                if word in self._prefix_set:
                    matched = word
                else:
                    # 前面的字符串是个词语
                    if matched:
                        yield matched
                        matched = ''
                        remain = remain[index:]
                    else:  # 前面为空
                        yield word
                        remain = remain[index + 1:]
                    # 有结果了，剩余的重新开始匹配
                    break
            else:  # 整个文本就是一个词语
                yield remain
                break
def cut ( self , text ) : remain = text while remain : matched = '' for index in range ( len ( remain ) ) : word = remain [ : index + 1 ] if word in self . _prefix_set : matched = word else : if matched : yield matched matched = '' remain = remain [ index : ] else : yield word remain = remain [ index + 1 : ] break else : yield remain break
分词

        :param text: 待分词的文本
        :yield: 单个词语