Skip to content

Commit

Permalink
load_restore_dic 메소드/함수의 이름 충돌 해소 #58
Browse files Browse the repository at this point in the history
  • Loading branch information
krikit committed Apr 24, 2019
1 parent 56e955a commit b36d1a4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions rsc/bin/compile_errpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import Dict, List, Tuple

from khaiii.resource.char_align import Aligner, align_patch
from khaiii.resource.resource import load_restore_dic, load_vocab_out
from khaiii.resource.resource import load_vocab_out, parse_restore_dic
from khaiii.resource.morphs import Morph, ParseError, mix_char_tag
from khaiii.resource.trie import Trie

Expand Down Expand Up @@ -221,7 +221,7 @@ def run(args: Namespace):
args: program arguments
"""
aligner = Aligner(args.rsc_src)
restore_dic = load_restore_dic('{}/restore.dic'.format(args.rsc_src))
restore_dic = parse_restore_dic('{}/restore.dic'.format(args.rsc_src))
if not restore_dic:
sys.exit(1)
vocab_out = load_vocab_out(args.rsc_src)
Expand Down
4 changes: 2 additions & 2 deletions rsc/bin/compile_preanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from khaiii.munjong import sejong_corpus
from khaiii.resource.char_align import Aligner, AlignError, align_to_tag
from khaiii.resource.morphs import Morph, ParseError
from khaiii.resource.resource import load_restore_dic, load_vocab_out
from khaiii.resource.resource import load_vocab_out, parse_restore_dic
from khaiii.resource.trie import Trie

from compile_restore import append_new_entries
Expand Down Expand Up @@ -231,7 +231,7 @@ def run(args: Namespace):
args: program arguments
"""
aligner = Aligner(args.rsc_src)
restore_dic = load_restore_dic('{}/restore.dic'.format(args.rsc_src))
restore_dic = parse_restore_dic('{}/restore.dic'.format(args.rsc_src))
if not restore_dic:
sys.exit(1)
restore_new = defaultdict(dict)
Expand Down
4 changes: 2 additions & 2 deletions rsc/bin/compile_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from typing import Dict

from khaiii.resource.morphs import TAG_SET
from khaiii.resource.resource import load_restore_dic, load_vocab_out
from khaiii.resource.resource import load_vocab_out, parse_restore_dic


#############
Expand Down Expand Up @@ -139,7 +139,7 @@ def run(args: Namespace):
Args:
args: program arguments
"""
restore_dic = load_restore_dic('{}/restore.dic'.format(args.rsc_src))
restore_dic = parse_restore_dic('{}/restore.dic'.format(args.rsc_src))
if not restore_dic:
sys.exit(1)
vocab_out = load_vocab_out(args.rsc_src)
Expand Down
6 changes: 3 additions & 3 deletions src/main/python/khaiii/resource/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def __init__(self, cfg: Namespace):
vocab_out_path = '{}/vocab.out'.format(cfg.rsc_src)
self.vocab_out = Vocabulary(vocab_out_path) # no unknown, no special
restore_dic_path = '{}/restore.dic'.format(cfg.rsc_src)
self.restore_dic = self._load_restore_dic(restore_dic_path)
self.restore_dic = self.load_restore_dic(restore_dic_path)

@classmethod
def _load_restore_dic(cls, path: str) -> Dict[str, str]:
def load_restore_dic(cls, path: str) -> Dict[str, str]:
"""
load character to output tag mapping
Args:
Expand All @@ -69,7 +69,7 @@ def _load_restore_dic(cls, path: str) -> Dict[str, str]:
#############
# functions #
#############
def load_restore_dic(file_path: str) -> Dict[Tuple[str, str], Dict[int, str]]:
def parse_restore_dic(file_path: str) -> Dict[Tuple[str, str], Dict[int, str]]:
"""
원형복원 사전을 로드한다.
Args:
Expand Down
4 changes: 2 additions & 2 deletions src/main/python/khaiii/train/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging
import os
import random
from typing import List, TextIO, Tuple
from typing import Dict, List, TextIO, Tuple

import torch
from torch import Tensor
Expand Down Expand Up @@ -210,7 +210,7 @@ class PosDataset:
"""
part-of-speech tag dataset
"""
def __init__(self, cfg: Namespace, restore_dic: dict, fin: TextIO):
def __init__(self, cfg: Namespace, restore_dic: Dict[str, str], fin: TextIO):
"""
Args:
cfg: config
Expand Down
10 changes: 5 additions & 5 deletions src/main/python/khaiii/train/sentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import logging
import re

from typing import List, Tuple
from typing import Dict, List, Tuple


#########
Expand Down Expand Up @@ -112,7 +112,7 @@ def __eq__(self, other: 'PosWord'):
"""
return self.res_chrs == other.res_chrs and self.res_tags == other.res_tags

def set_pos_result(self, tags: List[str], restore_dic: dict = None):
def set_pos_result(self, tags: List[str], restore_dic: Dict[str, str] = None):
"""
외부에서 생성된 PosWord객체의 정보를 현재 인스턴스에 설정합니다.
Args:
Expand All @@ -125,7 +125,7 @@ def set_pos_result(self, tags: List[str], restore_dic: dict = None):
assert len(self.raw) == len(self.tags) # 음절수와 태그수는 동일해야 한다.
self.pos_tagged_morphs = self._make_pos_morphs(restore_dic)

def _make_pos_morphs(self, restore_dic: dict = None):
def _make_pos_morphs(self, restore_dic: Dict[str, str] = None):
"""
형태소 태그리스트를 대상으로 B/I 로 병합되는 위치를 구합니다.
Args:
Expand Down Expand Up @@ -159,7 +159,7 @@ def _make_pos_morphs(self, restore_dic: dict = None):
(lex, iob_tag, self.res_chrs, self.res_tags))
return pos_morphs

def _restore(self, restore_dic: dict):
def _restore(self, restore_dic: Dict[str, str]):
"""
원형 복원 사전을 이용하여 형태소의 원형을 복원한다.
Args:
Expand Down Expand Up @@ -234,7 +234,7 @@ def init_pos_tags(self):
for word in self.words:
self.pos_tagged_words.append(PosWord(word))

def set_pos_result(self, tags: List[str], restore_dic: dict = None):
def set_pos_result(self, tags: List[str], restore_dic: Dict[str, str] = None):
"""
문장 전체에 대한 형태소 태그 출력 레이블 정보를 세팅하고 형태소를 복원한다.
Args:
Expand Down
4 changes: 2 additions & 2 deletions train/validate_errpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from khaiii.munjong.sejong_corpus import Sentence, sents
from khaiii.resource.char_align import Aligner, AlignError, align_patch, align_to_tag
from khaiii.resource.morphs import mix_char_tag, WORD_DELIM_NUM, SENT_DELIM_NUM
from khaiii.resource.resource import load_restore_dic, load_vocab_out
from khaiii.resource.resource import load_vocab_out, parse_restore_dic


#########
Expand Down Expand Up @@ -198,7 +198,7 @@ def run(args: Namespace):
args: program arguments
"""
aligner = Aligner(args.rsc_src)
restore_dic = load_restore_dic('{}/restore.dic'.format(args.rsc_src))
restore_dic = parse_restore_dic('{}/restore.dic'.format(args.rsc_src))
if not restore_dic:
sys.exit(1)
vocab_out = load_vocab_out(args.rsc_src)
Expand Down

0 comments on commit b36d1a4

Please sign in to comment.