Skip to content

Plug in API Subcorpus Restore

Tomas Machalek edited this page Apr 25, 2016 · 1 revision

Plug-ins / [subc_restore]

interface: plugins.abstract.subc_restore.AbstractSubcRestore type: optional

This plug-in is hooked up to subcorpus creation and deletion actions and archives all the necessary arguments to provide additional information in the subcorpus list page or to regenerate subcorpora outside current installation (which is CNC's specific need).

# AbstractSubcRestore.store_query(user_id, corpname, subcname, structname, condition)

Stores user's subcorpus query. Please note that the method should also:

  1. store a current UNIX timestamp
  2. generate and store unique (on its own, i.e. even without user_id) string ID for the record

arguments:

  • user_id -- int, ID of a user
  • corpname -- a name of a corpus
  • subcname -- a name of a subcorpus
  • structname -- name of a structure used to define a subcorpus
  • condition -- a CQL-compatible conjunctive normal form describing required attribute values e.g.: srclang="en" & (txtype="FAC" | txtype="IMA") & txtype_group="fiction"

# AbstractSubcRestore.delete_query(user_id, corpname, subcname)

Removes a query from archive

arguments:

  • user_id -- int, ID of a user
  • corpname -- a name of a corpus
  • subcname -- a name of a subcorpus

# AbstractSubcRestore.list_queries(user_id, from_idx, to_idx)

Lists all user subcorpus-creation queries from index from_idx to index to_idx (including both ends). The method is not expected to support negative indices (like Python does).

arguments:

  • user_id -- int, ID of a user
  • from_idx -- values from 0 to num_of_user_queries - 1
  • to_idx -- values from 0 to num_of_user_queries - 1

returns:

a list/tuple of dicts with following structure:

{
  'id': str,
  'user_id': int,
  'corpname': str,
  'subcname': str,
  'struct_name': str,
  'condition': str,
  'timestamp': int
}

If nothing is found then an empty list/tuple is returned.

# AbstractSubcRestore.get_query(query_id)

Returns a query with ID == query_id

returns:

a dict with the following structure:

{
    'id': str,
    'user_id': int,
    'corpname': str,
    'subcname': str,
    'struct_name': str,
    'condition': str,
    'timestamp': int
}

If nothing is found then None is returned.

Clone this wiki locally