
"""Base Materializer to realize artifact data."""ASSOCIATED_ARTIFACT_TYPE = ArtifactType.BASE

ASSOCIATED_TYPES = ()

def __init__(

self, uri: str, artifact_store: Optional[BaseArtifactStore] = None

):

"""Initializes a materializer with the given URI.

Args:

uri: The URI where the artifact data will be stored.

artifact_store: The artifact store used to store this artifact.

"""

self.uri = uri

self._artifact_store = artifact_store

def load(self, data_type: Type[Any]) -> Any:

"""Write logic here to load the data of an artifact.

Args:

data_type: The type of data that the artifact should be loaded as.

Returns:

The data of the artifact.

"""

# read from a location inside self.uri

# Example:

# data_path = os.path.join(self.uri, "abc.json")

# with self.artifact_store.open(filepath, "r") as fid:

#     return json.load(fid)

...

def save(self, data: Any) -> None:

"""Write logic here to save the data of an artifact.

Args:

data: The data of the artifact to save.

"""

# write `data` into self.uri

# Example:

# data_path = os.path.join(self.uri, "abc.json")

# with self.artifact_store.open(filepath, "w") as fid:

#     json.dump(data,fid)

...

def save_visualizations(self, data: Any) -> Dict[str, VisualizationType]:

"""Save visualizations of the given data.

Args:

data: The data of the artifact to visualize.

Returns:

A dictionary of visualization URIs and their types.

"""

# Optionally, define some visualizations for your artifact

# E.g.:

# visualization_uri = os.path.join(self.uri, "visualization.html")

# with self.artifact_store.open(visualization_uri, "w") as f:

#     f.write("<html><body>data</body></html>")

# visualization_uri_2 = os.path.join(self.uri, "visualization.png")

# data.save_as_png(visualization_uri_2)

# return {

#     visualization_uri: ArtifactVisualizationType.HTML,

#     visualization_uri_2: ArtifactVisualizationType.IMAGE

# }

...

def extract_metadata(self, data: Any) -> Dict[str, "MetadataType"]:

"""Extract metadata from the given data.