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
- close()[source]#
Release the backend’s resources; safe to call more than once.
The default holds nothing and does nothing. A backend that holds a connection or a file (
SQLiteStorage) overrides it.Notes
User. Prefer
with SQLiteStorage(path) as store: ...: the connection is closed when the block ends, also on an error. An unclosed SQLite connection is reported as aResourceWarningby Python 3.13 and later when it is garbage-collected (R3-8).- Return type:
None
- 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 emulated by a case-insensitive substring scan and reported asFilterSupport.EMULATED– there is no stemming, tokenisation or relevance ranking. It is never silently ignored (finding F-R07-01).- 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
Gallery examples#
Build and Search a Real Hamlet Corpus with FluentCorpus
Build and Search a Real Hamlet Corpus with FluentCorpus
Build and Search a Real Hamlet Corpus with FluentCorpus