InMemoryStorage#

class scikitplot.corpus.InMemoryStorage[source]#

Thread-safe in-memory dict store.

Stores documents as CorpusDocument objects directly in a dict keyed by doc_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
clear()[source]#

Remove all documents from the store.

Return type:

None

count()[source]#

Return total stored document count in O(1).

Return type:

int

get(doc_id)[source]#

Return the document with the given doc_id, or None.

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 — the full_text field is ignored silently.

Parameters:
qStorageQuery
Returns:
QueryResult
Parameters:

q (StorageQuery)

Return type:

QueryResult

save(doc)[source]#

Store doc by doc_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