我正在尝试从字符串中提取拼写出的数字,并提取数字后面的单词。我已经设法通过编写我自己的代码的方式来实现这一点,包括要搜索的拼写数字(这里是stringr::sentences
的例子:
numbers <- str_c(c(" one ", " two ", " three ", " four ", " five ", " six ", " seven ", " eight "," nine ", " ten "), "([^ ]+)")
number_match <- str_c(numbers, collapse = "|")
reduced <- sentences %>%
str_detect(number_match)
sent <- sentences[reduced==TRUE]
str_extract(sent, number_match)
这些是提取的字符串:
[1] " seven books" " two met" " two factors" " three lists" " seven is" " two when" " ten inches." " one war"
[9] " one button" " six minutes." " ten years" " two shares" " two distinct" " five cents" " two pins" " five robins."
[17] " four kinds" " three story" " three inches" " six comes" " three batches" " two leaves."
如果我已经考虑过所有可能的数字,我不可能事先知道,我想知道R是否提供了一个可以识别拼写数字的工具?我发现了类似的问题,例如Convert spelled out number to number 但不幸的是,这不是关于R的问题。
感谢任何帮助。