lift_utils.base

Manipulate base linguistic elements.

Module Contents

Classes

Annotation

Provides a mechanism for adding meta-information to almost any element.

Extensible

Used to provide certain extra information in a controlled way.

Field

A generalised element to allow an application to store information.

Flag

An important mechanism for giving type information to an object.

Form

A representation of a string in a particular language and script.

Gloss

A representation of a sense's gloss.

LIFTUtilsBase

This is a base class for all LIFT nodes.

Multitext

Allows for different representations of the same information.

Span

A Unicode string marked with language and formatting information.

Text

Contains textual data mixed with span elements only.

Trait

An important mechanism for giving type information to an object.

URLRef

This is a URL with a caption.

class lift_utils.base.Annotation(name: str = None, value: str = None, who: str = None, when: str = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: Multitext

Provides a mechanism for adding meta-information to almost any element.

XML_TAG = 'annotation'
class lift_utils.base.Extensible(xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: LIFTUtilsBase

Used to provide certain extra information in a controlled way.

Variables:
  • date_created (Optional[DateTime]) – Contains a date/timestamp saying when the element was added to the dictionary.

  • date_modified (Optional[DateTime]) – Contains a date/timestamp saying when the element was last changed.

  • field_items (Optional[List[Field]]) – Holds extra textual information.

  • trait_items (Optional[List[Trait]]) – Adds type or constraint information.

  • annotation (Optional[List[Annotation]]) – Adds meta-information describing the element.

XML_TAG
add_annotation(name=None, value=None, who=None, when=None)
add_field(name=None)
add_trait(name=None, value=None, trait_id=None)
set_date_created()
set_date_modified()
class lift_utils.base.Field(field_type: str = None, name: str = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: Multitext

A generalised element to allow an application to store information. It’s for information in a LIFT file that isn’t explicitly described in the LIFT standard.

XML_TAG = 'field'
class lift_utils.base.Flag(xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: Trait

An important mechanism for giving type information to an object. It can also be use for adding binary constraints.

Note

Used by LIFT v0.13 (FieldWorks). Mentioned in specification but not defined; assumed to be equivalent to Trait.

class lift_utils.base.Form(lang: lift_utils.datatypes.Lang = None, text: Text = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: LIFTUtilsBase

A representation of a string in a particular language and script. This is specified by the lang attribute.

XML_TAG = 'form'
class lift_utils.base.Gloss(lang: str = None, text: str = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: Form

A representation of a sense’s gloss. It’s given in a particular language and script as specified by the lang attribute.

XML_TAG = 'gloss'
set_trait_items(trait_dict)
class lift_utils.base.LIFTUtilsBase(parent_item=None, xml_tree: lxml.etree._Element = None)

This is a base class for all LIFT nodes.

Variables:

xml_tree (etree._Element) – The node’s current data.

XML_PY_NAMES
XML_TAG
print(_format='xml')

Print the node’s data to stdout; as XML by default.

prop_name_from_xml_name(xml_name)

Return the object property name from the given XML attribute or element name.

show()

Print an overview of the object in the terminal window.

class lift_utils.base.Multitext(form_dict: dict = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: Text

Allows for different representations of the same information. It can be in a given language, or in multiple languages.

XML_TAG
get_form_by_lang(lang)

Return first form item with matching lang attribute.

Variables:

lang (str) – Language code; e.g. “en”.

set_form_items(form_dict)
class lift_utils.base.Span(text: str = None, tail: str = None, lang: str = None, href: str = None, span_class: str = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: LIFTUtilsBase

A Unicode string marked with language and formatting information.

XML_TAG = 'span'
class lift_utils.base.Text(text: str = None, xml_tree: lxml.etree._Element | None = None, subinit=False, **kwargs)

Bases: LIFTUtilsBase

Contains textual data mixed with span elements only.

XML_TAG = 'text'
class lift_utils.base.Trait(name: str = None, value: str = None, trait_id: str = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: LIFTUtilsBase

An important mechanism for giving type information to an object. It can also be used for adding binary constraints.

XML_TAG = 'trait'
class lift_utils.base.URLRef(href: str = None, label: dict = None, xml_tree: lxml.etree._Element | None = None, **kwargs)

Bases: LIFTUtilsBase

This is a URL with a caption.

XML_TAG = 'urlref'
set_label(label_dict)