gpt4 book ai didi

r - 根据大写字母 (R) 拆分字符串

转载 作者:行者123 更新时间:2023-12-04 10:47:44 25 4
gpt4 key购买 nike

我正在使用 Vagalume 的 API 提取歌词。

library(vagalumeR)
library(tibble)
library(stringr)
set.seed(1234)

key = "7a67715b6d0dd6edf7556cc0d176e4ac"

musicas = as.tibble(topLyrics(name = "seu-jorge",
message = TRUE))

musica = sample(musicas$id.top, 1)

letra = lyrics(identifier = musica,
type = "id",
artist = "seu-jorge",
key = key)

但是,letra 只是一大块文本,我想将它分成较小的文本 block

str_split(string = as.character(letra),
"[[:upper:]]")

这就是我得到的:

[1] "Pretinha"                                 "aço tudo pelo nosso amor"                
[3] "aço tudo pelo bem de nosso bem (meu bem)" " saudade é minha dor"
[5] "ue anda arrasando com meu coração" "ão"
[7] "uvide que um dia" "u te darei o céu"
[9] "eu amor junto com um anel" "ra gente se casar"

我很确定你们中的大多数人都不懂葡萄牙语,但请相信我,它会跳过我用作分隔符的大写字母。如何将大写字母包含到较小的 block 中?

最佳答案

您想使用 positive lookahead :

str_split(string = as.character(letra), "(?=[[:upper:]])")

它在 "" 处拆分,如果它后面有一个大写字母。

关于r - 根据大写字母 (R) 拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com