# 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
    taglist.append(_pre_nature)
    for i in xrange(1, _length):
        perfect_cost = DOUBLE_MAX
        item = roletaglist[i]
        for i, nature, freq in item.natures:
            _now = hmm.trans_prob[_pre_nature.index][nature.index] - math.log((item.get_nature_frequency(nature)+1e-8) / hmm.get_total_freq(nature))
            if perfect_cost > _now:
                perfect_cost = _now
                _perfect_nature = nature
        _pre_nature = _perfect_nature
        taglist.append(_pre_nature)
    return taglist

def viterbi_template(node_list, hmm, init_cost=DOUBLE_MAX):
    node_count = len(node_list)
    taglist = []
    # 得到第一个元素的第一个标签的词性
    _pre_nature = node_list[0].nature
    _perfect_nature = _pre_nature
    taglist.append(_pre_nature)
    for i, cur_node in enumerate(node_list[1:]):
        perfect_cost = init_cost
        for j, vertex, freq in cur_node.natures:
            _now = hmm.trans_prob[_pre_nature.index][vertex.index] - math.log(
                (cur_node.get_nature_frequency(vertex) + 1e-8) / hmm.get_total_freq(vertex))
            if perfect_cost > _now:
                perfect_cost = _now
                _perfect_nature = vertex
        _pre_nature = _perfect_nature
        taglist.append(_pre_nature)

# 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

    taglist.append(_pre_nature)
    for i in xrange(1, _length):
        perfect_cost = DOUBLE_MAX
        item = roletaglist[i]
        for i, nature, freq in item.natures:
            _now = hmm.trans_prob[_pre_nature.index][nature.index] - math.log((item.get_nature_frequency(nature)+1e-8) / hmm.get_total_freq(nature))
            if perfect_cost > _now:
                perfect_cost = _now
                _perfect_nature = nature
        _pre_nature = _perfect_nature
        taglist.append(_pre_nature)
    return taglist

def viterbi_template(node_list, hmm, init_cost=DOUBLE_MAX):
    node_count = len(node_list)
    taglist = []
    # 得到第一个元素的第一个标签的词性
    _pre_nature = node_list[0].nature
    _perfect_nature = _pre_nature
    taglist.append(_pre_nature)
    for i, cur_node in enumerate(node_list[1:]):
        perfect_cost = init_cost
        for j, vertex, freq in cur_node.natures:
            _now = hmm.trans_prob[_pre_nature.index][vertex.index] - math.log(
                (cur_node.get_nature_frequency(vertex) + 1e-8) / hmm.get_total_freq(vertex))
            if perfect_cost > _now:
                perfect_cost = _now
                _perfect_nature = vertex
        _pre_nature = _perfect_nature
        taglist.append(_pre_nature)

    return taglist