Datasets:

ArXiv:
File size: 1,000 Bytes
8f3bc41
c5700f9
 
8f3bc41
 
c5700f9
 
 
 
 
 
 
 
 
 
 
 
 
 
73c5930
 
 
c5700f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import random
from abc import abstractmethod
from dataclasses import field

from .artifact import Artifact


class Collection(Artifact):
    @abstractmethod
    def __getitem__(self, key):
        pass


class ListCollection(Collection):
    items: list = field(default_factory=list)

    def __getitem__(self, index):
        return self.items[index]

    def __len__(self):
        return len(self.items)


class DictCollection(Collection):
    items: dict = field(default_factory=dict)

    def __getitem__(self, key):
        return self.items[key]


class ItemPicker(Artifact):
    item: object = None

    def __call__(self, collection: Collection):
        return collection[self.item]


class RandomPicker(Artifact):
    def __call__(self, collection: Collection):
        if isinstance(collection, ListCollection):
            return random.choice(list(collection.items))
        elif isinstance(collection, DictCollection):
            return random.choice(list(collection.items.values()))