├── ndic ├── tests │ ├── __init__.py │ ├── scripts │ │ ├── __init__.py │ │ └── test_search.py │ └── test_search.py ├── scripts │ ├── __init__.py │ └── search.py ├── __init__.py ├── constants.py ├── exceptions.py ├── search.py └── utils.py ├── dev-requirements.txt ├── doc-requirements.txt ├── setup.cfg ├── .coveragerc ├── test-requirements.txt ├── requirements.txt ├── Makefile ├── MANIFEST.in ├── .travis.yml ├── tox.ini ├── LICENSE ├── .gitignore ├── setup.py ├── docs ├── index.rst ├── Makefile ├── make.bat └── conf.py └── README.rst /ndic/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ndic/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dev-requirements.txt: -------------------------------------------------------------------------------- 1 | twine 2 | -------------------------------------------------------------------------------- /doc-requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx 2 | -------------------------------------------------------------------------------- /ndic/tests/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [report] 2 | omit = 3 | */python?.?/* 4 | */site-packages/* 5 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | virtualenv 2 | nose 3 | coveralls 4 | tox 5 | tox-pyenv 6 | flake8 7 | mock 8 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests>=2.11.0 2 | beautifulsoup4>=4.5.1 3 | click>=6.6 4 | lxml>=3.6.1 5 | future>=0.15.2 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | upload: 2 | - python setup.py sdist 3 | - twine upload dist/* 4 | testupload: 5 | - twine upload --repository testpypi dist/* 6 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | include MANIFEST.in 4 | include setup.cfg 5 | include setup.py 6 | include requirements.txt 7 | include test-requirements.txt 8 | -------------------------------------------------------------------------------- /ndic/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import absolute_import 3 | 4 | from pkg_resources import get_distribution 5 | 6 | from ndic.search import search 7 | 8 | 9 | __version__ = get_distribution('ndic').version 10 | 11 | __all__ = [ 12 | 'search', 13 | ] 14 | -------------------------------------------------------------------------------- /ndic/constants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | This module provides constants that are used within Ndic 5 | 6 | """ 7 | from __future__ import unicode_literals 8 | 9 | 10 | NAVER_ENDIC_URL = "http://endic.naver.com/search.nhn?"\ 11 | + "sLn=kr&searchOption=all&query={search_word}" 12 | 13 | CONNECTION_ERROR_MESSAGE = "Network connection is lost. "\ 14 | + "Please check the connection to the Internet." 15 | -------------------------------------------------------------------------------- /ndic/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | This module contains the set of Ndic' exceptions. 5 | 6 | """ 7 | from __future__ import absolute_import 8 | 9 | from ndic.constants import CONNECTION_ERROR_MESSAGE 10 | 11 | 12 | class NdicConnectionError(Exception): 13 | """ 14 | Exception raised when network is unconnected 15 | """ 16 | 17 | def __init__(self): 18 | pass 19 | 20 | def __str__(self): 21 | return CONNECTION_ERROR_MESSAGE 22 | 23 | def __repr__(self): 24 | return CONNECTION_ERROR_MESSAGE 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | # For python3.7 4 | # https://github.com/travis-ci/travis-ci/issues/9815 5 | matrix: 6 | include: 7 | - python: 2.7 8 | dist: trusty 9 | sudo: false 10 | - python: 3.4 11 | dist: trusty 12 | sudo: false 13 | - python: 3.5 14 | dist: trusty 15 | sudo: false 16 | - python: 3.6 17 | dist: trusty 18 | sudo: false 19 | - python: 3.7 20 | dist: xenial 21 | sudo: true 22 | # command to install dependencies 23 | install: 24 | - "pip install tox-travis" 25 | # command to run tests 26 | script: 27 | - tox -v 28 | -------------------------------------------------------------------------------- /ndic/scripts/search.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | This module provides functions for searching the word 5 | in command line interface by Ndic 6 | 7 | """ 8 | from __future__ import absolute_import 9 | 10 | import click 11 | 12 | from ndic.search import search 13 | 14 | 15 | @click.command() 16 | @click.argument('search_word') 17 | @click.option('--xth', '-x', default=1, help='xth meaning. default=1') 18 | def cli_search(search_word, xth): 19 | """ 20 | Search the SEARCH_WORD in English-Korean and Korean-English dictionaries 21 | and echo the corresponding Korean word(s) or English word(s). 22 | 23 | """ 24 | word_meaning = search(search_word, xth) 25 | click.echo(word_meaning) 26 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py34, py35, py36, py37, flake8, coveralls 3 | 4 | [tox:travis] 5 | 2.7 = py27 6 | 3.4 = py34 7 | 3.5 = py35 8 | 3.6 = py36, flake8, coveralls 9 | 3.7 = py37 10 | 11 | [testenv] 12 | passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH 13 | deps = 14 | nose 15 | coveralls 16 | mock 17 | commands = nosetests --with-coverage --cover-package=ndic 18 | 19 | [testenv:py27] 20 | basepython = python2.7 21 | 22 | [testenv:py34] 23 | basepython = python3.4 24 | 25 | [testenv:py35] 26 | basepython = python3.5 27 | 28 | [testenv:py36] 29 | basepython = python3.6 30 | 31 | [testenv:py37] 32 | basepython = python3.7 33 | 34 | [testenv:flake8] 35 | basepython = python3.6 36 | deps = flake8 37 | commands = flake8 --exclude ndic/lib ndic tests 38 | 39 | [testenv:coveralls] 40 | passenv = COVERALLS_REPO_TOKEN 41 | basepython = python3.6 42 | deps = coveralls 43 | commands = coveralls 44 | -------------------------------------------------------------------------------- /ndic/search.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | This module provides functions for searching the word by Ndic 5 | 6 | """ 7 | from __future__ import absolute_import 8 | 9 | from ndic.utils import make_naver_endic_url 10 | from ndic.utils import request_naver_endic_url 11 | from ndic.utils import get_word_meaning 12 | 13 | 14 | def search(search_word, xth=1): 15 | """ 16 | Search the word in English-Korean and Korean-English dictionaries 17 | and return the corresponding Korean word(s) or English word(s). 18 | 19 | Args: 20 | search_word: the word which user want to search 21 | Returns: 22 | English word(s) or Korean word(s) corresponding to the search_word 23 | Raises: 24 | NdicConnectionError: if network connection is lost. 25 | 26 | """ 27 | naver_endic_url = make_naver_endic_url(search_word) 28 | response = request_naver_endic_url(naver_endic_url) 29 | word_meaning = get_word_meaning(response, xth) 30 | return word_meaning 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 SeunghwanJoo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.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 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /ndic/utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | This module provides utility functions that are used within Ndic 5 | 6 | """ 7 | from __future__ import absolute_import 8 | 9 | import requests 10 | from bs4 import BeautifulSoup 11 | 12 | from ndic.constants import NAVER_ENDIC_URL 13 | from ndic.exceptions import NdicConnectionError 14 | 15 | 16 | def make_naver_endic_url(search_word): 17 | """ 18 | Return NAVER dictionary url which contains the value of 19 | search word parameter 20 | 21 | """ 22 | 23 | naver_endic_url = NAVER_ENDIC_URL.format( 24 | search_word=search_word, 25 | ) 26 | return naver_endic_url 27 | 28 | 29 | def request_naver_endic_url(naver_endic_url): 30 | """ 31 | Send a GET request to NAVER dictionary url 32 | 33 | """ 34 | 35 | try: 36 | response = requests.get(naver_endic_url) 37 | except requests.ConnectionError: 38 | raise NdicConnectionError() 39 | return response 40 | 41 | 42 | def get_word_meaning(response, xth): 43 | """ 44 | Parse a HTML document and get a text of xth meaning 45 | from particular tags 46 | By default, xth = 1 47 | """ 48 | 49 | dom = BeautifulSoup(response.content, "lxml") 50 | div_element = dom.select_one(".word_num") or None 51 | word_meaning = "" 52 | if div_element: 53 | word_meaning_elements = div_element.select(".fnt_k05") 54 | meaning_cnt = len(word_meaning_elements) 55 | if 1 <= xth and xth <= meaning_cnt: 56 | word_meaning = word_meaning_elements[xth-1].text 57 | return word_meaning 58 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | import os 3 | 4 | 5 | ROOT = os.path.abspath(os.path.dirname(__file__)) 6 | VERSION = '1.9' 7 | 8 | def get_requirements(filename): 9 | return open(os.path.join(ROOT, filename)).read().splitlines() 10 | 11 | setup( 12 | name='ndic', 13 | packages=find_packages(), 14 | include_package_data=True, 15 | install_requires=get_requirements('requirements.txt'), 16 | tests_require=get_requirements('test-requirements.txt'), 17 | version=VERSION, 18 | description='Python module for NAVER English-Korean and Korean-English dictionaries', 19 | long_description=open(os.path.join(ROOT, 'README.rst')).read(), 20 | author='jupiny', 21 | author_email='tmdghks584@gmail.com', 22 | url='https://github.com/jupiny/ndic', 23 | download_url='https://pypi.python.org/pypi/ndic', 24 | # keywords = ['dictionary', 'translate', 'English', 'Korean', 'Naver'], 25 | license='MIT', 26 | platforms = "Posix; MacOS X; Windows", 27 | test_suite='nose.collector', 28 | entry_points=''' 29 | [console_scripts] 30 | ndic=ndic.scripts.search:cli_search 31 | ''', 32 | classifiers=[ 33 | 'Development Status :: 5 - Production/Stable', 34 | 'Topic :: Software Development :: Testing', 35 | 'Intended Audience :: Developers', 36 | 'License :: OSI Approved :: MIT License', 37 | 'Operating System :: OS Independent', 38 | 'Programming Language :: Python', 39 | 'Programming Language :: Python :: 2.7', 40 | 'Programming Language :: Python :: 3.4', 41 | 'Programming Language :: Python :: 3.5', 42 | 'Programming Language :: Python :: 3.6', 43 | 'Programming Language :: Python :: 3.7', 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. ndic documentation master file, created by 2 | sphinx-quickstart on Fri Sep 2 16:23:42 2016. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Ndic Documentation 7 | ****************** 8 | 9 | Ndic is Python package for NAVER English-Korean and Korean-English dictionaries. 10 | 11 | Search of both English-Korean and Korean-English dictionaries is provided. 12 | 13 | Ndic works by crawling the web http://endic.naver.com/. To crawl, it 14 | uses `Requests`_ and `BeautifulSoup`_. Therefore, you should use it in **Internet Environments**. 15 | 16 | Ndic supports Python Python 2.7 & 3.4–3.7 because `Requests officially 17 | supports these versions.`_ 18 | 19 | 20 | Installation 21 | ============ 22 | 23 | Install via pip: 24 | 25 | .. code-block:: bash 26 | 27 | pip install ndic 28 | 29 | Quickstart 30 | =========== 31 | 32 | The usage is very simple. 33 | 34 | But, make sure that: 35 | 36 | * Ndic is installed 37 | * The user is connected to the Internet. 38 | 39 | Let's get started with some simple examples. 40 | 41 | Search for Words 42 | ---------------- 43 | 44 | Begin by importing the Ndic module: 45 | 46 | .. code-block:: python 47 | 48 | >>> import ndic 49 | 50 | Entering an English word as the ``search`` function argument will return the 51 | corresponding Korean word(s). 52 | 53 | .. code-block:: python 54 | 55 | >>> ndic.search('apple') 56 | '사과' 57 | 58 | Conversely, entering a Korean word as the ``search`` function argument will return 59 | the corresponding English word(s). 60 | 61 | .. code-block:: python 62 | 63 | >>> ndic.search('안녕하세요') 64 | 'Hi!' 65 | 66 | Multiple Definitions 67 | -------------------- 68 | 69 | If the word you search has multiple meanings, you can choose the meaning of the desired order. 70 | 71 | Unless you set any xth value, you will get the first meaning of the word. 72 | 73 | .. code-block:: python 74 | 75 | >>> ndic.search('말', 1) # 1st meaning 76 | '(언어) word, language, speech, (literary) tongue' 77 | >>> ndic.search('말', 2) # 2nd meaning 78 | '(동물) horse' 79 | 80 | Search for Phrases 81 | ------------------ 82 | 83 | Phrases may also be searched. 84 | 85 | .. code-block:: python 86 | 87 | >>> ndic.search('in order to') 88 | '(목적) 위하여' 89 | 90 | Search for Nonexistent Words 91 | ---------------------------- 92 | 93 | Entering a nonexistent word as the ``search`` function argument will return the 94 | empty string. 95 | 96 | .. code-block:: python 97 | 98 | >>> ndic.search("aslkjfwe") 99 | '' 100 | >>> ndic.search("아댜리야") 101 | '' 102 | 103 | Network Error 104 | ------------- 105 | 106 | If your network connection is lost, you will get below error message. 107 | 108 | .. code-block:: python 109 | 110 | >>> ndic.search('...') 111 | NdicConnectionError: Network connection is lost. Please check the connection to the Internet. 112 | 113 | Command Line Interface 114 | ====================== 115 | 116 | Furthermore, Ndic supports CLI(Command Line System). 117 | 118 | So you can use it 119 | in command line and get the return value of the ``search`` fuction in terminals. It works 120 | by `Click`_. 121 | 122 | .. code-block:: bash 123 | 124 | $ ndic love 125 | (특히 가족・친구에 대한) 사랑 126 | $ ndic get --xth 2 # or -x 2 127 | 얻다, 입수하다; 가지다(obtain) 128 | 129 | .. _Requests: http://docs.python-requests.org/en/master/ 130 | .. _BeautifulSoup: https://www.crummy.com/software/BeautifulSoup/bs4/doc/ 131 | .. _Requests officially supports these versions.: https://github.com/kennethreitz/requests#feature-support 132 | .. _Click: http://click.pocoo.org/5/ 133 | -------------------------------------------------------------------------------- /ndic/tests/test_search.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals, absolute_import 3 | 4 | from unittest import TestCase 5 | 6 | import mock 7 | import requests 8 | 9 | from ndic.search import search 10 | from ndic.exceptions import NdicConnectionError 11 | 12 | 13 | class NdicTestCase(TestCase): 14 | 15 | def test_search_korean_word(self): 16 | test_search_korean_word = "사과" 17 | test_corresponding_english_word = "(과일) apple" 18 | self.assertEqual( 19 | search(test_search_korean_word), 20 | test_corresponding_english_word, 21 | ) 22 | 23 | def test_search_english_word(self): 24 | test_search_english_word = "apple" 25 | test_corresponding_korean_word = "사과" 26 | self.assertEqual( 27 | search(test_search_english_word), 28 | test_corresponding_korean_word, 29 | ) 30 | 31 | def test_search_nonexistent_korean_word(self): 32 | test_nonexistent_korean_word = "아갸야라" 33 | self.assertFalse( 34 | search(test_nonexistent_korean_word), 35 | ) 36 | 37 | def test_search_nonexistent_english_word(self): 38 | test_nonexistent_english_word = "asfasdfasdf" 39 | self.assertFalse( 40 | search(test_nonexistent_english_word), 41 | ) 42 | 43 | def test_search_korean_word_multiple_meaning(self): 44 | test_search_korean_word = "말" 45 | test_corresponding_english_word_1 = "(언어) word, language, speech, " \ 46 | "(literary) tongue" 47 | test_corresponding_english_word_2 = "(동물) horse" 48 | test_corresponding_english_word_3 = "(마지막) end (of), close (of)" 49 | self.assertEqual( 50 | search(test_search_korean_word, 1), 51 | test_corresponding_english_word_1, 52 | ) 53 | self.assertEqual( 54 | search(test_search_korean_word, 2), 55 | test_corresponding_english_word_2, 56 | ) 57 | self.assertEqual( 58 | search(test_search_korean_word, 3), 59 | test_corresponding_english_word_3, 60 | ) 61 | 62 | def test_search_english_word_multiple_meaning(self): 63 | test_search_english_word = "get" 64 | test_corresponding_korean_word_1 = "받다" 65 | test_corresponding_korean_word_2 = "얻다, 입수하다; 가지다(obtain)" 66 | test_corresponding_korean_word_3 = "(동물의) 새끼; 새끼를 낳음" 67 | self.assertEqual( 68 | search(test_search_english_word, 1), 69 | test_corresponding_korean_word_1, 70 | ) 71 | self.assertEqual( 72 | search(test_search_english_word, 2), 73 | test_corresponding_korean_word_2, 74 | ) 75 | self.assertEqual( 76 | search(test_search_english_word, 3), 77 | test_corresponding_korean_word_3, 78 | ) 79 | 80 | def test_search_xth_exceed(self): 81 | test_nonexistent_english_word = "말" 82 | self.assertFalse( 83 | search(test_nonexistent_english_word, 10), 84 | ) 85 | 86 | def test_search_negative_or_zero_xth(self): 87 | test_nonexistent_english_word = "말" 88 | self.assertFalse( 89 | search(test_nonexistent_english_word, -1), 90 | ) 91 | self.assertFalse( 92 | search(test_nonexistent_english_word, 0), 93 | ) 94 | 95 | @mock.patch.object(requests, 'get', side_effect=requests.ConnectionError) 96 | def test_search_without_internet_network(self, mock_requests): 97 | test_search_korean_word = "사과" 98 | self.assertRaises( 99 | NdicConnectionError, 100 | search, 101 | test_search_korean_word, 102 | ) 103 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Ndic 2 | ==== 3 | 4 | |Build Status| |Coverage Status| |Pypi Version| |Downloads Per Month| |License MIT| 5 | 6 | Python package for NAVER English-Korean and Korean-English dictionaries 7 | 8 | Introduction 9 | ------------ 10 | 11 | Search of both English-Korean and Korean-English dictionaries is 12 | provided. 13 | 14 | Requirements 15 | ------------ 16 | 17 | Ndic works by crawling the web http://endic.naver.com/. To crawl, it 18 | uses `Requests`_ and `BeautifulSoup`_. 19 | 20 | Therefore, you should use it in **Internet Environments**. 21 | 22 | Ndic supports Python 2.7 & 3.4–3.7 because `Requests officially 23 | supports these versions.`_ 24 | 25 | Installation 26 | ------------ 27 | 28 | Install via pip: 29 | 30 | .. code-block:: bash 31 | 32 | $ pip install ndic 33 | 34 | Usage 35 | ----- 36 | 37 | The usage is very simple. 38 | 39 | Begin by importing the Ndic module: 40 | 41 | .. code-block:: python 42 | 43 | >>> import ndic 44 | 45 | Entering an English word as the ``search`` function argument will return the 46 | corresponding Korean word(s). 47 | 48 | .. code-block:: python 49 | 50 | >>> ndic.search('apple') 51 | '사과' 52 | 53 | Conversely, entering a Korean word as the ``search`` function argument will return 54 | the corresponding English word(s). 55 | 56 | .. code-block:: python 57 | 58 | >>> ndic.search('안녕하세요') 59 | 'Hi!' 60 | 61 | If the word you search has multiple meanings, you can choose the meaning of the desired order. 62 | 63 | Unless you set any ``xth`` value, you will get the first meaning of the word. 64 | 65 | .. code-block:: python 66 | 67 | >>> ndic.search('말', 1) # 1st meaning 68 | '(언어) word, language, speech, (literary) tongue' 69 | >>> ndic.search('말', 2) # 2nd meaning 70 | '(동물) horse' 71 | 72 | Phrases may also be searched. 73 | 74 | .. code-block:: python 75 | 76 | >>> ndic.search('in order to') 77 | '(목적) 위하여' 78 | 79 | Entering a nonexistent word as the ``search`` function argument will return the 80 | empty string. 81 | 82 | .. code-block:: python 83 | 84 | >>> ndic.search("aslkjfwe") 85 | '' 86 | >>> ndic.search("아댜리야") 87 | '' 88 | 89 | If your network connection is lost, you will get below error message. 90 | 91 | .. code-block:: python 92 | 93 | >>> ndic.search('...') 94 | NdicConnectionError: Network connection is lost. Please check the connection to the Internet. 95 | 96 | Command Line Interface 97 | ---------------------- 98 | 99 | Furthermore, Ndic supports CLI(Command Line System). 100 | 101 | So you can use it 102 | in command line and get the return value of the ``search`` fuction in terminals. It works 103 | by `Click`_. 104 | 105 | .. code-block:: bash 106 | 107 | $ ndic love 108 | (특히 가족・친구에 대한) 사랑 109 | $ ndic get --xth 2 # or -x 2 110 | 얻다, 입수하다; 가지다(obtain) 111 | 112 | .. _Requests: http://docs.python-requests.org/en/master/ 113 | .. _BeautifulSoup: https://www.crummy.com/software/BeautifulSoup/bs4/doc/ 114 | .. _Requests officially supports these versions.: https://github.com/kennethreitz/requests#feature-support 115 | .. _Click: http://click.pocoo.org/5/ 116 | 117 | .. |Build Status| image:: https://travis-ci.org/jupiny/ndic.svg?branch=master 118 | :target: https://travis-ci.org/jupiny/ndic 119 | .. |Coverage Status| image:: https://coveralls.io/repos/github/jupiny/ndic/badge.svg?branch=master 120 | :target: https://coveralls.io/github/jupiny/ndic?branch=master 121 | .. |Pypi Version| image:: https://img.shields.io/pypi/v/ndic.svg 122 | :target: https://pypi.python.org/pypi/ndic 123 | .. |Downloads Per Month| image:: https://img.shields.io/pypi/dm/ndic.svg 124 | :target: https://pypi.python.org/pypi/ndic 125 | .. |License MIT| image:: https://img.shields.io/badge/license-MIT-blue.svg 126 | :target: https://raw.githubusercontent.com/jupiny/ndic/master/LICENSE 127 | -------------------------------------------------------------------------------- /ndic/tests/scripts/test_search.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from unittest import TestCase 3 | 4 | from click.testing import CliRunner 5 | import mock 6 | import requests 7 | 8 | from ndic.scripts.search import cli_search 9 | from ndic.exceptions import NdicConnectionError 10 | 11 | 12 | class NdicScriptTestCase(TestCase): 13 | 14 | def setUp(self): 15 | self.runner = CliRunner() 16 | 17 | def test_search_korean_word(self): 18 | result = self.runner.invoke( 19 | cli_search, 20 | ["사과"], 21 | ) 22 | self.assertEqual( 23 | result.exit_code, 24 | 0, 25 | ) 26 | self.assertEqual( 27 | result.output.replace('\n', ''), 28 | u"(과일) apple", 29 | ) 30 | 31 | def test_search_english_word(self): 32 | result = self.runner.invoke( 33 | cli_search, 34 | ["apple"], 35 | ) 36 | self.assertEqual( 37 | result.exit_code, 38 | 0, 39 | ) 40 | self.assertEqual( 41 | result.output.replace('\n', ''), 42 | u"사과", 43 | ) 44 | 45 | def test_search_nonexistent_korean_word(self): 46 | result = self.runner.invoke( 47 | cli_search, 48 | ["아갸야라"], 49 | ) 50 | self.assertEqual( 51 | result.exit_code, 52 | 0, 53 | ) 54 | self.assertFalse( 55 | result.output.replace('\n', ''), 56 | ) 57 | 58 | def test_search_nonexistent_english_word(self): 59 | result = self.runner.invoke( 60 | cli_search, 61 | ["asfasdfasdf"], 62 | ) 63 | self.assertEqual( 64 | result.exit_code, 65 | 0, 66 | ) 67 | self.assertFalse( 68 | result.output.replace('\n', ''), 69 | ) 70 | 71 | def test_search_korean_word_multiple_meaning(self): 72 | test_corresponding_english_word_1 = u"(언어) word, language, speech, " \ 73 | "(literary) tongue" 74 | test_corresponding_english_word_2 = u"(동물) horse" 75 | test_corresponding_english_word_3 = u"(마지막) end (of), close (of)" 76 | 77 | result1 = self.runner.invoke( 78 | cli_search, 79 | ["말", "-x", "1"], 80 | ) 81 | self.assertEqual( 82 | result1.exit_code, 83 | 0, 84 | ) 85 | self.assertEqual( 86 | result1.output.replace('\n', ''), 87 | test_corresponding_english_word_1, 88 | ) 89 | 90 | result2 = self.runner.invoke( 91 | cli_search, 92 | ["말", "--xth", "2"], 93 | ) 94 | self.assertEqual( 95 | result2.exit_code, 96 | 0, 97 | ) 98 | self.assertEqual( 99 | result2.output.replace('\n', ''), 100 | test_corresponding_english_word_2, 101 | ) 102 | 103 | result3 = self.runner.invoke( 104 | cli_search, 105 | ["말", "-x", "3"], 106 | ) 107 | self.assertEqual( 108 | result3.exit_code, 109 | 0, 110 | ) 111 | self.assertEqual( 112 | result3.output.replace('\n', ''), 113 | test_corresponding_english_word_3, 114 | ) 115 | 116 | def test_search_english_word_multiple_meaning(self): 117 | test_corresponding_korean_word_1 = u"받다" 118 | test_corresponding_korean_word_2 = u"얻다, 입수하다; 가지다(obtain)" 119 | test_corresponding_korean_word_3 = u"(동물의) 새끼; 새끼를 낳음" 120 | 121 | result1 = self.runner.invoke( 122 | cli_search, 123 | ["get", "-x", "1"], 124 | ) 125 | self.assertEqual( 126 | result1.exit_code, 127 | 0, 128 | ) 129 | self.assertEqual( 130 | result1.output.replace('\n', ''), 131 | test_corresponding_korean_word_1, 132 | ) 133 | 134 | result2 = self.runner.invoke( 135 | cli_search, 136 | ["get", "--xth", "2"], 137 | ) 138 | self.assertEqual( 139 | result2.exit_code, 140 | 0, 141 | ) 142 | self.assertEqual( 143 | result2.output.replace('\n', ''), 144 | test_corresponding_korean_word_2, 145 | ) 146 | 147 | result3 = self.runner.invoke( 148 | cli_search, 149 | ["get", "-x", "3"], 150 | ) 151 | self.assertEqual( 152 | result3.exit_code, 153 | 0, 154 | ) 155 | self.assertEqual( 156 | result3.output.replace('\n', ''), 157 | test_corresponding_korean_word_3, 158 | ) 159 | 160 | def test_search_xth_exceed(self): 161 | result = self.runner.invoke( 162 | cli_search, 163 | ["말", "-x", "10"], 164 | ) 165 | self.assertEqual( 166 | result.exit_code, 167 | 0, 168 | ) 169 | self.assertFalse( 170 | result.output.replace('\n', ''), 171 | ) 172 | 173 | def test_search_negative_or_zero_xth(self): 174 | result1 = self.runner.invoke( 175 | cli_search, 176 | ["말", "-x", "0"], 177 | ) 178 | self.assertEqual( 179 | result1.exit_code, 180 | 0, 181 | ) 182 | self.assertFalse( 183 | result1.output.replace('\n', ''), 184 | ) 185 | 186 | result2 = self.runner.invoke( 187 | cli_search, 188 | ["말", "-x", "-1"], 189 | ) 190 | self.assertEqual( 191 | result2.exit_code, 192 | 0, 193 | ) 194 | self.assertFalse( 195 | result2.output.replace('\n', ''), 196 | ) 197 | 198 | @mock.patch.object(requests, 'get', side_effect=requests.ConnectionError) 199 | def test_search_without_internet_network(self, mock_requests): 200 | result = self.runner.invoke( 201 | cli_search, 202 | ["사과"], 203 | ) 204 | self.assertEqual( 205 | result.exit_code, 206 | -1, 207 | ) 208 | self.assertEqual( 209 | result.exception.__class__, 210 | NdicConnectionError, 211 | ) 212 | self.assertEqual( 213 | str(result.exception), 214 | str(NdicConnectionError()), 215 | ) 216 | self.assertEqual( 217 | repr(result.exception), 218 | repr(NdicConnectionError()), 219 | ) 220 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help 18 | help: 19 | @echo "Please use \`make ' where is one of" 20 | @echo " html to make standalone HTML files" 21 | @echo " dirhtml to make HTML files named index.html in directories" 22 | @echo " singlehtml to make a single large HTML file" 23 | @echo " pickle to make pickle files" 24 | @echo " json to make JSON files" 25 | @echo " htmlhelp to make HTML files and a HTML help project" 26 | @echo " qthelp to make HTML files and a qthelp project" 27 | @echo " applehelp to make an Apple Help Book" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " epub3 to make an epub3" 31 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 32 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 33 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 34 | @echo " text to make text files" 35 | @echo " man to make manual pages" 36 | @echo " texinfo to make Texinfo files" 37 | @echo " info to make Texinfo files and run them through makeinfo" 38 | @echo " gettext to make PO message catalogs" 39 | @echo " changes to make an overview of all changed/added/deprecated items" 40 | @echo " xml to make Docutils-native XML files" 41 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 42 | @echo " linkcheck to check all external links for integrity" 43 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 44 | @echo " coverage to run coverage check of the documentation (if enabled)" 45 | @echo " dummy to check syntax errors of document sources" 46 | 47 | .PHONY: clean 48 | clean: 49 | rm -rf $(BUILDDIR)/* 50 | 51 | .PHONY: html 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | .PHONY: dirhtml 58 | dirhtml: 59 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 60 | @echo 61 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 62 | 63 | .PHONY: singlehtml 64 | singlehtml: 65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 66 | @echo 67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 68 | 69 | .PHONY: pickle 70 | pickle: 71 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 72 | @echo 73 | @echo "Build finished; now you can process the pickle files." 74 | 75 | .PHONY: json 76 | json: 77 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 78 | @echo 79 | @echo "Build finished; now you can process the JSON files." 80 | 81 | .PHONY: htmlhelp 82 | htmlhelp: 83 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 84 | @echo 85 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 86 | ".hhp project file in $(BUILDDIR)/htmlhelp." 87 | 88 | .PHONY: qthelp 89 | qthelp: 90 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 91 | @echo 92 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 93 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 94 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ndic.qhcp" 95 | @echo "To view the help file:" 96 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ndic.qhc" 97 | 98 | .PHONY: applehelp 99 | applehelp: 100 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 101 | @echo 102 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 103 | @echo "N.B. You won't be able to view it unless you put it in" \ 104 | "~/Library/Documentation/Help or install it in your application" \ 105 | "bundle." 106 | 107 | .PHONY: devhelp 108 | devhelp: 109 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 110 | @echo 111 | @echo "Build finished." 112 | @echo "To view the help file:" 113 | @echo "# mkdir -p $$HOME/.local/share/devhelp/ndic" 114 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ndic" 115 | @echo "# devhelp" 116 | 117 | .PHONY: epub 118 | epub: 119 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 120 | @echo 121 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 122 | 123 | .PHONY: epub3 124 | epub3: 125 | $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 126 | @echo 127 | @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." 128 | 129 | .PHONY: latex 130 | latex: 131 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 132 | @echo 133 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 134 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 135 | "(use \`make latexpdf' here to do that automatically)." 136 | 137 | .PHONY: latexpdf 138 | latexpdf: 139 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 140 | @echo "Running LaTeX files through pdflatex..." 141 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 142 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 143 | 144 | .PHONY: latexpdfja 145 | latexpdfja: 146 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 147 | @echo "Running LaTeX files through platex and dvipdfmx..." 148 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 149 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 150 | 151 | .PHONY: text 152 | text: 153 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 154 | @echo 155 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 156 | 157 | .PHONY: man 158 | man: 159 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 160 | @echo 161 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 162 | 163 | .PHONY: texinfo 164 | texinfo: 165 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 166 | @echo 167 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 168 | @echo "Run \`make' in that directory to run these through makeinfo" \ 169 | "(use \`make info' here to do that automatically)." 170 | 171 | .PHONY: info 172 | info: 173 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 174 | @echo "Running Texinfo files through makeinfo..." 175 | make -C $(BUILDDIR)/texinfo info 176 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 177 | 178 | .PHONY: gettext 179 | gettext: 180 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 181 | @echo 182 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 183 | 184 | .PHONY: changes 185 | changes: 186 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 187 | @echo 188 | @echo "The overview file is in $(BUILDDIR)/changes." 189 | 190 | .PHONY: linkcheck 191 | linkcheck: 192 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 193 | @echo 194 | @echo "Link check complete; look for any errors in the above output " \ 195 | "or in $(BUILDDIR)/linkcheck/output.txt." 196 | 197 | .PHONY: doctest 198 | doctest: 199 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 200 | @echo "Testing of doctests in the sources finished, look at the " \ 201 | "results in $(BUILDDIR)/doctest/output.txt." 202 | 203 | .PHONY: coverage 204 | coverage: 205 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 206 | @echo "Testing of coverage in the sources finished, look at the " \ 207 | "results in $(BUILDDIR)/coverage/python.txt." 208 | 209 | .PHONY: xml 210 | xml: 211 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 212 | @echo 213 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 214 | 215 | .PHONY: pseudoxml 216 | pseudoxml: 217 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 218 | @echo 219 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 220 | 221 | .PHONY: dummy 222 | dummy: 223 | $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy 224 | @echo 225 | @echo "Build finished. Dummy builder generates no files." 226 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. epub3 to make an epub3 31 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 32 | echo. text to make text files 33 | echo. man to make manual pages 34 | echo. texinfo to make Texinfo files 35 | echo. gettext to make PO message catalogs 36 | echo. changes to make an overview over all changed/added/deprecated items 37 | echo. xml to make Docutils-native XML files 38 | echo. pseudoxml to make pseudoxml-XML files for display purposes 39 | echo. linkcheck to check all external links for integrity 40 | echo. doctest to run all doctests embedded in the documentation if enabled 41 | echo. coverage to run coverage check of the documentation if enabled 42 | echo. dummy to check syntax errors of document sources 43 | goto end 44 | ) 45 | 46 | if "%1" == "clean" ( 47 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 48 | del /q /s %BUILDDIR%\* 49 | goto end 50 | ) 51 | 52 | 53 | REM Check if sphinx-build is available and fallback to Python version if any 54 | %SPHINXBUILD% 1>NUL 2>NUL 55 | if errorlevel 9009 goto sphinx_python 56 | goto sphinx_ok 57 | 58 | :sphinx_python 59 | 60 | set SPHINXBUILD=python -m sphinx.__init__ 61 | %SPHINXBUILD% 2> nul 62 | if errorlevel 9009 ( 63 | echo. 64 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 65 | echo.installed, then set the SPHINXBUILD environment variable to point 66 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 67 | echo.may add the Sphinx directory to PATH. 68 | echo. 69 | echo.If you don't have Sphinx installed, grab it from 70 | echo.http://sphinx-doc.org/ 71 | exit /b 1 72 | ) 73 | 74 | :sphinx_ok 75 | 76 | 77 | if "%1" == "html" ( 78 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 79 | if errorlevel 1 exit /b 1 80 | echo. 81 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 82 | goto end 83 | ) 84 | 85 | if "%1" == "dirhtml" ( 86 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 87 | if errorlevel 1 exit /b 1 88 | echo. 89 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 90 | goto end 91 | ) 92 | 93 | if "%1" == "singlehtml" ( 94 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 95 | if errorlevel 1 exit /b 1 96 | echo. 97 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 98 | goto end 99 | ) 100 | 101 | if "%1" == "pickle" ( 102 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 103 | if errorlevel 1 exit /b 1 104 | echo. 105 | echo.Build finished; now you can process the pickle files. 106 | goto end 107 | ) 108 | 109 | if "%1" == "json" ( 110 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 111 | if errorlevel 1 exit /b 1 112 | echo. 113 | echo.Build finished; now you can process the JSON files. 114 | goto end 115 | ) 116 | 117 | if "%1" == "htmlhelp" ( 118 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 119 | if errorlevel 1 exit /b 1 120 | echo. 121 | echo.Build finished; now you can run HTML Help Workshop with the ^ 122 | .hhp project file in %BUILDDIR%/htmlhelp. 123 | goto end 124 | ) 125 | 126 | if "%1" == "qthelp" ( 127 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 128 | if errorlevel 1 exit /b 1 129 | echo. 130 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 131 | .qhcp project file in %BUILDDIR%/qthelp, like this: 132 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\ndic.qhcp 133 | echo.To view the help file: 134 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\ndic.ghc 135 | goto end 136 | ) 137 | 138 | if "%1" == "devhelp" ( 139 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 140 | if errorlevel 1 exit /b 1 141 | echo. 142 | echo.Build finished. 143 | goto end 144 | ) 145 | 146 | if "%1" == "epub" ( 147 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 148 | if errorlevel 1 exit /b 1 149 | echo. 150 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 151 | goto end 152 | ) 153 | 154 | if "%1" == "epub3" ( 155 | %SPHINXBUILD% -b epub3 %ALLSPHINXOPTS% %BUILDDIR%/epub3 156 | if errorlevel 1 exit /b 1 157 | echo. 158 | echo.Build finished. The epub3 file is in %BUILDDIR%/epub3. 159 | goto end 160 | ) 161 | 162 | if "%1" == "latex" ( 163 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 164 | if errorlevel 1 exit /b 1 165 | echo. 166 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdf" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "latexpdfja" ( 181 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 182 | cd %BUILDDIR%/latex 183 | make all-pdf-ja 184 | cd %~dp0 185 | echo. 186 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 187 | goto end 188 | ) 189 | 190 | if "%1" == "text" ( 191 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 192 | if errorlevel 1 exit /b 1 193 | echo. 194 | echo.Build finished. The text files are in %BUILDDIR%/text. 195 | goto end 196 | ) 197 | 198 | if "%1" == "man" ( 199 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 200 | if errorlevel 1 exit /b 1 201 | echo. 202 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 203 | goto end 204 | ) 205 | 206 | if "%1" == "texinfo" ( 207 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 208 | if errorlevel 1 exit /b 1 209 | echo. 210 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 211 | goto end 212 | ) 213 | 214 | if "%1" == "gettext" ( 215 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 216 | if errorlevel 1 exit /b 1 217 | echo. 218 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 219 | goto end 220 | ) 221 | 222 | if "%1" == "changes" ( 223 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 224 | if errorlevel 1 exit /b 1 225 | echo. 226 | echo.The overview file is in %BUILDDIR%/changes. 227 | goto end 228 | ) 229 | 230 | if "%1" == "linkcheck" ( 231 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 232 | if errorlevel 1 exit /b 1 233 | echo. 234 | echo.Link check complete; look for any errors in the above output ^ 235 | or in %BUILDDIR%/linkcheck/output.txt. 236 | goto end 237 | ) 238 | 239 | if "%1" == "doctest" ( 240 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 241 | if errorlevel 1 exit /b 1 242 | echo. 243 | echo.Testing of doctests in the sources finished, look at the ^ 244 | results in %BUILDDIR%/doctest/output.txt. 245 | goto end 246 | ) 247 | 248 | if "%1" == "coverage" ( 249 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 250 | if errorlevel 1 exit /b 1 251 | echo. 252 | echo.Testing of coverage in the sources finished, look at the ^ 253 | results in %BUILDDIR%/coverage/python.txt. 254 | goto end 255 | ) 256 | 257 | if "%1" == "xml" ( 258 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 259 | if errorlevel 1 exit /b 1 260 | echo. 261 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 262 | goto end 263 | ) 264 | 265 | if "%1" == "pseudoxml" ( 266 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 267 | if errorlevel 1 exit /b 1 268 | echo. 269 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 270 | goto end 271 | ) 272 | 273 | if "%1" == "dummy" ( 274 | %SPHINXBUILD% -b dummy %ALLSPHINXOPTS% %BUILDDIR%/dummy 275 | if errorlevel 1 exit /b 1 276 | echo. 277 | echo.Build finished. Dummy builder generates no files. 278 | goto end 279 | ) 280 | 281 | :end 282 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # ndic documentation build configuration file, created by 5 | # sphinx-quickstart on Fri Sep 2 16:23:42 2016. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | import os 21 | import sys 22 | 23 | from pkg_resources import get_distribution 24 | 25 | 26 | sys.path.insert(0, os.path.abspath('..')) 27 | 28 | # -- General configuration ------------------------------------------------ 29 | 30 | # If your documentation needs a minimal Sphinx version, state it here. 31 | # 32 | # needs_sphinx = '1.0' 33 | 34 | # Add any Sphinx extension module names here, as strings. They can be 35 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 36 | # ones. 37 | extensions = [ 38 | 'sphinx.ext.autodoc', 39 | 'sphinx.ext.doctest', 40 | 'sphinx.ext.intersphinx', 41 | 'sphinx.ext.todo', 42 | 'sphinx.ext.coverage', 43 | 'sphinx.ext.viewcode', 44 | ] 45 | 46 | # Add any paths that contain templates here, relative to this directory. 47 | templates_path = ['_templates'] 48 | 49 | # The suffix(es) of source filenames. 50 | # You can specify multiple suffix as a list of string: 51 | # 52 | # source_suffix = ['.rst', '.md'] 53 | source_suffix = '.rst' 54 | 55 | # The encoding of source files. 56 | # 57 | # source_encoding = 'utf-8-sig' 58 | 59 | # The master toctree document. 60 | master_doc = 'index' 61 | 62 | # General information about the project. 63 | project = 'ndic' 64 | copyright = '2016, jupiny' 65 | author = 'jupiny' 66 | 67 | # The version info for the project you're documenting, acts as replacement for 68 | # |version| and |release|, also used in various other places throughout the 69 | # built documents. 70 | # 71 | # The short X.Y version. 72 | version = get_distribution('ndic').version 73 | # The full version, including alpha/beta/rc tags. 74 | release = version 75 | 76 | # The language for content autogenerated by Sphinx. Refer to documentation 77 | # for a list of supported languages. 78 | # 79 | # This is also used if you do content translation via gettext catalogs. 80 | # Usually you set "language" from the command line for these cases. 81 | language = None 82 | 83 | # There are two options for replacing |today|: either, you set today to some 84 | # non-false value, then it is used: 85 | # 86 | # today = '' 87 | # 88 | # Else, today_fmt is used as the format for a strftime call. 89 | # 90 | # today_fmt = '%B %d, %Y' 91 | 92 | # List of patterns, relative to source directory, that match files and 93 | # directories to ignore when looking for source files. 94 | # This patterns also effect to html_static_path and html_extra_path 95 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 96 | 97 | # The reST default role (used for this markup: `text`) to use for all 98 | # documents. 99 | # 100 | # default_role = None 101 | 102 | # If true, '()' will be appended to :func: etc. cross-reference text. 103 | # 104 | # add_function_parentheses = True 105 | 106 | # If true, the current module name will be prepended to all description 107 | # unit titles (such as .. function::). 108 | # 109 | # add_module_names = True 110 | 111 | # If true, sectionauthor and moduleauthor directives will be shown in the 112 | # output. They are ignored by default. 113 | # 114 | # show_authors = False 115 | 116 | # The name of the Pygments (syntax highlighting) style to use. 117 | pygments_style = 'sphinx' 118 | 119 | # A list of ignored prefixes for module index sorting. 120 | # modindex_common_prefix = [] 121 | 122 | # If true, keep warnings as "system message" paragraphs in the built documents. 123 | # keep_warnings = False 124 | 125 | # If true, `todo` and `todoList` produce output, else they produce nothing. 126 | todo_include_todos = True 127 | 128 | 129 | # -- Options for HTML output ---------------------------------------------- 130 | 131 | # The theme to use for HTML and HTML Help pages. See the documentation for 132 | # a list of builtin themes. 133 | # 134 | # html_theme = 'alabaster' 135 | html_theme = 'default' 136 | 137 | # Theme options are theme-specific and customize the look and feel of a theme 138 | # further. For a list of options available for each theme, see the 139 | # documentation. 140 | # 141 | # html_theme_options = {} 142 | 143 | # Add any paths that contain custom themes here, relative to this directory. 144 | # html_theme_path = [] 145 | 146 | # The name for this set of Sphinx documents. 147 | # " v documentation" by default. 148 | # 149 | # html_title = 'ndic v1.2' 150 | 151 | # A shorter title for the navigation bar. Default is the same as html_title. 152 | # 153 | # html_short_title = None 154 | 155 | # The name of an image file (relative to this directory) to place at the top 156 | # of the sidebar. 157 | # 158 | # html_logo = None 159 | 160 | # The name of an image file (relative to this directory) to use as a favicon of 161 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 162 | # pixels large. 163 | # 164 | # html_favicon = None 165 | 166 | # Add any paths that contain custom static files (such as style sheets) here, 167 | # relative to this directory. They are copied after the builtin static files, 168 | # so a file named "default.css" will overwrite the builtin "default.css". 169 | html_static_path = ['_static'] 170 | 171 | # Add any extra paths that contain custom files (such as robots.txt or 172 | # .htaccess) here, relative to this directory. These files are copied 173 | # directly to the root of the documentation. 174 | # 175 | # html_extra_path = [] 176 | 177 | # If not None, a 'Last updated on:' timestamp is inserted at every page 178 | # bottom, using the given strftime format. 179 | # The empty string is equivalent to '%b %d, %Y'. 180 | # 181 | # html_last_updated_fmt = None 182 | 183 | # If true, SmartyPants will be used to convert quotes and dashes to 184 | # typographically correct entities. 185 | # 186 | # html_use_smartypants = True 187 | 188 | # Custom sidebar templates, maps document names to template names. 189 | # 190 | # html_sidebars = {} 191 | 192 | # Additional templates that should be rendered to pages, maps page names to 193 | # template names. 194 | # 195 | # html_additional_pages = {} 196 | 197 | # If false, no module index is generated. 198 | # 199 | # html_domain_indices = True 200 | 201 | # If false, no index is generated. 202 | # 203 | # html_use_index = True 204 | 205 | # If true, the index is split into individual pages for each letter. 206 | # 207 | # html_split_index = False 208 | 209 | # If true, links to the reST sources are added to the pages. 210 | # 211 | # html_show_sourcelink = True 212 | 213 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 214 | # 215 | # html_show_sphinx = True 216 | 217 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 218 | # 219 | # html_show_copyright = True 220 | 221 | # If true, an OpenSearch description file will be output, and all pages will 222 | # contain a tag referring to it. The value of this option must be the 223 | # base URL from which the finished HTML is served. 224 | # 225 | # html_use_opensearch = '' 226 | 227 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 228 | # html_file_suffix = None 229 | 230 | # Language to be used for generating the HTML full-text search index. 231 | # Sphinx supports the following languages: 232 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 233 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' 234 | # 235 | # html_search_language = 'en' 236 | 237 | # A dictionary with options for the search language support, empty by default. 238 | # 'ja' uses this config value. 239 | # 'zh' user can custom change `jieba` dictionary path. 240 | # 241 | # html_search_options = {'type': 'default'} 242 | 243 | # The name of a javascript file (relative to the configuration directory) that 244 | # implements a search results scorer. If empty, the default will be used. 245 | # 246 | # html_search_scorer = 'scorer.js' 247 | 248 | # Output file base name for HTML help builder. 249 | htmlhelp_basename = 'ndicdoc' 250 | 251 | # -- Options for LaTeX output --------------------------------------------- 252 | 253 | latex_elements = { 254 | # The paper size ('letterpaper' or 'a4paper'). 255 | # 256 | # 'papersize': 'letterpaper', 257 | 258 | # The font size ('10pt', '11pt' or '12pt'). 259 | # 260 | # 'pointsize': '10pt', 261 | 262 | # Additional stuff for the LaTeX preamble. 263 | # 264 | # 'preamble': '', 265 | 266 | # Latex figure (float) alignment 267 | # 268 | # 'figure_align': 'htbp', 269 | } 270 | 271 | # Grouping the document tree into LaTeX files. List of tuples 272 | # (source start file, target name, title, 273 | # author, documentclass [howto, manual, or own class]). 274 | latex_documents = [ 275 | (master_doc, 'ndic.tex', 'ndic Documentation', 276 | 'jupiny', 'manual'), 277 | ] 278 | 279 | # The name of an image file (relative to this directory) to place at the top of 280 | # the title page. 281 | # 282 | # latex_logo = None 283 | 284 | # For "manual" documents, if this is true, then toplevel headings are parts, 285 | # not chapters. 286 | # 287 | # latex_use_parts = False 288 | 289 | # If true, show page references after internal links. 290 | # 291 | # latex_show_pagerefs = False 292 | 293 | # If true, show URL addresses after external links. 294 | # 295 | # latex_show_urls = False 296 | 297 | # Documents to append as an appendix to all manuals. 298 | # 299 | # latex_appendices = [] 300 | 301 | # It false, will not define \strong, \code, itleref, \crossref ... but only 302 | # \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added 303 | # packages. 304 | # 305 | # latex_keep_old_macro_names = True 306 | 307 | # If false, no module index is generated. 308 | # 309 | # latex_domain_indices = True 310 | 311 | 312 | # -- Options for manual page output --------------------------------------- 313 | 314 | # One entry per manual page. List of tuples 315 | # (source start file, name, description, authors, manual section). 316 | man_pages = [ 317 | (master_doc, 'ndic', 'ndic Documentation', 318 | [author], 1) 319 | ] 320 | 321 | # If true, show URL addresses after external links. 322 | # 323 | # man_show_urls = False 324 | 325 | 326 | # -- Options for Texinfo output ------------------------------------------- 327 | 328 | # Grouping the document tree into Texinfo files. List of tuples 329 | # (source start file, target name, title, author, 330 | # dir menu entry, description, category) 331 | texinfo_documents = [ 332 | (master_doc, 'ndic', 'ndic Documentation', 333 | author, 'ndic', 'Python package for NAVER English-Korean and Korean-English dictionaries', 334 | 'Dictionary'), 335 | ] 336 | 337 | # Documents to append as an appendix to all manuals. 338 | # 339 | # texinfo_appendices = [] 340 | 341 | # If false, no module index is generated. 342 | # 343 | # texinfo_domain_indices = True 344 | 345 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 346 | # 347 | # texinfo_show_urls = 'footnote' 348 | 349 | # If true, do not generate a @detailmenu in the "Top" node's menu. 350 | # 351 | # texinfo_no_detailmenu = False 352 | 353 | 354 | # -- Options for Epub output ---------------------------------------------- 355 | 356 | # Bibliographic Dublin Core info. 357 | epub_title = project 358 | epub_author = author 359 | epub_publisher = author 360 | epub_copyright = copyright 361 | 362 | # The basename for the epub file. It defaults to the project name. 363 | # epub_basename = project 364 | 365 | # The HTML theme for the epub output. Since the default themes are not 366 | # optimized for small screen space, using the same theme for HTML and epub 367 | # output is usually not wise. This defaults to 'epub', a theme designed to save 368 | # visual space. 369 | # 370 | # epub_theme = 'epub' 371 | 372 | # The language of the text. It defaults to the language option 373 | # or 'en' if the language is not set. 374 | # 375 | # epub_language = '' 376 | 377 | # The scheme of the identifier. Typical schemes are ISBN or URL. 378 | # epub_scheme = '' 379 | 380 | # The unique identifier of the text. This can be a ISBN number 381 | # or the project homepage. 382 | # 383 | # epub_identifier = '' 384 | 385 | # A unique identification for the text. 386 | # 387 | # epub_uid = '' 388 | 389 | # A tuple containing the cover image and cover page html template filenames. 390 | # 391 | # epub_cover = () 392 | 393 | # A sequence of (type, uri, title) tuples for the guide element of content.opf. 394 | # 395 | # epub_guide = () 396 | 397 | # HTML files that should be inserted before the pages created by sphinx. 398 | # The format is a list of tuples containing the path and title. 399 | # 400 | # epub_pre_files = [] 401 | 402 | # HTML files that should be inserted after the pages created by sphinx. 403 | # The format is a list of tuples containing the path and title. 404 | # 405 | # epub_post_files = [] 406 | 407 | # A list of files that should not be packed into the epub file. 408 | epub_exclude_files = ['search.html'] 409 | 410 | # The depth of the table of contents in toc.ncx. 411 | # 412 | # epub_tocdepth = 3 413 | 414 | # Allow duplicate toc entries. 415 | # 416 | # epub_tocdup = True 417 | 418 | # Choose between 'default' and 'includehidden'. 419 | # 420 | # epub_tocscope = 'default' 421 | 422 | # Fix unsupported image types using the Pillow. 423 | # 424 | # epub_fix_images = False 425 | 426 | # Scale large images. 427 | # 428 | # epub_max_image_width = 0 429 | 430 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 431 | # 432 | # epub_show_urls = 'inline' 433 | 434 | # If false, no index is generated. 435 | # 436 | # epub_use_index = True 437 | 438 | 439 | # Example configuration for intersphinx: refer to the Python standard library. 440 | intersphinx_mapping = {'https://docs.python.org/': None} 441 | --------------------------------------------------------------------------------