정보통신기술(ICT)

한국어-영어 맞춤법 기초 검사기

해머슴 2024. 11. 14. 21:31
import tkinter as tk
from textblob import TextBlob
import nltk

# nltk punkt 데이터 다운로드 (필요한 경우 자동 다운로드)
try:
    nltk.data.find('tokenizers/punkt')
except LookupError:
    nltk.download('punkt', quiet=True)  # 다운로드 시 메시지 생략을 위해 quiet=True 사용

def check_spelling():
    # 입력받은 텍스트 가져오기
    input_text = text_input.get("1.0", tk.END).strip()
    result_text.delete("1.0", tk.END)  # 이전 결과 삭제

    # 한국어와 영어에 맞춰 단순한 맞춤법 검사 및 추천
    if input_text:
        if all('\uAC00' <= char <= '\uD7A3' for char in input_text):  # 한국어 문장인지 확인
            # 기본 한국어 맞춤법 검사 (예시: 모든 받침이 정확하게 들어갔는지 확인)
            # 실제 맞춤법 검사는 패키지가 필요하며 여기서는 예시로 대체
            result_text.insert(tk.END, f"한국어 문장은 잘 입력되었습니다.\n")
        else:
            # 영어 문장인 경우 TextBlob으로 맞춤법 검사
            blob = TextBlob(input_text)
            corrected_text = str(blob.correct())
            result_text.insert(tk.END, f"Original: {input_text}\nCorrected: {corrected_text}\n")

        # 역사 순환에 기반한 문장 예시 (임의의 예시 제공)
        result_text.insert(tk.END, "\n역사 순환의 예시 문장: '역사는 반복된다.'\n")

# GUI 설정
root = tk.Tk()
root.title("한국어-영어 맞춤법 기초 검사기")

# 입력 필드와 레이블
label = tk.Label(root, text="한국어 또는 영어 문장을 입력하세요:")
label.pack()
text_input = tk.Text(root, height=5, width=50)
text_input.pack()

# 검사 버튼
check_button = tk.Button(root, text="검사하기", command=check_spelling)
check_button.pack()

# 결과 출력 필드
result_label = tk.Label(root, text="결과:")
result_label.pack()
result_text = tk.Text(root, height=10, width=50)
result_text.pack()

root.mainloop()