Source code for docarray.dataclasses.getter

from typing import TYPE_CHECKING
from docarray.dataclasses.enums import DocumentMetadata, ImageType

if TYPE_CHECKING:  # pragma: no cover
    from docarray import Document


[docs]def image_getter(doc: 'Document'): if doc._metadata[DocumentMetadata.IMAGE_TYPE] == ImageType.URI: return doc.uri elif doc._metadata[DocumentMetadata.IMAGE_TYPE] == ImageType.PIL: from PIL import Image return Image.fromarray(doc.tensor) elif doc._metadata[DocumentMetadata.IMAGE_TYPE] == ImageType.NDARRAY: return doc.tensor
[docs]def text_getter(doc: 'Document'): return doc.text
[docs]def uri_getter(doc: 'Document'): return doc.uri
[docs]def audio_getter(doc: 'Document'): return doc.uri or doc.tensor
[docs]def video_getter(doc: 'Document'): return doc.uri or doc.tensor
[docs]def mesh_getter(doc: 'Document'): return doc.uri or doc.tensor
[docs]def tabular_getter(doc: 'Document'): return doc.uri
[docs]def blob_getter(doc: 'Document'): return doc.uri or doc.blob
[docs]def json_getter(doc: 'Document'): return doc.tags