Giter Club home page Giter Club logo

wiktionary-lookup's Introduction

wiktionary lookup

[Notice] This repository was deprecated, please use wikt2pron instead.

Build Status Coverage Status BSD licensed

A Python toolkit which looks up given words in Wiktionary and returns structured Python dict format. Support the following list at present,

  • languages
  • parts of speech
  • pronunciations (IPA, CMUBET, enPR, audio link)

Requirements

Written in pure Python, compatible with Python 2.6+ and 3.2+, no dependencies.

Installation

# download the latest version
$ git clone https://github.com/abuccts/wiktionary-lookup.git
$ cd wiktionary-lookup

# install and run test
$ python setup.py install
$ python setup.py -q test

Usage

First, create an instance of Wiktionary class:

>>> from pywiktionary import Wiktionary
>>> wikidict = Wiktionary(lang="English", CMUBET=True, phoneme_only=False)

Lookup a word using lookup method:

>>> word = wikidict.lookup("read")

The entry of word "read" is at https://en.wiktionary.org/wiki/read#English, and here is the lookup result:

>>> from pprint import pprint
>>> pprint(word)
{'English': {'Part of Speech': ['Verb', 'Noun'],
             'Pronunciation': [{'CMUBET': ['R IY D .'],
                                'IPA': (['/ɹiːd/'], 'en'),
                                'enPR': 'rēd'},
                               {'Audio': ('En-uk-to read.ogg',
                                          'Audio (UK)',
                                          'en')},
                               {'Audio': ('en-us-read.ogg',
                                          'Audio (US)',
                                          'en')},
                               {'CMUBET': ['R EH D .'],
                                'IPA': (['/ɹɛd/'], 'en'),
                                'enPR': 'rĕd'},
                               {'Audio': ('en-us-read-past.ogg',
                                          'Audio (US)',
                                          'en')}]}}

To lookup a word in a different language, specify the lang parameter (CMUBET parameter is only available for lang="English" at present):

>>> word = wikidict.lookup("читать", lang="Russian")
>>> pprint(word)
{'Russian': {'Part of Speech': ['Verb'],
             'Pronunciation': [{'IPA': (['[t͡ɕɪˈtatʲ]'], 'ru')},
                               {'Audio': ('Ru-читать.ogg', 'Audio', 'ru')}]}}

Please note that the default language of wikidict is "English" which is set when the instance is created. To change the language of wikidict permanently, create another instance of Wiktionary class or use set_lang function:

>>> wikidict.set_lang("French")
>>> word = wikidict.lookup("être")
>>> pprint(word)
{'French': {'Part of Speech': ['Verb', 'Noun'],
            'Pronunciation': [{'IPA': (['/ɛtʁ/'], 'fr')},
                              {'Audio': ('Fr-être-fr-ouest.ogg',
                                         'Audio (France, West)',
                                         'fr')},
                              {'Accent': 'Quebec', 'IPA': (['[aɛ̯tʁ]'], 'fr')},
                              {'Audio': ('Qc-être.ogg',
                                         'Audio (Quebec, Montreal)',
                                         'fr')},
                              {'Accent': 'Louisiana',
                               'IPA': (['[ɛt(ɾ)]'], 'fr')}]}}

For phoneme only output without other information, set phoneme_only parameter to True:

>>> word_phoneme = wikidict.lookup("être", phoneme_only=True)
>>> pprint(word_phoneme)
{'IPA': ['/ɛtʁ/', '[aɛ̯tʁ]', '[ɛt(ɾ)]']}

More exmaples of different languages can be found at Example Index Wiki Page.

For command line interface, please refer to Command Line Usage Wiki Page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.