CharBudgetCompressor#
- class scikitplot.corpus.CharBudgetCompressor(max_chars, whole_words=True)[source]#
Keep each hit’s text, best first, until a character budget is spent.
- Parameters:
- max_charsint
Characters of source text the context may hold in total.
- whole_wordsbool, default=True
Cut a partly kept hit at its last whitespace character (
str.isspace) within the budget, so no word is split; a hit whose first word does not fit keeps nothing. Text without whitespace (Chinese, Japanese) is then kept only whole: useFalsefor it.
- Parameters:
Notes
User. Deterministic and order-preserving: hits are kept in rank order and each keeps one span from the start of its text. Hits after the budget is spent keep nothing.
Examples
>>> class Doc: ... def __init__(self, text): ... self.text = text >>> class Hit: ... def __init__(self, text): ... self.doc = Doc(text) >>> CharBudgetCompressor(12)("q", [Hit("alpha beta"), Hit("gamma delta")]) [((0, 10),), ()]