Skip to content

Commit

Permalink
style: json에 교정문장 추가, score 포맷 수정
Browse files Browse the repository at this point in the history
[#12]
  • Loading branch information
9ooDa committed Mar 24, 2024
1 parent 15359bf commit c8454b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions models/utils/gram_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import string
from typing import List, Dict, Literal, get_args
from .gram_out_json import get_cleaned_token_list, get_scrs_tok
from typing import Dict, Literal, get_args
from out_json import get_cleaned_token_list, get_scrs_tok


def get_error_count(
Expand Down Expand Up @@ -33,7 +33,7 @@ def get_error_rate_sen(
error_count = get_error_count(checker_data=checker_data)
sentence_count = len(og_list)

return error_count / sentence_count
return round(error_count / sentence_count, 2)


def get_error_rate_word(
Expand All @@ -47,12 +47,14 @@ def get_error_rate_word(
# remove punctuations
new_sen = sen.translate(str.maketrans('', '', string.punctuation))
word_count += len(new_sen.split(" "))
result = (1 - (error_count / word_count)) * 100

return 1 - (error_count / word_count)
return round(result, 2)

# ec = error count, psc = per sentence count, pwc = per word count
_TYPES = Literal["ec", "psc", "pwc"]


def get_score(
checker_data: Dict,
score_type: _TYPES = "pwc",
Expand Down
6 changes: 5 additions & 1 deletion models/utils/gram_out_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def get_phase_1_data(
def get_phase_2_inner_data(
sid: int,
sent: str,
corr_sent: str,
edited: bool,
ref_word_list: List,
tag_list: List,
Expand All @@ -213,6 +214,7 @@ def get_phase_2_inner_data(
inner = {
"sid": int,
"sentence": str,
"corrected_sentence": str,
"edited": False,
"ref_word": [],
"category": [],
Expand All @@ -221,6 +223,7 @@ def get_phase_2_inner_data(
}
inner["sid"] = sid
inner["sentence"] = sent
inner["corrected_sentence"] = corr_sent
inner["edited"] = edited
inner["ref_word"] = ref_word_list
inner["tag"] = tag_list
Expand Down Expand Up @@ -251,11 +254,12 @@ def get_phase_2_data(
gector_dict = get_scrs_tok(inner_dict, ctl)
sid = sentence_list.index(og_sent)
sent = og_sent
corr_sent = inner_dict["fin_sentence"]
edited = inner_dict["edited"]
ref_word_list = gector_dict["og_word"]
tag_list = gector_dict["full_tag"]
if edited == True:
inner = get_phase_2_inner_data(sid=sid, sent=sent, edited=edited, ref_word_list=ref_word_list,
inner = get_phase_2_inner_data(sid=sid, sent=sent, corr_sent=corr_sent, edited=edited, ref_word_list=ref_word_list,
tag_list=tag_list, tag_grammar=tag_grammar)
tag_gram_dict["tag_grammar_info"].append(inner)

Expand Down

0 comments on commit c8454b9

Please sign in to comment.