# Path: yaya/const.py
# DOUBLE_MAX = 1.7976931348623157e+308
# 
# Path: yaya/config.py
# DICT_BIN_EXT = '.ya'
# DICT_BIN_REVERSE_EXT = '.reverse.ya'
# DATA_ROOT = "/home/tony/MyProject/YaYaNLP/data"
# CUSTOM_DICT_NAME = [os.path.join(DATA_ROOT, "dictionary", "custom", f) for f in [
#     u"CustomDictionary.txt",
#     u"上海地名.txt",
#     u"人名词典.txt",
#     u"全国地名大全.txt",
#     u"机构名词典.txt",
#     u"现代汉语补充词库.txt"]]
# CORE_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "CoreNatureDictionary.txt")
# CORE_BIGRAM_NAME = os.path.join(DATA_ROOT, "dictionary", "CoreNatureDictionary.ngram.txt")
# CORE_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "person", "CoreNatureDictionary.tr.txt")
# CHAR_TYPE_PATH = os.path.join(DATA_ROOT, "dictionary", "other", "CharType.dat.yes")
# PERSON_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "person", "nr.tr.txt")
# PERSON_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "person", "nr.txt")
# ORG_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "organization", "nt.tr.txt")
# ORG_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "organization", "nt.txt")
# PLACE_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "place", "ns.tr.txt")
# PLACE_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "place", "ns.txt")
# TRADITIONAL_CHINESE_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "tc", "TraditionalChinese.txt")
# class _Config:


import math
from yaya.const import DOUBLE_MAX
from yaya.config import Config

    # 计算第2个元素
    current_line = node_list[1]
    for i, vertex, freq in current_line.natures:
        _now = hmm.trans_prob[_pre_nature.index][vertex.index] - math.log(
            (current_line.get_nature_frequency(vertex) + 1e-8) / hmm.get_total_freq(vertex))
        route_cost.append(_now)
    pre_line = current_line

    # 计算第三个元素
    for i, current_line in enumerate(node_list[2:]):
        new_route_cost = []
        perfect_pre_nature = None
        perfect_cost = init_cost
        for k, cur_nature, cur_freq in current_line.natures:
            new_route_cost.append(init_cost)
            for j, pre_nature, pre_freq in pre_line.natures:
                assert j < len(route_cost)

                _now = route_cost[j] + hmm.trans_prob[pre_nature.index][cur_nature.index] - math.log(
                    (current_line.get_nature_frequency(cur_nature) + 1e-8) / hmm.get_total_freq(cur_nature))

                if new_route_cost[k] > _now:
                    new_route_cost[k] = _now
                    if perfect_cost > _now:
                        perfect_cost = _now
                        perfect_pre_nature = pre_nature

        pre_line = current_line
        route_cost = new_route_cost

# Path: yaya/const.py
# DOUBLE_MAX = 1.7976931348623157e+308
# 
# Path: yaya/config.py
# DICT_BIN_EXT = '.ya'
# DICT_BIN_REVERSE_EXT = '.reverse.ya'
# DATA_ROOT = "/home/tony/MyProject/YaYaNLP/data"
# CUSTOM_DICT_NAME = [os.path.join(DATA_ROOT, "dictionary", "custom", f) for f in [
#     u"CustomDictionary.txt",
#     u"上海地名.txt",
#     u"人名词典.txt",
#     u"全国地名大全.txt",
#     u"机构名词典.txt",
#     u"现代汉语补充词库.txt"]]
# CORE_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "CoreNatureDictionary.txt")
# CORE_BIGRAM_NAME = os.path.join(DATA_ROOT, "dictionary", "CoreNatureDictionary.ngram.txt")
# CORE_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "person", "CoreNatureDictionary.tr.txt")
# CHAR_TYPE_PATH = os.path.join(DATA_ROOT, "dictionary", "other", "CharType.dat.yes")
# PERSON_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "person", "nr.tr.txt")
# PERSON_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "person", "nr.txt")
# ORG_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "organization", "nt.tr.txt")
# ORG_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "organization", "nt.txt")
# PLACE_TR_PATH = os.path.join(DATA_ROOT, "dictionary", "place", "ns.tr.txt")
# PLACE_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "place", "ns.txt")
# TRADITIONAL_CHINESE_DICT_NAME = os.path.join(DATA_ROOT, "dictionary", "tc", "TraditionalChinese.txt")
# class _Config:


# Path: yaya/seg/viterbi.py
import math
from yaya.const import DOUBLE_MAX
from yaya.config import Config


    # 计算第2个元素
    current_line = node_list[1]
    for i, vertex, freq in current_line.natures:
        _now = hmm.trans_prob[_pre_nature.index][vertex.index] - math.log(
            (current_line.get_nature_frequency(vertex) + 1e-8) / hmm.get_total_freq(vertex))
        route_cost.append(_now)
    pre_line = current_line

    # 计算第三个元素
    for i, current_line in enumerate(node_list[2:]):
        new_route_cost = []
        perfect_pre_nature = None
        perfect_cost = init_cost
        for k, cur_nature, cur_freq in current_line.natures:
            new_route_cost.append(init_cost)
            for j, pre_nature, pre_freq in pre_line.natures:
                assert j < len(route_cost)

                _now = route_cost[j] + hmm.trans_prob[pre_nature.index][cur_nature.index] - math.log(
                    (current_line.get_nature_frequency(cur_nature) + 1e-8) / hmm.get_total_freq(cur_nature))

                if new_route_cost[k] > _now:
                    new_route_cost[k] = _now
                    if perfect_cost > _now:
                        perfect_cost = _now
                        perfect_pre_nature = pre_nature

        pre_line = current_line
        route_cost = new_route_cost

        if Config.debug: