Package: wdp
Introductionwdp (Wiktionary Data Preparer)is a small Python library that can help you get your language
data onto Wiktionary. Formatting Wiktionary entries perfectly can be hard, and it’s wdp’s goal
to take care of the tricky stuff for you.ExampleUsing theWordAPI, enter your data:fromwdpimportWord# use the Word class to represent our wordsapple=Word("apple")apple.add_pronunciation("/ˈæp.əl/",notation="IPA")apple.add_definition("A common, round fruit","Noun")apple.add_definition("A tree of the genus Malus","Noun")apple.set_etymology("Old English æppel < Proto-Germanic *ap(a)laz < PIE *ab(e)l-")pear=Word("pear")# ...# put all our words in a listwdp_words=[apple,pear,...]Use theformat_entriesfunction with your list ofWordobjects to produce Wiktionary markup:fromwdpimportformat_entries# Generate Wiktionary markup from our entriesformatted_entries=format_entries(wdp_words,"en","English")# Produces an entry like the following:"""
==English==

===Etymology===
Old English æppel < Proto-Germanic *ap(a)laz < PIE *ab(e)l-

===Noun===
{{head|en|noun}}

# A common, round fruit
# A tree of the genus Malus
"""Perform the upload:fromwdp.uploadimportupload_formatted_entriesupload_formatted_entries(formatted_entries,"English")ContentsIntroductionExampleInstallationUsagePrerequisitesStep 1: BuildWordObjectsStep 2, option 1 (Recommended): ExportWordObjectsStep 2, option 2 (Advanced): Format and UploadWordObjectsFAQI don’t know Python. Can I still use WDP?I have data inXformat. Will WDP work with it?What should I do if my language doesn’t have a code?Can I update my entries once they’re uploaded?Installation(Note: wdp requiresPython 3.6 or higher. If you do not have a Python installation, we
recommend that you useAnaconda.)pipinstallwdpUsagePrerequisitesTo use wdp, you will need to have your data available in a machine-readable format. The
format does not matter, but you will need to be able to read it and turn it into a list
ofWordobjects.Step 1: BuildWordObjectsAs in the example above, you will need to build a list ofWordobjects. A singleWordobject is defined by its canonical form. It is OK for two or more words to
have the same form–this might happen when two words are homonyms, or when they have
separate etymologies.fromwdpimportWordbank_1=Word("bank")bank_1.add_definition("A place where people keep their money","Noun")bank_2=Word("bank")bank_2.add_definition("The edges of a river","Noun")Methods of theWordclass which begin withadd_can be invoked multiple
times (because e.g. a word can have many definitions), but methods which begin withset_should only be called once (because e.g. you should only have one
etymological note).Consult theWord class’s documentationfor a complete description of its methods.
Currently, the following methods are available:add_definitionadd_alternative_formadd_pronunciationset_etymologyset_descriptionset_referencesset_usage_notesset_conjugationset_declensionset_inflectionFor more information on how to use these methods, see Wiktionary’sentry layout guidelines.Step 2, option 1 (Recommended): ExportWordObjectsOnce you have constructed your list of words, they are ready to be uploaded.
Uploading to Wiktionary is a bit complicated, so we recommend that you export
your data so someone else can upload it. You can do this by using theexport_wordsfunction:fromwdpimportexport_wordsmy_english_words=[bank_1,bank_2]export_words(my_english_words,'my_english_words.zip')Once you’ve done this, please email it to Luke Gessler (lg876@georgetown.edu)
or Aryaman Arora (aa2190@georgetown.edu) so we can help you perform your upload.Step 2, option 2 (Advanced): Format and UploadWordObjectsSection under constructionFirst, you will need tocreate an account on Wiktionary.Next, in your working directory, create auser-config.pyfile with
the following contents:family="wiktionary"mylang="en"usernames["wiktionary"]["en"]=u"Ldgessler"# change to your usernameconsole_encoding="utf-8"minthrottle=0maxthrottle=1In your main Python file, you can now usewdp.upload.upload_formatted_entriesto perform your upload:# load your list of Wordsfromwdp.uploadimportupload_formatted_entriesmy_english_words=[...]# orfromwdpimportimport_wordsmy_english_words=import_words('my_english_words.zip')# format the list of Words into entries# you will need a language code from here:# https://en.wiktionary.org/wiki/Wiktionary:List_of_languagesfromwdpimportformat_entrieslang_code="en"lang_name="English"formatted_entries=format_entries(my_english_words,lang_code,lang_name)# use the page_prefix argument to upload the data to your personal pages# first for debugging, e.g. User:Ldgessler/chafeupload_formatted_entries(formatted_entries,lang_name,page_prefix="User:Ldgessler/")# Once you are CERTAIN your data is correct, you may remove the page_prefix# argument to perform the upload for real:upload_formatted_entries(formatted_entries,lang_name)FAQI don’t know Python. Can I still use WDP?Not on your own, but pleaseopen an issueon our GitHub page explaining what your data looks like, and
someone may be available to help you.I have data inXformat. Will WDP work with it?Yes, WDP is agnostic as to the source format of your data.In the future, we may add support for popular formats (likeFLEx dictionary XML) to allow you to upload from them
without writing any code. If there is a format you’d like us to support, pleaseopen an issue.What should I do if my language doesn’t have a code?A new one can easily be created, but you will need to consult with an expert. Contact Aryaman Arora
(aa2190@georgetown.edu) or a Wiktionary admin.Can I update my entries once they’re uploaded?Not currently, but this is a feature we’d like to support if there’s demand for it. Pleaseopen an issueif you
would like this functionality.