kazu.utils.caching¶
Module Attributes
A TypeVar to represent a return value. |
|
We use the |
Classes
A simple wrapper around LFUCache to reduce calls to expensive processes (e.g. bert). |
|
- class kazu.utils.caching.EntityLinkingLookupCache[source]¶
Bases:
object
A simple wrapper around LFUCache to reduce calls to expensive processes (e.g. bert)
- check_lookup_cache(entities)[source]¶
Checks the cache for linking candidates. If relevant candidates are found for an entity, update it accordingly. If not return as a list of cache misses (e.g. for further processing)
- update_candidates_lookup_cache(entity, candidates)[source]¶
- Parameters:
entity (Entity)
candidates (dict[LinkingCandidate, LinkingMetrics])
- Return type:
None
- class kazu.utils.caching.Memoization[source]¶
- class kazu.utils.caching.Ret¶
A TypeVar to represent a return value.
Used in
Memoization
to encode that a memorized function returns the same type as the original function it ‘memoized’.alias of TypeVar(‘Ret’, covariant=True)
- kazu.utils.caching.kazu_disk_cache: CacheProtocol = <diskcache.core.Cache object>¶
We use the
diskcache.Cache
concept to cache expensive to produce resources to disk. Methods and functions can be decorated with kazu_disk_cache.memoize() to use this feature. Note, when used with a class method, the default behaviour of this function is to generate a key based on the constructor arguments of the class instance. Since these can be large (e.g. OntologyParser), we sometimes use the ignore argument to override this behaviour.e.g.
@kazu_disk_cache.memoize(ignore={0}) def method_of_class_with_lots_of_args(self): ...