| 1 |
queryOne <- function(x, |
| 2 |
pattern, |
| 3 |
fuzzy=TRUE, |
| 4 |
perl=TRUE, |
| 5 |
fixed=TRUE, |
| 6 |
ignore.case=TRUE, |
| 7 |
insertions=0.999999999, |
| 8 |
deletions=0, |
| 9 |
substitutions=0 |
| 10 |
){ |
| 11 |
max.distance <- list(insertions=insertions,deletions=deletions,substitutions=substitutions) |
| 12 |
found <- if(fuzzy) |
| 13 |
agrep(pattern,x, |
| 14 |
ignore.case=ignore.case, |
| 15 |
max.distance=max.distance) |
| 16 |
else |
| 17 |
suppressWarnings(grep(pattern,x, |
| 18 |
perl=perl, |
| 19 |
fixed=fixed, |
| 20 |
ignore.case=ignore.case)) |
| 21 |
if(length(found)) x else NULL |
| 22 |
} |
| 23 |
|
| 24 |
queryList <- function(x, |
| 25 |
pattern, |
| 26 |
fuzzy=TRUE, |
| 27 |
perl=TRUE, |
| 28 |
fixed=TRUE, |
| 29 |
ignore.case=TRUE, |
| 30 |
insertions=0.999999999, |
| 31 |
deletions=0, |
| 32 |
substitutions=0 |
| 33 |
){ |
| 34 |
res <- lapply(x,query, |
| 35 |
pattern=pattern, |
| 36 |
fuzzy=fuzzy, |
| 37 |
perl=perl, |
| 38 |
fixed=fixed, |
| 39 |
ignore.case=ignore.case, |
| 40 |
insertions=insertions, |
| 41 |
deletions=deletions, |
| 42 |
substitutions=substitutions |
| 43 |
) |
| 44 |
res <- res[sapply(res,length)>0] |
| 45 |
if(length(res)) res else NULL |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
setMethod("query","data.set",function(x,pattern,...)queryList(x,pattern,...)) |
| 50 |
setMethod("query","importer",function(x,pattern,...)queryList(x,pattern,...)) |
| 51 |
|
| 52 |
setMethod("query","item",function(x,pattern,...){ |
| 53 |
annot <- queryOne(annotation(x),pattern,...) |
| 54 |
labs <- queryOne(labels(x),pattern,...) |
| 55 |
if(length(annot) && length(labs)) list(annotation=annot, labels=labs) |
| 56 |
else if (length(annot)) annot |
| 57 |
else if (length(labs)) labs |
| 58 |
else NULL |
| 59 |
}) |
| 60 |
|