kazu.annotation.label_studio

Classes

class kazu.annotation.label_studio.KazuToLabelStudioConverter[source]

Bases: object

Converts a Kazu Document into Label Studio tasks.

Since LS is region based, we need to create a new region for every CharSpan (even overlapping ones), and add entity information (class, mappings etc) to the region.

classmethod convert_docs_to_tasks(docs)[source]
Parameters:

docs (list[Document])

Return type:

list[dict]

classmethod convert_multiple_docs_to_tasks(docs)[source]

If you want to utilise multiple annotation views in label studio, you can supply an iterable of sets of kazu documents annotated by different pipelines. The entity information from each will be added to an independent annotation set in label studio.

index 0 of the sublist is assumed to be ground truth.

Parameters:

docs (Iterable[list[Document]])

Returns:

Return type:

Iterable[dict]

classmethod convert_single_doc_to_tasks(doc, ground_truth)[source]
Parameters:
Return type:

Iterable[dict]

class kazu.annotation.label_studio.LSToKazuConversion[source]

Bases: object

__init__(task)[source]
Parameters:

task (dict)

classmethod convert_tasks_to_docs(tasks)[source]
Parameters:

tasks (list[dict])

Return type:

list[Document]

create_ents()[source]
Return type:

list[Entity]

create_mappings(taxonomy_hits, task_id)[source]
Parameters:
Return type:

list[Mapping]

create_section()[source]
Return type:

Section

class kazu.annotation.label_studio.LabelStudioAnnotationView[source]

Bases: object

__init__(ner_labels)[source]
Parameters:

ner_labels (dict[str, str]) – a mapping of ner label (i.e. Entity.entity_class) to a valid colour

build_labels(dom, element)[source]
Parameters:
Return type:

None

static build_taxonomy(dom, element, tasks, name)[source]
Parameters:
Return type:

None

create_main_view(tasks)[source]
Parameters:

tasks (list[dict])

Return type:

str

static getDOM()[source]
Return type:

xml.dom.minidom.Document

static with_default_colours()[source]
Return type:

LabelStudioAnnotationView

class kazu.annotation.label_studio.LabelStudioManager[source]

Bases: object

__init__(project_name, headers, url='http://localhost:8080', server_connect_timeout=3.05)[source]
Parameters:
create_linking_project()[source]
Return type:

None

delete_project_if_exists()[source]
Return type:

None

export_from_ls()[source]
Return type:

list[Document]

get_all_tasks()[source]
Return type:

list[dict[str, Any]]

get_tasks(ids)[source]
Parameters:

ids (list[int])

Return type:

list[dict[str, Any]]

update_tasks(docs: list[Document]) None[source]
update_tasks(docs: list[list[Document]]) None

Add tasks to a label studio project.

Parameters:

docs – either a list of kazu documents, or a list of a set of kazu documents. If using the latter, each document in the set should be identical, apart from the entity information. Each documents entity information will form a seperate annotation set in label studio.

Returns:

update_view(view: LabelStudioAnnotationView, docs: list[Document]) None[source]
update_view(view: LabelStudioAnnotationView, docs: list[list[Document]]) None

Update the view of a label studio project.

Parameters:
  • view

  • docs – either a list of kazu documents, or a list of a set of kazu documents. If using the latter, each document in the set should be identical, apart from the entity information. Each documents entity information will form a seperate annotation set in label studio.

Returns:

property project_id: int