# 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/collection/dict.py
# class CoreDict:
#     def __init__(self):
#         self.trie = DoubleArrayTrie.load(config.CORE_DICT_NAME)
# 
# Path: yaya/const.py
# DOUBLE_MAX = 1.7976931348623157e+308
# TAG_PLACE = u"未##地"
# TAG_BIGIN = u"始##始"
# TAG_OTHER = u"未##它"
# TAG_GROUP = u"未##团"
# TAG_NUMBER = u"未##数"
# TAG_QUANTIFIER = u"未##量"
# TAG_PROPER = u"未##专"
# TAG_TIME = u"未##时"
# TAG_CLUSTER = u"未##串"
# TAG_END = u"末##末"
# TAG_PEOPLE = u"未##人"
# MAX_FREQUENCY = 25146057
# SMOOTHING_FACTOR = 1.0 / MAX_FREQUENCY + 0.00001
# SMOOTHING_PARAM = 0.1
# 
# Path: yaya/utility/singleton.py
# def singleton(class_):
#     instances = {}
# 
#     def get_instance(*args, **kwargs):
#         if class_ not in instances:
#             instances[class_] = class_(*args, **kwargs)
#         return instances[class_]
# 
#     return get_instance


import time
        import os
            import cPickle as Pickle
        import cPickle as Pickle
        import codecs
from yaya import config
from yaya.collection.dict import CoreDict
from yaya.const import logger
from yaya.utility.singleton import singleton
            return table
        logger.info(u"加载核心二元语法词表完毕，耗时%s", time.time() - start)

    @staticmethod
    def load_bin(filename):
        with open(filename, 'r') as f:
            bigram = Pickle.load(f)
            f.close()
            return bigram

    @staticmethod
    def build(filename):
        f = codecs.open(filename, 'r', 'utf-8')
        pre_word_map = {}
        max_word_id = CoreDict().trie.word_size()
        total = 0
        while True:
            line = f.readline()
            if not line:
                break
            params = line.split()
            if params.__len__() != 2:
                continue
            two_word = params[0].split('@', 2)
            if two_word.__len__() != 2:
                continue

            pre_word_id = CoreDict().trie.exact_match_search(two_word[0])
            if pre_word_id == -1:
                continue

# 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/collection/dict.py
# class CoreDict:
#     def __init__(self):
#         self.trie = DoubleArrayTrie.load(config.CORE_DICT_NAME)
# 
# Path: yaya/const.py
# DOUBLE_MAX = 1.7976931348623157e+308
# TAG_PLACE = u"未##地"
# TAG_BIGIN = u"始##始"
# TAG_OTHER = u"未##它"
# TAG_GROUP = u"未##团"
# TAG_NUMBER = u"未##数"
# TAG_QUANTIFIER = u"未##量"
# TAG_PROPER = u"未##专"
# TAG_TIME = u"未##时"
# TAG_CLUSTER = u"未##串"
# TAG_END = u"末##末"
# TAG_PEOPLE = u"未##人"
# MAX_FREQUENCY = 25146057
# SMOOTHING_FACTOR = 1.0 / MAX_FREQUENCY + 0.00001
# SMOOTHING_PARAM = 0.1
# 
# Path: yaya/utility/singleton.py
# def singleton(class_):
#     instances = {}
# 
#     def get_instance(*args, **kwargs):
#         if class_ not in instances:
#             instances[class_] = class_(*args, **kwargs)
#         return instances[class_]
# 
#     return get_instance


# Path: yaya/collection/bigram.py
import time
        import os
            import cPickle as Pickle
        import cPickle as Pickle
        import codecs
from yaya import config
from yaya.collection.dict import CoreDict
from yaya.const import logger
from yaya.utility.singleton import singleton

            return table
        logger.info(u"加载核心二元语法词表完毕，耗时%s", time.time() - start)

    @staticmethod
    def load_bin(filename):
        with open(filename, 'r') as f:
            bigram = Pickle.load(f)
            f.close()
            return bigram

    @staticmethod
    def build(filename):
        f = codecs.open(filename, 'r', 'utf-8')
        pre_word_map = {}
        max_word_id = CoreDict().trie.word_size()
        total = 0
        while True:
            line = f.readline()
            if not line:
                break
            params = line.split()
            if params.__len__() != 2:
                continue
            two_word = params[0].split('@', 2)
            if two_word.__len__() != 2:
                continue

            pre_word_id = CoreDict().trie.exact_match_search(two_word[0])
            if pre_word_id == -1:
                continue

            next_word_id = CoreDict().trie.exact_match_search(two_word[1])