Skip to content

Layer

linpipe.Layer

Bases: object

A base class of all LinPipe layers.

A layer holds one kind of annotation of a document, for example its plain text. Its data can be accessed through views, created by Layer.create_view.

create staticmethod

create(type: str, name: str = '') -> Layer

Create a new layer of the given type.

Parameters:

  • type (str) –

    the type of the layer to create, e.g., plain_text.

  • name (str, default: '' ) –

    the name of the layer; the layer type is used when empty.

Returns:

  • Layer –

    a new layer of the given type.

create_from_json staticmethod

create_from_json(json: str) -> Layer

Create a new layer from its JSON representation.

Parameters:

  • json (str) –

    the JSON representation of the layer, as produced by Layer.to_json.

Returns:

  • Layer –

    a new layer described by the given JSON.

create_view

create_view(selectors: str) -> View

Create a view of the layer matching the given selectors.

The view refers to the layer, so the layer must outlive it.

Parameters:

  • selectors (str) –

    colon-separated key=value or value selectors, where a missing key means type; a literal colon is written as ::.

Returns:

  • View –

    the unique view of the layer matching all the selectors.

type

type() -> str

Return the type of the layer.

Returns:

  • str –

    the layer type, e.g., plain_text.

name instance-attribute

name: str

The name of the layer.

model instance-attribute

model: str

The model which created the layer, if any.

license instance-attribute

license: str

The license of the layer data, if any.

timestamp instance-attribute

timestamp: str

The creation time of the layer as an ISO 8601 date-time in UTC, e.g., 2026-01-01T12:00:00Z.

matches

matches(selectors: str) -> bool

Check whether the layer matches the given selectors.

Parameters:

  • selectors (str) –

    colon-separated key=value or value selectors, where a missing key means type; a literal colon is written as ::.

Returns:

  • bool –

    whether the layer matches all the selectors.

to_json

to_json(indent: int = -1) -> str

Format the layer as JSON.

Parameters:

  • indent (int, default: -1 ) –

    the number of spaces to indent the JSON with; a compact single-line JSON is produced when negative.

Returns:

  • str –

    the JSON representation of the layer.

to_html

to_html() -> str

Format the layer as HTML.

Returns:

  • str –

    an HTML representation of the layer.