better pattern matching logic

This commit is contained in:
2015-01-21 13:17:24 +01:00
parent a8987936c4
commit 54d1cd79aa
3 changed files with 228 additions and 215 deletions
+19 -14
View File
@@ -26,22 +26,27 @@ convertLogical0 <- function(var) {
return(var)
}
smartPatternMatch <- function(string, pattern, chars, acronym) {
smartPatternMatch <- function(string, pattern, dist, acronym) {
patternrex <- str_c("\\b", pattern, "\\b")
if(chars <= 4) { # 4 or less
found <- agrep(patternrex, string, max.distance = list(all = 0), ignore.case = !acronym, fixed = FALSE)
}
else if(chars >= 8) { # 8 or more
found <- agrep(patternrex, string, max.distance = list(all = 1), 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 { # 5,6,7
found <- agrep(patternrex, string, max.distance = list(all = 1), ignore.case = !acronym, fixed = FALSE)
}
found <- agrep(patternrex, string, max.distance = list(all = dist), 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) { # 8 or more
# found <- agrep(patternrex, string, max.distance = list(all = 1), 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 { # 5,6,7
# found <- agrep(patternrex, string, max.distance = list(all = 1), ignore.case = !acronym, fixed = FALSE)
# }
#
# Convert 0/1 to F/T
found <- convertLogical0(found)
if(found == 1) {
found <- TRUE