current status

This commit is contained in:
2015-01-18 22:46:54 +01:00
parent ba40416197
commit 24f5b02221
6 changed files with 431 additions and 394 deletions
+11 -7
View File
@@ -27,16 +27,20 @@ convertLogical0 <- function(var) {
}
smartPatternMatch <- function(string, pattern, chars, acronym) {
pattern <- str_c("\\b", pattern, "\\b")
patternrex <- str_c("\\b", pattern, "\\b")
if(chars <= 4) {
found <- agrep(pattern, string, max.distance = list(all = 0), ignore.case = !acronym, fixed = FALSE)
if(chars <= 4) { # 4 or less
found <- agrep(patternrex, string, max.distance = list(all = 0), ignore.case = !acronym, fixed = FALSE)
}
else if(chars >= 8) {
found <- agrep(pattern, string, max.distance = list(all = 2), ignore.case = !acronym, fixed = FALSE)
else if(chars >= 8) { # 8 or more
found <- agrep(patternrex, string, max.distance = list(all = 3), ignore.case = !acronym, fixed = FALSE)
# Give longer words a chance by ignoring word boundaries \\b
if(convertLogical0(found) == 0) {
found <- grep(pattern, string, ignore.case = !acronym, fixed = FALSE)
}
}
else {
found <- agrep(pattern, string, max.distance = list(all = 1), ignore.case = !acronym, fixed = FALSE)
else { # 5,6,7
found <- agrep(patternrex, string, max.distance = list(all = 2), ignore.case = !acronym, fixed = FALSE)
}
found <- convertLogical0(found)
return(found)