Text (tokens:numpy.ndarray, has_spaces:numpy.ndarray, metadata:dict={},
doc_df:polars.dataframe.frame.DataFrame=None)
Class to represent text documents
Type
Default
Details
tokens
ndarray
list of token strs
has_spaces
ndarray
whether token strs followed by space
metadata
dict
{}
metadata for doc as a dict
doc_df
DataFrame
None
if provided can be used for enhanced display (e.g. keyword highlighting)
The Text class is not intended to be used directly. Functionality is accessible via the Corpus.text method, which provides the necessary inputs to instantiate the class. The examples below illustrate how Text objects can be created and used for a Corpus.
maximum length of text to display in tokens, if None, display all
output_html
bool
True
whether to display text with HTML formatting
textwrap_width
int | None
None
maximum length of text to display in characters, if None, no wrapping
textwrap_args
dict | None
None
additional args to pass to textwrap.fill
reflow_paragraphs
bool
False
whether to reflow paragraphs individually before text wrapping is applied
paragraph_delimiter_regex
str
(){1,}
regex to split paragraphs for reflow_paragraphs (default looks for whitespace ending with a newline that contains at least one other newline)
gardenparty.text(12).display(max_tokens =200)
Metadata
Attribute
Value
document_id
12
file
the-singing-lesson.txt
With despair—cold, sharp despair—buried deep in her heart like a wicked
knife, Miss Meadows, in cap and gown and carrying a little baton, trod
the cold corridors that led to the music hall. Girls of all ages, rosy
from the air, and bubbling over with that gleeful excitement that comes
from running to school on a fine autumn morning, hurried, skipped,
fluttered by; from the hollow class-rooms came a quick drumming of
voices; a bell rang; a voice like a bird cried, “Muriel.” And then
there came from the staircase a tremendous knock-knock-knocking. Some
one had dropped her dumbbells.
The Science Mistress stopped Miss Meadows.
“Good mor-ning,” she cried, in her sweet, affected drawl. “Isn’t it
cold? It might be win-ter.”
Miss Meadows, hugging the knife, stared in hatred at the Science
Mistress. Everything about her was sweet,…
[200 of 2985 tokens]
With despair—cold, sharp despair—buried deep in her heart like a wicked knife, Miss Meadows, in cap
and gown and carrying a little baton, trod the cold corridors that led to the music hall. Girls of
all ages, rosy from the air, and bubbling over with that gleeful excitement that comes from
running to school on a fine autumn morning, hurried, skipped, fluttered by; from the hollow class-
rooms came a quick drumming of voices; a bell rang; a voice like a bird cried, “Muriel.” And then
there came from the staircase a tremendous knock-knock-knocking. Some one had dropped her
dumbbells.
The Science Mistress stopped Miss Meadows.
“Good mor-ning,” she cried, in her sweet, affected drawl. “Isn’t it cold? It might be win-ter.”
Miss Meadows, hugging the knife, stared in hatred at the Science Mistress. Everything about her was
sweet,… [200 of 2985 tokens]
gardenparty.text(12).as_string(max_tokens =50)
'With despair—cold, sharp despair—buried deep in her heart like a wicked\r\nknife, Miss Meadows, in cap and gown and carrying a little baton, trod\r\nthe cold corridors that led to the music hall. Girls of all ages, rosy'