# 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
# -*- encoding:utf-8 -*-
from __future__ import unicode_literals


__author__ = 'tony'


class Viterbi:
    @staticmethod
    def computer(obs, states, start_p, trans_p, emit_p):
        max_states_value = 0
        for s in states:
            max_states_value = max(max_states_value, s)
        max_states_value += 1

        V = [[0 for col in range(obs.__len__())] for row in range(max_states_value)]
        path = [[0 for col in range(max_states_value)] for row in range(obs.__len__())]

        for y in states:
            V[0][y] = start_p[y] + emit_p[obs[0]]
            path[y][0] = y

        for t in range(obs.__len__()):
            new_path = [[0 for col in range(max_states_value) for row in range(obs.__len__())]]
            for y in states:

# 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

# -*- encoding:utf-8 -*-
from __future__ import unicode_literals


__author__ = 'tony'


class Viterbi:
    @staticmethod
    def computer(obs, states, start_p, trans_p, emit_p):
        max_states_value = 0
        for s in states:
            max_states_value = max(max_states_value, s)
        max_states_value += 1

        V = [[0 for col in range(obs.__len__())] for row in range(max_states_value)]
        path = [[0 for col in range(max_states_value)] for row in range(obs.__len__())]

        for y in states:
            V[0][y] = start_p[y] + emit_p[obs[0]]
            path[y][0] = y

        for t in range(obs.__len__()):
            new_path = [[0 for col in range(max_states_value) for row in range(obs.__len__())]]
            for y in states:

                prob = DOUBLE_MAX