pos_count = {}
data = joblib.load(UTS_DICT_DATA)
count = 0
logger.info("End loading")

for key in data:
    # count += 1
    # if count > 30:
    #     break
    defs = []
    pos_tags = {}
    text = key
    for definition in data[key]:
        pos_tag = definition['pos']
        if pos_tag not in pos_tags:
            i = len(pos_tags)
            pos_tags[pos_tag] = i
            tag_data = {'tag': pos_tag, 'defs': []}
            defs.append(tag_data)
        index = pos_tags[pos_tag]
        defs[index]["defs"].append({
            "def": definition['definition'],
            'examples': [definition['example']]
        })
    word = Word(text, defs)
    dict.add(word)
logger.info("End Process")
dict.save(join(DICT_FOLDER, 'underthesea_dictionary.yaml'))
logger.info("End Save")
print('[+] Done')
示例#2
0
from data import Dictionary, Word

dict = Dictionary()
words = [
    Word('a', []),
    Word('b', [{
        'tag': 'Noun',
        'defs': [{
            'def': 'abcdf',
            'examples': ['1', '2']
        }]
    }])
]
for word in words:
    dict.add(word)
dict.save('test_dict.yaml')