├── preprocess-text.sh ├── .gitattributes ├── extract-text.sh ├── .gitignore ├── preprocess.py └── README.md /preprocess-text.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | pip install tqdm kss 3 | python preprocess.py 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /extract-text.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git clone -b v3.0.4 https://github.com/attardi/wikiextractor.git /wikiextractor 4 | cd /wikiextractor 5 | cat < a.patch 6 | diff --git a/wikiextractor/extract.py b/wikiextractor/extract.py 7 | index 5dd2a93..0d93675 100644 8 | --- a/wikiextractor/extract.py 9 | +++ b/wikiextractor/extract.py 10 | @@ -823,7 +823,7 @@ class Extractor(): 11 | self.recursion_exceeded_3_errs = 0 # parameter recursion 12 | self.template_title_errs = 0 13 | 14 | - def clean_text(self, text, mark_headers=False, expand_templates=False, 15 | + def clean_text(self, text, mark_headers=True, expand_templates=False, 16 | escape_doc=True): 17 | """ 18 | :param mark_headers: True to distinguish headers from paragraphs 19 | EOF 20 | patch -p1 < a.patch 21 | pip install . 22 | 23 | cd /app 24 | python -m wikiextractor.WikiExtractor $WIKI_FILE 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # celery beat schedule file 95 | celerybeat-schedule 96 | 97 | # SageMath parsed files 98 | *.sage.py 99 | 100 | # Environments 101 | .env 102 | .venv 103 | env/ 104 | venv/ 105 | ENV/ 106 | env.bak/ 107 | venv.bak/ 108 | 109 | # Spyder project settings 110 | .spyderproject 111 | .spyproject 112 | 113 | # Rope project settings 114 | .ropeproject 115 | 116 | # mkdocs documentation 117 | /site 118 | 119 | # mypy 120 | .mypy_cache/ 121 | .dmypy.json 122 | dmypy.json 123 | 124 | # Pyre type checker 125 | .pyre/ 126 | 127 | /text/ 128 | /text-preprocessed/ 129 | -------------------------------------------------------------------------------- /preprocess.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | from multiprocessing import Pool 4 | from functools import partial 5 | 6 | from kss import split_sentences 7 | from tqdm import tqdm 8 | 9 | parser = argparse.ArgumentParser() 10 | parser.add_argument("--input-path", default='text') 11 | parser.add_argument("--output-path", default='text-preprocessed') 12 | 13 | 14 | def preprocess_fn(filename, input_path, output_path): 15 | path = filename[len(input_path):] 16 | if path.startswith("/"): 17 | path = path[1:] 18 | filedir = os.path.dirname(path) 19 | 20 | target_path = os.path.join(output_path, filedir) 21 | target_file = os.path.join(output_path, path) 22 | 23 | os.makedirs(target_path, exist_ok=True) 24 | 25 | with open(filename, encoding='utf8') as in_file, open(target_file, 'w', encoding='utf8') as out_file: 26 | heading = '' 27 | subheading = '' 28 | content = '' 29 | 30 | for line in in_file: 31 | line = line.strip() 32 | 33 | if line.startswith("Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. 4 | 5 | 문장 단위로 분절한 한국어 위키피디아 코퍼스 6 | 7 | ## 사용법 8 | 9 | Releases에서 직접 다운로드받은 후 사용하시거나, [tfds-korean 패키지](https://github.com/jeongukjae/tfds-korean)([카탈로그 페이지](https://jeongukjae.github.io/tfds-korean/datasets/korean_wikipedia_corpus.html))를 이용해 사용하세요. 10 | 11 | ## 텍스트 추출 방법 12 | 13 | wikiextractor를 통해 한번 뽑아낸 다음, ``안에서 같은 섹션에 존재하는 문장을 전부 개행문자로 이어놓았습니다. 14 | 문장은 [kss](https://github.com/hyunwoongko/kss)를 사용하여 분리하였습니다. 15 | 16 | 문서와 문서 사이에는 개행문자 두개가 존재합니다. 17 | 문서의 첫 문장은 항상 제목입니다. 18 | 제목만을 담고 있을 경우에는 문서가 저장되지 않습니다. 19 | 20 | 즉, 아래와 같은 포맷입니다. 21 | 22 | ```text 23 | 문서1 제목 24 | 문서1 - 문장1 25 | 문서1 - 문장2 26 | 문서1 - 문장... 27 | 문서1 - 문장n 28 | 29 | 문서2 제목 30 | 문서2 - 문장1 31 | 문서2 - 문장2 32 | 문서2 - 문장... 33 | 문서2 - 문장m 34 | 35 | 문서3 제목 36 | 문서3 - 문장1 37 | 문서3 - 문장2 38 | 문서3 - 문장... 39 | 문서3 - 문장m 40 | 41 | ... 42 | ``` 43 | 44 | 예시 45 | 46 | ```text 47 | 나성범 48 | 나성범(羅成範, 1989년 10월 3일 ~ )은 KBO 리그 NC 다이노스의 외야수이다. 49 | 그의 형은 KBO 리그 KIA 타이거즈의 잔류군 배터리코치인 나성용이다. 50 | 51 | 나성범 - 아마추어 시절. 52 | 2008년 신인 드래프트에서 2차 4라운드 8순위(전체 32순위)로 LG 트윈스의 지명을 받았으나 연세대학교 체육교육학과에 진학했다. 53 | 연세대학교 2학년 때인 2010년에 중앙대학교 투수 김명성과 함께 광저우 아시안 게임 예비 엔트리에 발탁됐으나 최종 엔트리에 선발되지 못했다. 54 | 그는 연고전에서 인상적인 활약을 펼쳤다. 55 | 연고전 등판 기록은 4경기에 등판해 34.2이닝동안 2승 1패, 평균자책점 2.34였다. 56 | 당시 고려대학교는 윤명준, 임치영, 문승원의 선발 트로이카와 김재율, 홍재호, 김준완 등이 이끄는 막강한 타선을 갖추고 있었고 연세대학교 체육교육학과는 그의 형인 나성용, 유민상, 최재원이 주축이 돼 상대적으로 전력이 약세였지만 그의 맹활약으로 2008년부터 2012년까지 고려대학교를 상대로 2승 1무 1패로 우위를 지켰다. 57 | 58 | 나성범 - 2012년 시즌. 59 | 신인 드래프트에서 2라운드 1순위(전체 10순위) 지명을 받아 창단 멤버로 입단했고, 뒤이어 2011년 야구 월드컵에 국가대표로 발탁됐다. 60 | 투수로 입단했으나, 당시 감독이었던 김경문의 권유로 2011년 가을 마무리 캠프를 통해 외야수로 전향했다. 61 | 2군 94경기에 출전해 타율 0.303, 16홈런, 67타점, 29도루, 33사구를 기록했다. 62 | 시즌 중에는 4할 타율을 기록했으나 손바닥 부상과 체력 저하로 인해 페이스가 떨어졌다. 63 | 남부 리그 최다 홈런, 최다 타점을 기록했고 팀 내에서 유일하게 3할 타율을 기록했다. 64 | 시즌 후 2012년 아시아 야구 선수권 대회 국가대표에 발탁됐으나 오른쪽 손등 부상으로 인해 박정준으로 교체됐다. 65 | 66 | ... 67 | ``` 68 | 69 | ## 사용법 70 | 71 | 1. 에서 덤프파일 다운로드 72 | 2. 텍스트 파일로 변환 73 | 74 | ```sh 75 | docker run \ 76 | --rm \ 77 | -it \ 78 | -w /app \ 79 | -v `pwd`:/app \ 80 | -v WIKI_FILE_PATH:/wiki.xml.bz2:ro \ 81 | -e WIKI_FILE=/wiki.xml.bz2 \ 82 | python:3.6 bash -c ./extract-text.sh 83 | ``` 84 | 85 | 이 단계 후에도 문서 제목과 `` 태그가 남아있어 아래 스크립트를 추가했습니다. 86 | 87 | 3. 텍스트만 추출 88 | 89 | ```sh 90 | docker run \ 91 | --rm \ 92 | -it \ 93 | -w /app \ 94 | -v `pwd`:/app \ 95 | python:3.6 bash -c ./preprocess-text.sh 96 | ``` 97 | --------------------------------------------------------------------------------