Extract the Text Per Cluster from the pdf_detect_clusters()
object
Source: R/pdf_extract_clusters.R
pdf_extract_clusters.Rd
As an end user, you mainly want to work with the text from the different detected text clusters. This function combines the text from each cluster into a character string and places it in a Tibble. A word count is added per cluster.
Arguments
- pdf_data
result of the
pdf_detect_clusters()
-function or a page of this result- combine
logical; if TRUE (default) and input is a list of tibbles, the function returns one combined tibble with a page number column added. If FALSE, returns a list of tibbles.
Value
If the input is a list of tibbles and combine=TRUE (default), a single tibble is returned containing the text of all clusters with an added page number column. If the input is a list of tibbles and combine=FALSE, a list-object is returned, where each element is a tibble containing the text extracted from each cluster on a page. If the input is a single tibble, a tibble is returned directly, containing the text extracted from each cluster on that page, including a word count per cluster.
Examples
# Extract text from a single page's clusters
npo[[1]] |>
pdf_detect_clusters() |>
pdf_extract_clusters()
#> ℹ Clusters detected and renumbered: 2 on this page.
#> # A tibble: 3 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 3 "Terugblik 2023\n 12\n"
#> 2 1 2 "Terugblik 2023\n"
#> 3 2 2 "Ons verhaal\n"
# Extract text from multiple pages as a single combined tibble
head(npo, 3) |>
pdf_detect_clusters() |>
pdf_extract_clusters()
#> ℹ Processing 3 pages
#> ✔ Clusters successfully detected and renumbered on 3 pages.
#> ℹ Extracting text from 3 pages
#> ✔ Text successfully extracted from 3 pages.
#> [[1]]
#> # A tibble: 3 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 3 "Terugblik 2023\n 12\n"
#> 2 1 2 "Terugblik 2023\n"
#> 3 2 2 "Ons verhaal\n"
#>
#> [[2]]
#> # A tibble: 11 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 10 "Inhoud\n Uitgelicht\n Verdieping\n Bijlagen\n Leeswijze…
#> 2 1 96 "De Terugblik is de jaarlijkse rapportage van de NPO ove…
#> 3 2 11 "NPO\n De Stichting NPO; het bestuursorgaan van de Neder…
#> 4 3 19 "Publieke omroep\n Het geheel van bestuur en omroepen va…
#> 5 4 28 "Omroepen\n Alle landelijke publieke omroepen; taakomroe…
#> 6 5 3 "NPO Terugblik 2023\n"
#> 7 6 5 "Inhoud\n 1. Voortdurend in verbinding\n"
#> 8 7 30 "2. \aVerdieping Terugblik 2023\n • Veelkleurig & waarde…
#> 9 9 3 "40\n 45\n 47\n"
#> 10 8 29 "3. \aBijlagen\n 1 Publieke Waardetoets\n 2 Kwaliteitsto…
#> 11 10 8 "48\n 49\n 52\n 53\n 57\n 72\n 74\n 81\n"
#>
#> [[3]]
#> # A tibble: 7 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 5 "Inhoud\n Uitgelicht\n Verdieping\n Bijlagen\n 3\n"
#> 2 1 3 "Voortdurend\n in verbinding\n"
#> 3 2 39 "In een samenleving die van alle kanten onder druk staat,…
#> 4 3 80 "De Nederlandse publieke omroep wil dat baken zijn. Een p…
#> 5 4 34 "Dankzij de gepassioneerde inzet van onze makers bereikte…
#> 6 5 62 "Ons streven naar verbinding is ook de katalysator voor d…
#> 7 6 3 "NPO Terugblik 2023\n"
#>
# Extract text from multiple pages as a list of tibbles
head(npo, 3) |>
pdf_detect_clusters() |>
pdf_extract_clusters(combine = FALSE)
#> ℹ Processing 3 pages
#> ✔ Clusters successfully detected and renumbered on 3 pages.
#> ℹ Extracting text from 3 pages
#> ✔ Text successfully extracted from 3 pages.
#> [[1]]
#> # A tibble: 3 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 3 "Terugblik 2023\n 12\n"
#> 2 1 2 "Terugblik 2023\n"
#> 3 2 2 "Ons verhaal\n"
#>
#> [[2]]
#> # A tibble: 11 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 10 "Inhoud\n Uitgelicht\n Verdieping\n Bijlagen\n Leeswijze…
#> 2 1 96 "De Terugblik is de jaarlijkse rapportage van de NPO ove…
#> 3 2 11 "NPO\n De Stichting NPO; het bestuursorgaan van de Neder…
#> 4 3 19 "Publieke omroep\n Het geheel van bestuur en omroepen va…
#> 5 4 28 "Omroepen\n Alle landelijke publieke omroepen; taakomroe…
#> 6 5 3 "NPO Terugblik 2023\n"
#> 7 6 5 "Inhoud\n 1. Voortdurend in verbinding\n"
#> 8 7 30 "2. \aVerdieping Terugblik 2023\n • Veelkleurig & waarde…
#> 9 9 3 "40\n 45\n 47\n"
#> 10 8 29 "3. \aBijlagen\n 1 Publieke Waardetoets\n 2 Kwaliteitsto…
#> 11 10 8 "48\n 49\n 52\n 53\n 57\n 72\n 74\n 81\n"
#>
#> [[3]]
#> # A tibble: 7 × 3
#> .cluster word_count text
#> <fct> <int> <chr>
#> 1 0 5 "Inhoud\n Uitgelicht\n Verdieping\n Bijlagen\n 3\n"
#> 2 1 3 "Voortdurend\n in verbinding\n"
#> 3 2 39 "In een samenleving die van alle kanten onder druk staat,…
#> 4 3 80 "De Nederlandse publieke omroep wil dat baken zijn. Een p…
#> 5 4 34 "Dankzij de gepassioneerde inzet van onze makers bereikte…
#> 6 5 62 "Ons streven naar verbinding is ook de katalysator voor d…
#> 7 6 3 "NPO Terugblik 2023\n"
#>