annotations Module

annotations Module

Defines objects to create and manipulate raw annotations.

class pyanno.annotations.AnnotationsContainer[source]

Bases: traits.has_traits.HasStrictTraits

Translate from general annotations files and arrays to pyAnno’s format.

This class exposes a few methods to import data from files and arrays, and converts them to pyAnno’s format:

  • annotations are 2D integer arrays; rows index items, and columns annotators
  • label classes are numbered 0 to nclasses-1 . The attribute labels defines a mapping from label tokens to label classes
  • missing values are defined as pyanno.util.MISSING_VALUE. The attribute missing_values contains the missing values tokens found in the original, raw data

The converted data can be accessed through the annotations property.

The AnnotationsContainer is also used as the format to store annotations in PyannoDatabase objects.

static from_array(x, missing_values=None, name='')[source]

Create an annotations object from an array or list-of-lists.

Parameters:
  • x (ndarray or list-of-lists) – Array or list-of-lists containing numerical or string annotations
  • missing_values (list) – List of values that are considered missing values. Default is DEFAULT_MISSING_VALUES_ALL
  • name (string) – Name of the annotations (for user interaction and used as key in databases).
static from_file(filename, missing_values=None)[source]

Load annotations from a file.

The file is a text file with a columns separated by spaces and/or commas, and rows on different lines.

Parameters:
  • filename (string) – File name
  • missing_values (list) – List of labels that are considered missing values. Default is DEFAULT_MISSING_VALUES_STR
save_to(filename, set_name=False)[source]

Save raw annotations to file.

Parameters:
  • filename (string) – File name
  • set_name (bool) – Set the name of the annotation container to the file name
DEFAULT_MISSING_VALUES_ALL = ['-1', 'NA', 'None', '*', -1, nan, None]
DEFAULT_MISSING_VALUES_NUM = [-1, nan, None]
DEFAULT_MISSING_VALUES_STR = ['-1', 'NA', 'None', '*']
annotations = None

annotations in pyAnno format

labels = None

list of all labels found in file/array

missing_values = None

labels corresponding to a missing value

name = None

name of file or array from which the annotations were imported

nannotators = None

number of annotators

nclasses = None

number of classes found in the annotations

nitems = None

number of annotations

raw_annotations = None

raw annotations, as they are imported from file or array

pyanno.annotations.load_annotations(filename, missing_values=None)[source]

Load annotations from file.

The file is a text file with a columns separated by spaces and/or commas, and rows on different lines.

Parameters:
  • filename (string) – File name
  • missing_values (list) – List of labels that are considered missing values. Default is DEFAULT_MISSING_VALUES_STR

Table Of Contents

Previous topic

models Module

Next topic

measures Package

This Page