Store

ExampleStore

__contains__(self, example)

Show source code in recon/store.py
28
29
30
31
32
33
34
35
36
37
38
    def __contains__(self, example: Union[int, Example]) -> bool:
        """Check whether a string is in the store.

        Args:
            example (Union[int, Example]): The example to check

        Returns:
            Whether the store contains the example.
        """
        example_hash = hash(example) if isinstance(example, Example) else example
        return example_hash in self._map

Check whether a string is in the store.

Parameters

Name Type Description Default
example Union[int, recon.types.Example] The example to check required

Returns

Type Description
bool Whether the store contains the example.

__len__(self)

Show source code in recon/store.py
20
21
22
23
24
25
26
    def __len__(self) -> int:
        """The number of strings in the store.

        Returns:
            Number of examples in store
        """
        return len(self._map)

The number of strings in the store.

Returns

Type Description
int Number of examples in store

add(self, example)

Show source code in recon/store.py
40
41
42
43
44
45
46
47
    def add(self, example: Example) -> None:
        """Add an Example to the store

        Args:
            example (Example): example to add
        """
        example_hash = hash(example)
        self._map[example_hash] = example

Add an Example to the store

Parameters

Name Type Description Default
example Example example to add required

from_disk(self, path)

Show source code in recon/store.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    def from_disk(self, path: Path) -> "ExampleStore":
        """Load store from disk

        Args:
            path (Path): Path to file to load from

        Returns:
            ExampleStore: Initialized ExampleStore
        """
        path = ensure_path(path)
        examples = srsly.read_jsonl(path)
        for e in examples:
            example_hash = e["example_hash"]
            raw_example = e["example"]
            example = Example(**raw_example)
            assert hash(example) == example_hash
            self.add(example)

        return self

Load store from disk

Parameters

Name Type Description Default
path Path Path to file to load from required

Returns

Type Description
ExampleStore ExampleStore: Initialized ExampleStore

to_disk(self, path)

Show source code in recon/store.py
69
70
71
72
73
74
75
76
77
78
79
80
    def to_disk(self, path: Path) -> None:
        """Save store to disk

        Args:
            path (Path): Path to save store to
        """
        path = ensure_path(path)
        examples = []
        for example_hash, example in self._map.items():
            examples.append({"example_hash": example_hash, "example": example.dict()})

        srsly.write_jsonl(path, examples)

Save store to disk

Parameters

Name Type Description Default
path Path Path to save store to required