
Convert a prepared topic corpus to a data frame
Source:R/accessors.R
as.data.frame.sbert_topic_corpus.Rdas.data.frame() returns the units of a prepared corpus, one row per unit to
be clustered: each document, or each sentence, clause, or phrase when the
corpus is segmented. The table shows what topics() and compare_topics()
will model, including the segments a segmentation produced and the columns
carried from a data frame input.
Usage
# S3 method for class 'sbert_topic_corpus'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)Arguments
- x
A corpus prepared by
topic_corpus().- row.names, optional
Ignored; present for compatibility with the generic.
- ...
Ignored.
Value
A base data frame with one row per unit and columns
document_id, document_name, segment (segmented corpora only), and
text, followed by the columns carried from a data frame input.
Examples
documents <- data.frame(
id = c("a", "b"),
text = c("Cats chase mice. Stocks and bonds trade.",
"Dogs chase balls. Markets price shares.")
)
prepared <- topic_corpus(
documents, column = "text", segment = "sentence",
embeddings = rbind(c(1, 0), c(0, 1), c(0.9, 0.1), c(0.1, 0.9))
)
as.data.frame(prepared)
#> document_id document_name segment text id
#> 1 1 1 Cats chase mice. a
#> 2 1 2 Stocks and bonds trade. a
#> 3 2 1 Dogs chase balls. b
#> 4 2 2 Markets price shares. b