def forward_segment(text, dic):
    """
    正向最长匹配的中文分词算法
    :param text:待分词的文本
    :param dic:词典
    :return:单词列表
    """
    word_list = []
    i = 0
    while i < len(text):
        longest_word = text[i]
        for j in range(i + 1, len(text) + 1):
            word = text[i:j]
            if (word in dic) and (len(word) > len(longest_word)):
                longest_word = word
        word_list.append(longest_word)  # 正向搜索，越先找到的单词排在越前面
        i += len(longest_word)
    return word_list