Skip to content

Sentiment Analysis | set_names-Workflow won't work if context of query word extends into next date #15

@ChristophLeonhardt

Description

@ChristophLeonhardt

In lesson 7, "Diktionäre und Sentiment-Analysen" (https://polmine.github.io/UCSSR/sentiments.html#8), you propose a workflow in which context() and partition_bundle() are deployed to identify hits and their surrounding words. The proposed workflow doesn't work if one of the query term's context extends into the next date (or whatever struc is used for grouping the sentiment).

If I see this correctly, the partition_bundle method here splits the context object into partitions, omitting the node (i.e. the query) itself. This doesn't regard boundaries which is why later, when set_names() is called, the s_attributes() methods returns more individual dates than there are partitions in the partition bundle.

Here is a reproducible example to see the error:

library(polmineR)
library(data.table)
 
gist_url <- "https://gist.githubusercontent.com/PolMine/70eeb095328070c18bd00ee087272adf/raw/c2eee2f48b11e6d893c19089b444f25b452d2adb/sentiws.R"
devtools::source_url(gist_url)
SentiWS <- get_sentiws()
 
vocab <- c(
  positive = nrow(SentiWS[base == TRUE][weight > 0]),
  negative = nrow(SentiWS[base == TRUE][weight < 0])
)
 
options("polmineR.left" = 10L)
options("polmineR.right" = 10L)

df <- context("GERMAPARLMINI", query = 'Präsidiums', p_attribute = "word") %>%
  partition_bundle(node = FALSE) %>%
  set_names(s_attributes(., s_attribute = "date")) %>%
  weigh(with = SentiWS) %>% 
  summary()

After writing this, I remembered that there is a boundary argument for context(). If the general behavior of this workflow is okay, then adding a reasonable boundary (probably speech, which isn't annotated in all corpora or speaker, but there certainly are a lot of situations in which the same speaker might end one debate and start the next) would improve the UCSSR example both functionally as well as substantially as we don't want to measure other speaker's words as context for the sentiment analysis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions