cjklib.dictionary.install — Install dictionaries

New in version 0.3.

Installs dictionaries at runtime.

Example:

  • Download and update a dictionary (here CFDICT):

    >>> from cjklib.dbconnector import getDBConnector
    >>> db = getDBConnector({'sqlalchemy.url': 'sqlite://','attach': ['cjklib']})
    >>> from cjklib.dictionary.install import DictionaryInstaller
    >>> installer = DictionaryInstaller()
    >>> installer.install('CFDICT', dbConnectInst=db)
    >>> from cjklib.dictionary import CFDICT
    >>> CFDICT(dbConnectInst=db).getFor(u'朋友')
    [EntryTuple(HeadwordTraditional=u'朋友',HeadwordSimplified=u'朋友', Reading=u'péng you',Translation=u'/ami (n.v.) (n)/')]
    

See also

installcjkdict — Install dictionaries
Documentation on the CLI

Functions

cjklib.dictionary.install.getDownloader(dictionaryName, **options)

Get a dictionary downloader instance by dictionary name.

Parameter:dictionaryName (str) – dictionary name
Return type:type
Returns:downloader instance
cjklib.dictionary.install.getDownloaderClass(dictionaryName)

Get a dictionary downloader class by dictionary name.

Parameter:dictionaryName (str) – dictionary name
Return type:type
Returns:downloader class
cjklib.dictionary.install.getDownloaderClasses()

Gets all classes in module that implement DownloaderBase.

Return type:set
Returns:list of all classes inheriting form DownloaderBase

Classes

class cjklib.dictionary.install.CEDICTDownloader(downloadFunc=None, quiet=True)

Bases: cjklib.dictionary.install.PageDownloaderBase

Downloader for the CEDICT dictionary.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

getDownloadPage(*args, **kwargs)
getVersion(*args, **kwargs)
class cjklib.dictionary.install.CEDICTGRDownloader(downloadFunc=None, quiet=True)

Bases: cjklib.dictionary.install.DownloaderBase

Downloader for the Gwoyeu Romatzyh version of the CEDICT dictionary.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

getVersion(*args, **kwargs)
Version of the online available dictionary.
class cjklib.dictionary.install.CFDICTDownloader(downloadFunc=None, quiet=True)

Bases: cjklib.dictionary.install.PageDownloaderBase

Downloader for the CFDICT dictionary.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

getDownloadPage(*args, **kwargs)
getVersion(*args, **kwargs)
class cjklib.dictionary.install.CommandLineInstaller

Bases: object

Command line dictionary installer.

buildParser()
classmethod getBuilderConfigSettings()

Gets the builder settings from the section Builder from cjklib.conf.

Return type:dict
Returns:dictionary of builder options

Todo

classmethod getDefaultOptions()
run()
Runs the builder
class cjklib.dictionary.install.DictionaryInstaller(quiet=True)

Bases: object

Dictionary installer for downloading and installing a dictionary to a SQL database.

classmethod getDefaultDatabaseUrl(dictionaryName, prefix=None, local=False, projectName='cjklib')
install(dictionaryName, **options)

Installs the given dictionary to a database.

Different installation methods are possible:

  • by default a global installation is done, a single database file

    if installed for SQLite, for other engines the database is installed to the same database as cjklib’s,

  • if local is set, the database file for SQLite is installed to

    the user’s home directory,

  • databaseUrl can be speficied for a user defined database,

  • dbConnectInst can be given to write to an open database

    instance.

Parameters:
  • options – extra options
  • databaseUrl – database connection setting in the format driver://user:pass@host/database.
  • dbConnectInst – instance of a DatabaseConnector
  • local – if True the SQLite file will be installed in the user’s home directory.
  • prefix – installation prefix for a global install (Unix only).
  • forceUpdate – dictionary will be installed even if a newer version already exists
  • quiet – if True no status information will be printed to stdout
class cjklib.dictionary.install.DownloaderBase(downloadFunc=None, quiet=True)

Bases: object

Abstract class for downloading dictionaries.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

Gets the download link for the online dictionary.

Needs to be implemented by subclasses.

getVersion(*args, **kwargs)
Version of the online available dictionary.
class cjklib.dictionary.install.EDICTDownloader(downloadFunc=None, quiet=True)

Bases: cjklib.dictionary.install.DownloaderBase

Downloader for the EDICT dictionary.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

getVersion(*args, **kwargs)
Version of the online available dictionary.
class cjklib.dictionary.install.HanDeDictDownloader(downloadFunc=None, quiet=True)

Bases: cjklib.dictionary.install.PageDownloaderBase

Downloader for the HanDeDict dictionary.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

getDownloadPage(*args, **kwargs)
getVersion(*args, **kwargs)
class cjklib.dictionary.install.PageDownloaderBase(downloadFunc=None, quiet=True)

Bases: cjklib.dictionary.install.DownloaderBase

Abstract class for downloading dictionaries by scraping the URL from a web page.

download(**options)

Downloads the dictionary and returns the path to the local file.

Parameters:
  • options – extra options
  • targetName – target file name for downloaded file
  • targetPath – target directory for downloaded file, file name will be used as provided online
  • temporary – if True a temporary file will be created retaining the last extension (i.e. for .tar.gz only .gz will be guaranteed.
Return type:

str

Returns:

path to local file

getDownloadPage(*args, **kwargs)
getVersion(*args, **kwargs)