简体   繁体   English

如何在不输入所有变体(在 R 中)的情况下搜索单词的变体?

[英]How can I search for the variation of a word without typing all variations ( in R)?

I need to check whether the variation of a word is in the text?我需要检查一个单词的变体是否在文本中? How can I do that without typing everything out?我怎么能在不输入所有内容的情况下做到这一点? For example, I need to search for the word 'broken', is there a way in r where it can look for the word and other variations?例如,我需要搜索“破碎”这个词,有没有办法在 r 中查找这个词和其他变体?

a="Broken flask"
b="fragmented flask"
c="broke glass"
d="shattered glass"
e="break flask"
text=c(a,b,c,d,e)
str_detect(tolower(text),"broken|fragmented|broke|break|shatter|shattered")

You could check out syn from the syn package, which generates synonyms for a given word, allowing you to do:您可以从syn包中查看syn ,该包会为给定单词生成同义词,允许您执行以下操作:

library(syn)

grepl(paste0(c("broken", syn("broken")), collapse = "|"), text, ignore.case = T)
#> [1]  TRUE  TRUE  TRUE  TRUE FALSE

It picked up 4 out of 5 here, without having to program any variations.它在这里选择了 5 个中的 4 个,而无需编程任何变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM