from hanspell import spell_checker
import openpyxl
def read_excel(file_name,x,y): #엑셀을 읽는 함수 (파일명, x좌표, y좌표)
dataExcel=openpyxl.load_workbook(file_name) #파일 오픈
ws1 = dataExcel.active
word=ws1.cell(row=y,column=x).value #워드 읽기
return word #읽은 워드 리턴
def write_excel(file_name,x,y,output_word): #엑셀에 파일에 입력
dataExcel=openpyxl.load_workbook(file_name)
ws1 = dataExcel.active
ws1.cell(row=y,column=x).value=output_word
dataExcel.save(file_name) #엑셀에 입력
def read_txt(file_name):
f=open(file_name,mode='rt',encoding='utf-8')
output_meg=f.read()
return output_meg
def checkString(inputString):
f=spell_checker.check(inputString)
return f
def main():#메인문 시작
excel_file_name="spellcheck.xlsx" #입력 및 출력을 위한 파일명
for y in range(2,10):
input_word=read_excel(excel_file_name,1,y) #문구 받아옴
result=spell_checker.check(input_word) #체크하기
result.as_dict()
print(result.only_checked())
write_excel(excel_file_name,2,y,result.only_checked()) #출력
def main_txt():
fileNameTxt="test.txt"
inputTxt=read_txt(fileNameTxt)
split_string=inputTxt.split(sep='\n')
for i in split_string:
o=checkString(i)
#print("수정전 문구: "+o.original()+"\n")
if(o.original!=o.checked):
print("변경전: "+ o.original)
print("\n")
print("변경후: "+o.checked)
print("\n\n")
main_txt()
'STUDY' 카테고리의 다른 글
언어 처리 학습 - 감정분석 (1) | 2024.09.25 |
---|---|
RPA 만들기 : 오타 검증 프로그램 만들기 (파이썬 활용) (0) | 2020.10.10 |