Skip to content

Datum

Bases: StaticCollection

A class used to store information about a datum for either a 'GroundTruth' or a 'Prediction'.

Attributes:

Name Type Description
uid String

The UID of the datum.

text (String, optional)

The text of the datum, if the datum is a piece of text, otherwise None.

metadata Dictionary

A dictionary of metadata that describes the datum.

Examples:

>>> Datum(uid="uid1")
>>> Datum(uid="uid1", metadata={})
>>> Datum(uid="uid1", metadata={"foo": "bar", "pi": 3.14})
>>> Datum(uid="uid2", text="Did Lincoln win the election of 1860?", metadata={"query_created_by": "Alice"})
Source code in valor/schemas/symbolic/collections.py
class Datum(StaticCollection):
    """
    A class used to store information about a datum for either a 'GroundTruth' or a 'Prediction'.

    Attributes
    ----------
    uid : String
        The UID of the datum.
    text : String, optional
        The text of the datum, if the datum is a piece of text, otherwise None.
    metadata : Dictionary
        A dictionary of metadata that describes the datum.

    Examples
    --------
    >>> Datum(uid="uid1")
    >>> Datum(uid="uid1", metadata={})
    >>> Datum(uid="uid1", metadata={"foo": "bar", "pi": 3.14})
    >>> Datum(uid="uid2", text="Did Lincoln win the election of 1860?", metadata={"query_created_by": "Alice"})
    """

    uid: String = String.symbolic(owner="datum", name="uid")
    text: String = String.symbolic(owner="datum", name="text")
    metadata: Dictionary = Dictionary.symbolic(owner="datum", name="metadata")

    def __init__(
        self,
        *,
        uid: str,
        text: Optional[str] = None,
        metadata: Optional[dict] = None,
    ):
        """
        Constructs a datum.

        Parameters
        ----------
        uid : str
            The UID of the datum.
        text : str, optional
            The text of the datum, if the datum is a piece of text, otherwise None.
        metadata : dict, optional
            A dictionary of metadata that describes the datum.
        """
        super().__init__(
            uid=uid, text=text, metadata=metadata if metadata else dict()
        )

    @staticmethod
    def formatting() -> Dict[str, Any]:
        """Attribute format mapping."""
        return {
            "text": String.nullable,
        }

Functions

valor.Datum.__init__(*, uid, text=None, metadata=None)

Constructs a datum.

Parameters:

Name Type Description Default
uid str

The UID of the datum.

required
text str

The text of the datum, if the datum is a piece of text, otherwise None.

None
metadata dict

A dictionary of metadata that describes the datum.

None
Source code in valor/schemas/symbolic/collections.py
def __init__(
    self,
    *,
    uid: str,
    text: Optional[str] = None,
    metadata: Optional[dict] = None,
):
    """
    Constructs a datum.

    Parameters
    ----------
    uid : str
        The UID of the datum.
    text : str, optional
        The text of the datum, if the datum is a piece of text, otherwise None.
    metadata : dict, optional
        A dictionary of metadata that describes the datum.
    """
    super().__init__(
        uid=uid, text=text, metadata=metadata if metadata else dict()
    )

valor.Datum.formatting() staticmethod

Attribute format mapping.

Source code in valor/schemas/symbolic/collections.py
@staticmethod
def formatting() -> Dict[str, Any]:
    """Attribute format mapping."""
    return {
        "text": String.nullable,
    }