clams.app package
Module contents
-
class
clams.app.
ClamsApp
[source] Bases:
abc.ABC
An abstract class to define API’s for ClamsApps. A CLAMS app should inherit this class and then can be used with classes in
restify
to work as web applications.-
abstract
_annotate
(mmif: Union[str, dict, mmif.serialize.mmif.Mmif], **runtime_params) → mmif.serialize.mmif.Mmif[source] An abstract method to generate (or load if stored elsewhere) the app metadata at runtime. All CLAMS app must implement this.
- Parameters
mmif – An input MMIF object to annotate
runtime_params – An arbitrary set of k-v pairs to configure the app at runtime
- Returns
A
Mmif
object of the annotated output, ready for serialization
-
abstract
_appmetadata
() → clams.appmetadata.AppMetadata[source] An abstract method to generate (or load if stored elsewhere) the app metadata at runtime. All CLAMS app must implement this. For metadata specification, see https://sdk.clams.ai/appmetadata.jsonschema.
- Returns
A Python object of the metadata, must be JSON-serializable
-
annotate
(mmif: Union[str, dict, mmif.serialize.mmif.Mmif], **runtime_params) → str[source] A public method to invoke the primary app function. It’s essentially a wrapper around
_annotate()
method where some common operations (that are invoked by keyword arguments) are implemented.- Parameters
mmif – An input MMIF object to annotate
runtime_params – An arbitrary set of k-v pairs to configure the app at runtime
- Returns
Serialized JSON string of the output of the app
-
appmetadata
(**kwargs) → str[source] A public method to get metadata for this app as a string.
- Returns
Serialized JSON string of the metadata
-
static
open_document_location
(document: Union[str, mmif.serialize.annotation.Document], opener: Any = <built-in function open>, **openerargs)[source] A context-providing file opener. A user can provide their own opener class/method and parameters. By default, with will use python built-in open to open the location of the document.
-
record_error
(mmif: Union[str, dict, mmif.serialize.mmif.Mmif], runtime_conf: Optional[dict] = None) → mmif.serialize.mmif.Mmif[source] A method to record an error instead of annotation results in the view this app generated. For logging purpose, the runtime parameters used when the error occurred must be passed as well.
- Parameters
mmif – input MMIF object
runtime_conf – parameters passed to annotate when the app encountered the error
- Returns
An output MMIF with a new view with the error encoded in the view metadata
-
set_error_view
(mmif: Union[str, dict, mmif.serialize.mmif.Mmif], runtime_conf: Optional[dict] = None) → mmif.serialize.mmif.Mmif[source] A method to record an error instead of annotation results in the view this app generated. For logging purpose, the runtime parameters used when the error occurred must be passed as well.
- Parameters
mmif – input MMIF object
runtime_conf – parameters passed to annotate when the app encountered the error
- Returns
An output MMIF with a new view with the error encoded in the view metadata
-
sign_view
(view: mmif.serialize.view.View, runtime_conf: Optional[dict] = None) → None[source] A method to “sign” a new view that this app creates at the beginning of annotation. Signing will populate the view metadata with information and configuration of this app. The parameters passed to the
_annotate()
must be passed to this method. This means all parameters for “common” configuration that are consumed inannotate()
should not be recorded in the view metadata. :param view: a view to sign :param runtime_conf: runtime configuration of the app as k-v pairs
-
static
validate_document_locations
(mmif: Union[str, mmif.serialize.mmif.Mmif]) → None[source] Validate files encoded in the input MMIF.
- Parameters
mmif – An input MMIF with zero or more
Document
- Raises
FileNotFoundError – When any of files is not found at its location
-
abstract