medkit.text.ner.date_attribute#

Classes:

DateAttribute(label[, year, month, day, ...])

Attribute representing an absolute date or time associated to a segment or entity.

DurationAttribute(label[, years, months, ...])

Attribute representing a time quantity associated to a segment or entity.

RelativeDateAttribute(label, direction[, ...])

Attribute representing a relative date or time associated to a segment or entity, ie a date/time offset from an (unknown) reference date/time, with a direction.

RelativeDateDirection(value)

Direction of a RelativeDateAttribute

class DateAttribute(label, year=None, month=None, day=None, hour=None, minute=None, second=None, metadata=None, uid=None)[source]#

Attribute representing an absolute date or time associated to a segment or entity.

The date or time can be incomplete: each date/time component is optional but at least one must be provided.

Variables
  • uid (str) – Identifier of the attribute

  • label (str) – Label of the attribute

  • value (Optional[Any]) – String representation of the date with YYYY-MM-DD format for the date part and HH:MM:SS for the time part, if present. Missing components are replaced with question marks.

  • year (Optional[int]) – Year component of the date

  • month (Optional[int]) – Month component of the date

  • day (Optional[int]) – Day component of the date

  • hour (Optional[int]) – Hour component of the time

  • minute (Optional[int]) – Minute component of the time

  • second (Optional[int]) – Second component of the time

  • metadata (Dict[str, Any]) – Metadata of the attribute

Methods:

copy()

Create a new attribute that is a copy of the current instance, but with a new identifier

from_dict(date_dict)

Creates an Attribute from a dict

get_subclass_for_data_dict(data_dict)

Return the subclass that corresponds to the class name found in a data dict

to_brat()

Return a value compatible with the brat format

to_spacy()

Return a value compatible with spaCy

to_brat()[source]#

Return a value compatible with the brat format

Return type

str

to_spacy()[source]#

Return a value compatible with spaCy

Return type

str

classmethod from_dict(date_dict)[source]#

Creates an Attribute from a dict

Parameters

attribute_dict (dict) – A dictionary from a serialized Attribute as generated by to_dict()

Return type

Self

copy()#

Create a new attribute that is a copy of the current instance, but with a new identifier

This is used when we want to duplicate an existing attribute onto a different annotation.

Return type

Attribute

classmethod get_subclass_for_data_dict(data_dict)#

Return the subclass that corresponds to the class name found in a data dict

Parameters

data_dict (Dict[str, Any]) – Data dict returned by the to_dict() method of a subclass (or of the base class itself)

Return type

Optional[Type[Self]]

Returns

subclass – Subclass that generated data_dict, or None if data_dict correspond to the base class itself.

class DurationAttribute(label, years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0, metadata=None, uid=None)[source]#

Attribute representing a time quantity associated to a segment or entity.

Each date/time component is optional but at least one must be provided.

Variables
  • uid (str) – Identifier of the attribute

  • label (str) – Label of the attribute

  • value (Optional[Any]) – String representation of the duration (ex: “1 year 10 months 2 days”)

  • direction – Direction the relative date. Ex: “2 years ago” correspond to the PAST direction and “in 2 weeks” to the FUTURE direction.

  • years (int) – Year component of the date quantity

  • months (int) – Month component of the date quantity

  • weeks (int) – Week component of the date quantity

  • days (int) – Day component of the date quantity

  • hours (int) – Hour component of the time quantity

  • minutes (int) – Minute component of the time quantity

  • seconds (int) – Second component of the time quantity

  • metadata (Dict[str, Any]) – Metadata of the attribute

Methods:

copy()

Create a new attribute that is a copy of the current instance, but with a new identifier

from_dict(duration_dict)

Creates an Attribute from a dict

get_subclass_for_data_dict(data_dict)

Return the subclass that corresponds to the class name found in a data dict

to_brat()

Return a value compatible with the brat format

to_spacy()

Return a value compatible with spaCy

to_brat()[source]#

Return a value compatible with the brat format

Return type

str

to_spacy()[source]#

Return a value compatible with spaCy

Return type

str

classmethod from_dict(duration_dict)[source]#

Creates an Attribute from a dict

Parameters

attribute_dict (dict) – A dictionary from a serialized Attribute as generated by to_dict()

Return type

Self

copy()#

Create a new attribute that is a copy of the current instance, but with a new identifier

This is used when we want to duplicate an existing attribute onto a different annotation.

Return type

Attribute

classmethod get_subclass_for_data_dict(data_dict)#

Return the subclass that corresponds to the class name found in a data dict

Parameters

data_dict (Dict[str, Any]) – Data dict returned by the to_dict() method of a subclass (or of the base class itself)

Return type

Optional[Type[Self]]

Returns

subclass – Subclass that generated data_dict, or None if data_dict correspond to the base class itself.

class RelativeDateAttribute(label, direction, years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0, metadata=None, uid=None)[source]#

Attribute representing a relative date or time associated to a segment or entity, ie a date/time offset from an (unknown) reference date/time, with a direction.

At least one date/time component must be non-zero.

Variables
  • uid (str) – Identifier of the attribute

  • label (str) – Label of the attribute

  • value (Optional[Any]) – String representation of the relative date (ex: “+ 1 year 10 months 2 days”)

  • direction (medkit.text.ner.date_attribute.RelativeDateDirection) – Direction the relative date. Ex: “2 years ago” corresponds to the PAST direction and “in 2 weeks” to the FUTURE direction.

  • years (int) – Year component of the date offset

  • months (int) – Month component of the date offset

  • weeks (int) – Week component of the date offset

  • days (int) – Day component of the date offset

  • hours (int) – Hour component of the time offset

  • minutes (int) – Minute component of the time offset

  • seconds (int) – Second component of the time offset

  • metadata (Dict[str, Any]) – Metadata of the attribute

Methods:

copy()

Create a new attribute that is a copy of the current instance, but with a new identifier

from_dict(date_dict)

Creates an Attribute from a dict

get_subclass_for_data_dict(data_dict)

Return the subclass that corresponds to the class name found in a data dict

to_brat()

Return a value compatible with the brat format

to_spacy()

Return a value compatible with spaCy

copy()#

Create a new attribute that is a copy of the current instance, but with a new identifier

This is used when we want to duplicate an existing attribute onto a different annotation.

Return type

Attribute

classmethod get_subclass_for_data_dict(data_dict)#

Return the subclass that corresponds to the class name found in a data dict

Parameters

data_dict (Dict[str, Any]) – Data dict returned by the to_dict() method of a subclass (or of the base class itself)

Return type

Optional[Type[Self]]

Returns

subclass – Subclass that generated data_dict, or None if data_dict correspond to the base class itself.

to_brat()[source]#

Return a value compatible with the brat format

Return type

str

to_spacy()[source]#

Return a value compatible with spaCy

Return type

str

classmethod from_dict(date_dict)[source]#

Creates an Attribute from a dict

Parameters

attribute_dict (dict) – A dictionary from a serialized Attribute as generated by to_dict()

Return type

Self

class RelativeDateDirection(value)[source]#

Direction of a RelativeDateAttribute