【发布时间】:2023-03-08 11:35:02
【问题描述】:
我正在尝试如下标记一个句子。
Section <- c("If an infusion reaction occurs, interrupt the infusion.")
df <- data.frame(Section)
当我使用 tidytext 和下面的代码进行标记时,
AA <- df %>%
mutate(tokens = str_extract_all(df$Section, "([^\\s]+)"),
locations = str_locate_all(df$Section, "([^\\s]+)"),
locations = map(locations, as.data.frame)) %>%
select(-Section) %>%
unnest(tokens, locations)
它给了我一个如下的结果集(见图)。
如何将逗号和句点作为独立标记而不是“发生”和“注入”的一部分。分别使用 tidytext。所以我的令牌应该是
If
an
infusion
reaction
occurs
,
interrupt
the
infusion
.
【问题讨论】: