| import pandas as pd |
| import os |
| import json |
| from tqdm import tqdm |
|
|
| |
| |
| |
| |
| input_file_path = '/chosun_pos_tagged_parallel.jsonl' |
| |
| output_dir = '/koselleck_analysis_results' |
| output_file_path = os.path.join(output_dir, 'neologism_rate_decade.csv') |
|
|
| |
| |
| |
| print("1. 전처리된 데이터를 로드하여 10년 단위 어휘 목록을 구축합니다.") |
| try: |
| |
| decade_vocabs = {} |
| |
| |
| with open(input_file_path, 'r', encoding='utf-8') as f: |
| for line in tqdm(f, desc="파일 로딩 및 어휘 목록 구축"): |
| record = json.loads(line) |
| if record.get('type') == 'article' and record.get('year'): |
| decade = (record['year'] // 10) * 10 |
| if decade not in decade_vocabs: |
| decade_vocabs[decade] = set() |
| |
| nouns = {word for word, pos in record['pos_tagged_body'] if pos == 'Noun'} |
| decade_vocabs[decade].update(nouns) |
|
|
| print("10년 단위 어휘 목록 구축 완료.") |
|
|
| except FileNotFoundError: |
| print(f"오류: '{input_file_path}'를 찾을 수 없습니다.") |
| exit() |
| except Exception as e: |
| print(f"데이터 처리 중 오류 발생: {e}") |
| exit() |
|
|
| |
| |
| |
| print("\n2. 10년 단위 신조어 출현율을 계산합니다.") |
|
|
| neologism_data = [] |
| sorted_decades = sorted(decade_vocabs.keys()) |
|
|
| for i in range(1, len(sorted_decades)): |
| current_decade = sorted_decades[i] |
| previous_decade = sorted_decades[i-1] |
| |
| vocab_current = decade_vocabs[current_decade] |
| vocab_previous = decade_vocabs[previous_decade] |
| |
| |
| new_words = vocab_current - vocab_previous |
| |
| |
| if len(vocab_current) > 0: |
| rate = (len(new_words) / len(vocab_current)) * 100 |
| neologism_data.append({ |
| 'decade': current_decade, |
| 'neologism_rate': rate, |
| 'new_words_count': len(new_words), |
| 'total_vocab_count': len(vocab_current) |
| }) |
|
|
| neologism_df = pd.DataFrame(neologism_data) |
| print("\n[10년 단위 신조어 출현율 계산 결과]") |
| print(neologism_df) |
|
|
| |
| |
| |
| print("\n3. 분석 결과를 파일로 저장합니다.") |
| os.makedirs(output_dir, exist_ok=True) |
| neologism_df.to_csv(output_file_path, index=False, encoding='utf-8-sig') |
| print(f"신조어 분석 결과가 다음 경로에 저장되었습니다: {output_file_path}") |
| print("\n> '시간의 가속화' (10년 단위) 분석이 완료되었습니다.") |
|
|