wdp package

Submodules

wdp.const module

wdp.format module

wdp.format.format_entries(words: List[wdp.models.Word], lang_code: str, lang_name: str) → List[Tuple[str, str]][source]
wdp.format.format_entry(word_group: List[wdp.models.Word], lang_code: str, lang_name: str) → Tuple[str, str][source]

Turn a list of Word objects into Wikitext.

wdp.format.group_definitions_by_pos(context: dict)[source]

Return a dict mapping from part of speech to a list of all the definitions with that part of speech.

wdp.format.group_words(words: List[wdp.models.Word]) → List[List[wdp.models.Word]][source]

Group words based on their word_form attribute

wdp.models module

TODO

class wdp.models.AlternativeForm(alternative_form: str, description_of_use: Optional[str] = None)[source]

Bases: wdp.models._DefaultReprMixin, wdp.models._ToDictMixin

class wdp.models.Definition(definition: str, part_of_speech: str, usage_examples: Optional[list] = None)[source]

Bases: wdp.models._DefaultReprMixin, wdp.models._ToDictMixin

class wdp.models.Pronunciation(pronunciation: str, notation: Optional[str] = None, accent: Optional[str] = None)[source]

Bases: wdp.models._DefaultReprMixin, wdp.models._ToDictMixin

class wdp.models.UsageExample(text: str, translation: str)[source]

Bases: wdp.models._DefaultReprMixin, wdp.models._ToDictMixin

class wdp.models.Word(word_form)[source]

Bases: wdp.models._DefaultReprMixin, wdp.models._ToDictMixin

An object that represents a single “word”. If two or more Word objects have the same word_form attribute, their information will appear under separate headings “Etymology 1”, “Etymology 2”, etc. (see for instance: https://en.wiktionary.org/wiki/graft#English).

Information is added to the object by using the methods beginning with add_ and set_. String arguments of these methods may contain wikitext markup in case you want to use it to e.g. link to other entries using the [[square bracket]] notation. For more information, see: https://en.wikipedia.org/wiki/Help:Wikitext

add_alternative_form(alternative_form: str, description_of_use: Optional[str] = None)[source]

Add an alternative representation of this word in case there are e.g. variant spellings or different orthographies. This is NOT for IPA or other kinds of pronunciation guides– use add_pronunciation for that instead.

Parameters
  • alternative_form – a string with the alternative representation of the word

  • description_of_use – e.g. “Chiefly British”, “Romaji”, “Cyrillic”

Examples

>>> w = Word('color')
>>> w.add_alternative_form('colour', description_of_use='Chiefly British')
add_definition(definition: str, part_of_speech: str, usage_examples: Optional[Iterable[Tuple[str, str]]] = None)[source]

Add a definition of this word. A valid part of speech or other lexical categorization is required. Part of speech should come from a list of approved parts of speech on Wiktionary if possible: https://en.wiktionary.org/wiki/Wiktionary:Entry_layout#Part_of_speech

Parameters
  • definition – Freetext explaining one meaning of the word.

  • part_of_speech – a lexical categorization of the word that this definition occurs with

  • usage_examples – a list of pairs of strings, where the first is the example, and the second is its translation

Examples

>>> w = Word('cibum')
>>> w.add_definition('food', 'noun', usage_examples=[('canis cibum edebat.', 'The dog was eating.')])
add_pronunciation(pronunciation: str, notation: Optional[str] = None, accent: Optional[str] = None)[source]

Add a representation of the word that indicates its pronunciation. For IPA, you MUST surround it with either [square brackets] or /forward slashes/ to indicate whether it is phonemic or phonetic and you MUST set notation to “IPA”

Parameters
  • pronunciation – a string that represents the word’s pronunciation

  • notation – a short description of the notation the pronunciation is given in. Use “IPA” if in IPA.

  • accent – a description of the accent/regional variety/dialect of this pronunciation, if applicable

Examples

>>> w = Word('bird')
>>> w.add_pronunciation("/bɝd/", "IPA", "General American")
>>> w.add_pronunciation("/bɜːd/", "IPA", "Received Pronunciation")
>>> w.add_pronunciation("[bɜɪd]", "IPA", "NYC")
set_conjugation(conjugation: str)[source]

Provide conjugational information for the word. Only use this for verbs–see set_declension for nouns and set_inflection for all other lexical classes.

Parameters

conjugation – Freetext describing the verb’s conjugation.

set_declension(declension: str)[source]

Provide declensional information for the word. Only use this for nouns–see set_conjugation for verbs and set_inflection for all other lexical classes.

Parameters

declension – Freetext describing the noun’s declension.

set_description(description: str)[source]

Provide a description for the word. Used mostly for symbols. See: https://en.wiktionary.org/wiki/Wiktionary:Entry_layout#Description

Parameters

description – Freetext describing the word.

Examples

>>> w = Word('⌛')
>>> w.set_description('An hourglass.')
set_etymology(etymology: str)[source]

Provide an etymological note for the word.

Parameters

etymology – Freetext explaining the word’s etymology.

Examples

>>> w = Word('werewolf')
>>> w.set_etymology('from wer "man, male person" + wulf "wolf"')
set_inflection(inflection: str)[source]

Provide inflecitonal information for the word. Only use this if the word is not a noun or a verb. For nouns, see set_declension, and for verbs, see set_inflection.

Parameters

inflection – Freetext describing the word’s inflection.

set_references(references: str)[source]

Provide references for the information in this Word.

Parameters

references – Freetext containing references.

Examples

>>> w = Word('गुरु')
>>> w.add_definition('master, teacher', 'noun')
>>> w.set_references("* [https://en.wikipedia.org/wiki/R._S._McGregor McGregor, Ronald Stewart] (1993) "गुरु", in ''The Oxford Hindi-English Dictionary'', London: Oxford University Press")
set_usage_notes(usage_notes: str)[source]

Provide notes on how the word is used with respect to e.g. formality and other social dimensions.

Parameters

usage_notes – Freetext containing a usage note.

Examples

>>> w = Word('hacker')
>>> w.set_usage_notes("* There are significantly more meanings of the word within the United States than in other English speaking nations.")
wdp.models.export_words(words: List[wdp.models.Word], filepath: str)[source]

Export a list of words to a .zip file for sharing with someone who can upload the data to Wiktionary.

Parameters
  • words – A list of Word objects that have had their information filled out.

  • filepath – A location to write the export .zip file to.

wdp.models.import_words(filepath: str) → List[wdp.models.Word][source]

Read a list of Word objects from a file produced by export_words.

Parameters

filepath – Location of the zip

wdp.upload module

wdp.upload.upload_formatted_entries(formatted_entries: List[Tuple[str, str]], lang_name: str, wiktionary_language: str = 'en', page_prefix: str = '')[source]

wdp.validate module

exception wdp.validate.WordValidationException[source]

Bases: BaseException

wdp.validate.test(f)[source]
wdp.validate.validate_word(word: wdp.models.Word)[source]
wdp.validate.validate_words(words: List[wdp.models.Word], lang_code: str, lang_name: str)[source]

Module contents