InMemoryStorage#
- class scikitplot.corpus.InMemoryStorage[source]#
Thread-safe in-memory dict store.
Stores documents as
CorpusDocumentobjects directly in adictkeyed bydoc_id. Insertion order is preserved (Python 3.7+ dict guarantee).Warning
This backend is intended for testing and prototyping only. Data is lost when the process exits.
- Parameters:
- None
Examples
>>> store = InMemoryStorage() >>> store.save(doc) >>> store.count() 1 >>> store.get(doc.doc_id).text == doc.text True
- get(doc_id)[source]#
Return the document with the given
doc_id, orNone.- Parameters:
- doc_idstr
- Parameters:
doc_id (str)
- Return type:
CorpusDocument | None
- query(q)[source]#
Filter documents by the query parameters.
Full-text search (
q.full_text) is not supported — thefull_textfield is ignored silently.- Parameters:
- qStorageQuery
- Returns:
- QueryResult
- Parameters:
q (StorageQuery)
- Return type:
- save(doc)[source]#
Store
docbydoc_id. Overwrites if already present.- Parameters:
- docCorpusDocument
- Parameters:
doc (CorpusDocument)
- Return type:
None
- save_batch(docs)[source]#
Store a batch of documents atomically (single lock acquisition).
- Parameters:
- docssequence of CorpusDocument
- Parameters:
docs (Sequence[CorpusDocument])
- Return type:
None