Package: ctext
ctext is a simple Python wrapper and set of helper functions for theCTP API, which fetches data from theChinese Text Projectdatabase, a digital library of pre-modern Chinese literature. Developed for Python 3; Python 2 is supported since version 0.263.Development statusThis software is currently experimental. Seehttp://ctext.org/tools/apifor API details.Installationpip install ctextUsageTextual items are identified byCTP URNs. Each URN identifies a text or part of a text. You can get these manually by visiting thehttp://ctext.orgwebsite (bottom-right of each page), or programmatically using thesearchtexts()function. To use this library, first:from ctext import *Some API functions (like getting the full structure of a text, or downloading a lot of data) may require an API key. If you have one, before calling any other functions, do this:setapikey("your-api-key-goes-here")You can also set the interface language (“en” for English, “zh” for Chinese):setlanguage("zh")Similarly, automatic remapping to simplified Chinese can be done with:setremap("gb")getstatsstats = getstats()Simple wrapper around thegetstats API call.getstatusstatus = getstatus()Simple wrapper around thegetstatus API call.gettexttitlestitles = gettexttitles()Simple wrapper around thegettexttitles API call.getcapabilitiescapabilities = getcapabilities()Simple wrapper around thegetcapabilities API call.readlinkurn = readlink("http://ctext.org/mengzi")Simple wrapper around thereadlink API call.gettextpassages = gettext("ctp:analects/xue-er")Simple wrapper around thegettext API call. Note that the API gettext function needs to be called recursively to get the full text of an entire book; the Python helper functionsgettextasparagraphlist,gettextasstring, andgettextasobjectcall gettext repeatedly to extract all corresponding textual data.gettextaschapterlistchapters = gettextaschapterlist("ctp:analects")Returns the full text of the requested URN as an object simple list of strings, each corresponding to one chapter of text. Titles are omitted.gettextasobjectdata = gettextasobject("ctp:analects/xue-er")Returns the full text of the requested URN as an object with a nested structure representing what eachgettextAPI call returns.gettextasparagraphlistpassages = gettextasparagraphlist("ctp:analects/xue-er")Returns the full text of the requested URN as a simple list of strings, each corresponding to one passage of text. Titles are omitted.gettextasstringstring = gettextasstring("ctp:analects/xue-er")Returns the full text of the requested URN as a single string. Each paragraph is separated with “\n\n”.gettextinfodata = gettextinfo("ctp:analects")Simple wrapper around thegettextinfo API call.searchtextsdata = searchtexts("論語")Simple wrapper around thesearchtexts API call.setapikeysetapikey("your-api-key-goes-here")This sets an API key which is then supplied to the CTP API with all subsequent API requests.setlanguagesetlanguage("zh")This sets the “if” (interface language) parameter, which is then supplied to the CTP API with all subsequent API requests.setremapsetremap("gb")This sets the “remap” (character remapping) parameter, which is then supplied to the CTP API with all subsequent API requests. Currently the only valid value is “gb”, which returns data in simplified Chinese.LicenseCopyright 2016 Donald Sturgeon. This code is licensed under the MIT License:http://opensource.org/licenses/mit-license.html