# Wikipedia Highlighter Article

In a second example, we view previous versions of a Wikipedia article (in this case, on the Highlighter), in order to see which parts are consistently included. This data includes the first 150 versions of the article, as well as the latest 150 versions of the article, collected around 14 March, 2024. The data was gathered as follows:

    library(rvest)
    library(dplyr)
    library(purrr)
    library(tibble)
    library(stringr)

    class_of_interest <- ".mw-content-ltr" ## ids are #id-name, classes are .class-name

    # Finding newest 150 versions of Wikipedia's highlighter article
    editurl <- "https://en.wikipedia.org/w/index.php?title=Highlighter&action=history&offset=&limit=150"
    editclass_of_interest <- ".mw-changeslist-date"

    # Save the urls of the full articles
    url_list1 <- editurl %>%
      rvest::read_html() %>%
      rvest::html_nodes(editclass_of_interest) %>%
      purrr::map(., list()) %>%
      tibble::tibble(node = .) %>%
      dplyr::mutate(link = purrr::map_chr(node, html_attr, "href") %>% paste0("https://en.wikipedia.org", .))

    # Finding oldest 150 versions of Wikipedia's highlighter article
    editurl2 <- "https://en.wikipedia.org/w/index.php?title=Highlighter&action=history&dir=prev&limit=150"

    # Save the urls of the full articles
    url_list2 <- editurl2 %>%
      rvest::read_html() %>%
      rvest::html_nodes(editclass_of_interest) %>%
      purrr::map(., list()) %>%
      tibble::tibble(node = .) %>%
      dplyr::mutate(link = purrr::map_chr(node, html_attr, "href") %>% paste0("https://en.wikipedia.org", .))

    # Combine url list
    url_list <- rbind(url_list1, url_list2)

    # create a data frame with the text of the documents
    wiki_pages <- data.frame(page_notes = rep(NA, dim(url_list)[1]))

    for (i in 1:dim(url_list)[1]){

      wiki_list <-  url_list$link[i] %>%
        rvest::read_html() %>%
        rvest::html_node(class_of_interest) %>%
        rvest::html_children() %>%
        purrr::map(., list()) %>%
        tibble::tibble(node = .) %>%
        dplyr::mutate(type = purrr::map_chr(node, html_name)) %>%
        dplyr::filter(type == "p") %>%
        dplyr::mutate(text = purrr::map_chr(node, html_text)) %>%
        dplyr::mutate(cleantext = stringr::str_remove_all(text, "\\[.*?\\]") %>% stringr::str_trim()) %>%
        plyr::summarise(cleantext = paste(cleantext, collapse = "<br> "))

      wiki_pages$page_notes[i] <- wiki_list$cleantext[1]

    }

The previous versions are then compared to the current version’s collocations with fuzzy matching in order to provide a count for the amount of times each collocation occurs in edited documents (divided by the number of times the collocation occurs in the current version to account for duplications).

    library(highlightr)
    # calculate frequencies with reference to source document (first row)
    merged_frequency <- collocation_frequency(highlightr::wiki_pages, text_column = "page_notes",
                                        source_row = 1, fuzzy=TRUE, n_bands=75)

    head(merged_frequency)
    #> # A tibble: 6 × 10
    #>   words        word_num to_merge col_1 col_2 col_3 col_4 col_5 collocation  Freq
    #>   <chr>           <int> <chr>    <dbl> <dbl> <dbl> <dbl> <dbl> <chr>       <dbl>
    #> 1 A                   1 a         7    NA    NA    NA    NA    a highligh…  7
    #> 2 highlighter,        2 highlig…  6.74  7    NA    NA    NA    highlighte…  6.87
    #> 3 also                3 also      6     6.74  7    NA    NA    also calle…  6.58
    #> 4 called              4 called    6     6     6.74  7    NA    called a f…  6.44
    #> 5 a                   5 a         6     6     6     6.74  7    a fluoresc…  6.35
    #> 6 fluorescent         6 fluores…  6     6     6     6     6.74 fluorescen…  6.15

These frequencies can be mapped back to the transcript document, then highlighted as described based on the average collocation frequency that each word appeared in. The results are shown below by specifying ``r page_highlight`` in an R Markdown document outside of a code chunk and knitting to HTML. Note that the “labels” argument can be used to add additional labels to the gradient key.

    # create a ggplot object of the transcript
    freq_plot <- collocation_plot(merged_frequency)

    # add html tags to source document
    page_highlight <- highlighted_text(freq_plot, labels=c("(fewest articles)", "(most articles)"))

(fewest articles) 0
274 (most articles)
A
highlighter,
also
called
a
fluorescent
pen,
is
a
type
of
writing
device
used
to
bring
attention
to
sections
of
text
by
marking
them
with
a
vivid,
translucent
colour.
A
typical
highlighter
is
fluorescent
yellow,
with
the
color
coming
from
pyranine.
Different
compounds,
such
as
rhodamines
(Rhodamine
6GD,
Rhodamine
B)
are
used
for
other
colours.
A
highlighter
is
a
felt
-
tip
marker
filled
with
transparent
fluorescent
ink
instead
of
black
or
opaque
ink.
The
first
highlighter
was
invented
by
Dr.
Frank
Honn
in
1962
and
produced
by
Carter’s
Ink
Company,
using
the
trademarked
name
Hi
-
Liter.
Avery
Dennison
Corporation
now
owns
the
brand,
having
acquired
Carter’s
in
1975.
Many
highlighters
come
in
bright,
often
fluorescent
and
vibrant
colors.
Being
fluorescent,
highlighter
ink
glows
under
black
light.
The
most
common
color
for
highlighters
is
yellow,
but
they
are
also
found
in
orange,
red,
pink,
purple,
blue,
and
green
varieties.
Some
yellow
highlighters
may
look
greenish
in
colour
to
the
naked
eye.
Yellow
is
the
preferred
color
to
use
when
making
a
photocopy
as
it
will
not
produce
a
shadow
on
the
copy.
Highlighters
are
available
in
multiple
forms,
including
some
that
have
a
retractable
felt
tip
or
an
eraser
on
the
end
opposite
the
felt.
Other
types
of
highlighters
include
the
trilighter,
a
triangularly
-
shaped
pen
with
a
different
-
coloured
tip
at
each
corner,
and
ones
that
are
stackable.
There
are
also
some
forms
of
highlighters
that
have
a
wax
-
like
quality
similar
to
an
oil
pastel.
“Dry
highlighters”
(occasionally
called
“dry
line
highlighters”)
have
an
applicator
that
applies
a
thin
strip
of
highlighter
tape
(physically
similar
to
audio
tape
or
correction
tape)
instead
of
a
felt
tip.
Unlike
standard
highlighters,
they
are
easily
erasable.
They
are
different
from
“dry
mark
highlighters”,
which
are
sometimes
advertised
as
being
useful
for
highlighting
books
with
thin
pages.
“Gel
highlighters”
contain
a
gel
stick
rather
than
a
felt
tip.
The
gel
does
not
bleed
through
paper
or
become
dried
out
in
the
pen
as
other
highlighters’
inks
may,
which
renders
them
useless.
“Liquid
Highlighters”
in
a
range
of
colours
are
also
available,
and
because
they
put
more
ink
on
a
page
when
highlighting,
they
make
words
stand
out
more
than
with
non
-
liquid
types.
Also
the
fact
that
more
highlighting
ink
is
put
on
the
page
with
liquid
highlighters
means
that
the
highlighting
ink
is
much
more
resistive
to
fading
with
age.
“Pastel
Highlighters”
use
pastel
dyes
instead
of
fluorescent
dyes.
Some
word
processing
software
can
simulate
highlighting
by
using
a
technique
similar
to
reverse
video
on
some
terminals.
Some
forms
of
syntax
highlighting
may
also
be
displayed
in
the
style
of
a
highlighter
pen,
with
a
bright
or
pastel
background
to
the
text.
Some
web
browser
extensions
also
enables
users
to
create
digital
highlights
on
websites
and
online
PDFs.

This text indicates changes to the Wikipedia article, where yellow indicates more occurrences (such as yellow as the primary highlight color and information regarding the trilighter). Darker colors indicate text that is seen in fewer versions of the article (such as the introductory sentence and the reference to correction tape).

We could also use the oldest version of the Highlighter article in the dataset as the transcript reference to view which text has been changed:

    # calculate frequencies with reference to source document (last row)
    merged_frequency2 <- collocation_frequency(highlightr::wiki_pages, text_column = "page_notes",
                                        source_row = nrow(wiki_pages), fuzzy=TRUE, n_bands=75)

    # create a gpplot object of the transcript
    freq_plot2 <- collocation_plot(merged_frequency2)

    # add html tags to source document
    page_highlight2 <- highlighted_text(freq_plot2, labels=c("(fewest articles)", "(most articles)"))

(fewest articles) 0
242 (most articles)
A
highlighter
is
a
form
of
marker
pen
which
is
used
to
highlight
sections
of
documents
in
a
vivid
colour,
but
not
intended
to
obscure
the
content
beneath
the
marking.
As
such,
highlighter
ink
is
translucent.
Many
highlighters
come
in
bright,
often
neon
colors,
such
as
yellow
or
pink,
but
also
coming
in
colors
such
as
blue,
green,
or
purple.

In this case, the beginning of the first sentence (“A highlighter is a form…”) is fairly popular.

Wikipedia Citation: “Highlighter.” Wikipedia, 14 Mar. 2024. Wikipedia, https://en.wikipedia.org/w/index.php?title=Highlighter&oldid=1213690238.