我有一个子串列表,具有以下模式:
my.list <- list("file1\\subfile1-D.ext", "file12\\subfile9-D.ext", "file2\\subfile113-D.ext")
Run Code Online (Sandbox Code Playgroud)
等等.我想将文件号和子文件号提取到包含文件/子文件号的数字数据框中.到目前为止,我一直在使用以下方法:
extract.file <- function(file.name){
file.name <- sub("file", "", file.name)
file.name <- sub("\\\\*subfile.*", "", file.name)
}
extract.subfile <- function(subfile.name){
subfile.name <- sub("file.*subfile", "", subfile.name)
subfile.name <- sub("-D.ext", "", subfile.name)
}
name.file <- lapply(my.list, extract.file)
name.file <- as.numeric(unlist(name.file))
name.subfile <- lapply(my.list, extract.subfile)
name.subfile <- as.numeric(unlist(name.subfile))
my.df <- data.frame(file=name.file, subfile=name.subfile)
Run Code Online (Sandbox Code Playgroud)
我还玩过第一次substring.location从stringr库中提取字符串位置(产生另一个包含开始和结束值的列表),然后循环遍历两个列表,但这又变得太复杂了.有没有更好的方法来实现目标?
所以我的代码看起来像这样
string order = "Im sending you big apples x100";
string[] fruits = { "apples", "big apples", "oranges" };
string[] vegetables = { "tomatoes", "carrots", "cucumber" };
string[] words = order.Split();
if (fruits.Any(w => words.Contains(w)))
{
//do things here
}
if (vegetables.Any(w => words.Contains(w)))
{
//do things here
}
Run Code Online (Sandbox Code Playgroud)
我希望能够找到依赖于顺序字符串的确切内容,如果可能的话,现在在我的情况下,当字符串数组有2个单词的顺序时,这个代码不起作用,当我的字符串数组有2个单词时,我怎么能这样做.我想找到只有它有"大苹果"我知道我只能做"苹果",但我想在订单字符串中找到序列字.
我有2个字符串数组.一个是基础,另一个是变化.
string[] baseArray = { "Gold", "Silver", "Bronze" };
string[] readArray = { "Bronze", "Silver", "Gold" };
// After comparing the readArray over the baseArray the result should be this
//string match = "Gold";
Run Code Online (Sandbox Code Playgroud)
我想按照baseArray的顺序获得第一名.
//Example2
string[] readArray = { "Bronze", "Silver" };
//string match should be "Silver"
Run Code Online (Sandbox Code Playgroud) 以下是本机字符串匹配中非常着名的问题.请有人向我解释答案.
假设模式P中的所有字符都不同.演示如何加速NAIVE-STRING MATCHER在n字符文本T上及时运行O(n).
为什么这种情况永远不会满足?它永远不会产生一个弹出窗口,在我的理解中应该显示一旦x是列表的第3个元素.
var list = [];
list[0] = "ahhah";
list[1] = "abcdef";
list[2] = "123";
for (var x in list) {
if (x == "123")
alert("HA");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试解决文本匹配问题,其中我试图在没有错误匹配的产品列表之间找到匹配.行进是通过文本相似性完成的.问题在于假设我"product G1234"在一个列表中,而在另一个列表 "product G1"中,这两个元素的所有其他特征是相同的.将 string operator in在python是不是一个好的选择这里,因为它的这两款产品相匹配(它不应该),任何人有什么建议吗?
如果我有这样的字符串:
var str = "play the Ukulele in Lebanon. play the Guitar in Lebanon.";
Run Code Online (Sandbox Code Playgroud)
我想得到每个子串"play"和"in"之间的字符串,所以基本上是一个带有"Ukelele"和"Guitar"的数组.
现在我正在做:
var test = str.match("play(.*)in");
Run Code Online (Sandbox Code Playgroud)
但是在第一个"游戏"和最后一个"在"之间返回字符串,所以我得到了"在黎巴嫩的尤克里里琴.弹吉他"而不是两个单独的字符串.有没有人知道如何全局搜索字符串以查找起始字符串和结束字符串之间的所有子字符串?
我希望将英语单词语义化,使得所有单词都转换为相同的时态.例如:
c("ran","run","running")
Run Code Online (Sandbox Code Playgroud)
应该成为c("run","run","run").
我已经探索了R包,如tm,wordnet,RTextTools和Snowball C; 但所有这些都会产生输出c("ran","run","run").如您所见,它们不会将"运行"转换为"运行".
这个问题在求职面试中呈现给我,我认为这很好,因为有几种方法可以解决它.
描述如下:
类似地,接受诸如" i16ion "," internationali2tion "甚至" 20 "的其他缩写.
要跳过的数字可以是任何正整数(没有0,没有负数),并且该字符串可能包含多个跳过事件 - 例如," int3ationa2za1ion "也是可接受的.
原始字符串不包含数字 - 因此缩写字符串中的每个数字都表示跳过.
缩写字符串也可以以跳过开头或结尾 - 例如" 6ationalizati2 ".
给定两个字符串 - 一个表示原始字符串,另一个表示缩写,确定缩写字符串是否有效.执行此操作的方法必须实现签名
public static boolean equals (String orig, String abbr);
Run Code Online (Sandbox Code Playgroud) 我有一个数据帧df:
df <- structure(list(page = c(12, 6, 9, 65),
text = structure(c(4L,2L, 1L, 3L),
.Label = c("I just bought a brand new AudiA6", "Get 2 years engine replacement warranty on BMW X6",
"Volkswagen is the parent company of BMW", "ToyotaCorolla is offering new car exchange offers"),
class = "factor")), .Names = c("page","text"), row.names = c(NA, -4L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
另外,我有一个单词列表:
wordlist <- c("Audi", "BMW", "extended", "engine", "replacement", "Volkswagen", "company", "Toyota","exchange", "brand")
Run Code Online (Sandbox Code Playgroud)
我通过取消列出文本和使用grepl来查找wordlist中的单词是否存在于列文本中.
library(data.table)
setDT(df)[, match := paste(wordlist[unlist(lapply(wordlist, function(x) grepl(x, text, …Run Code Online (Sandbox Code Playgroud) string-matching ×10
string ×5
r ×3
algorithm ×2
arrays ×2
c# ×2
javascript ×2
regex ×2
data.table ×1
for-loop ×1
grep ×1
grepl ×1
java ×1
linq ×1
nlp ×1
python ×1
substr ×1
text-mining ×1