\name{ConfigShowSimilarVars}
\alias{ConfigShowSimilarVars}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
%%  ~~function to do ... ~~
}
\description{
%%  ~~ A concise (1-5 lines) description of what the function does. ~~
}
\usage{
ConfigShowSimilarVars(configuration, var_name, n_results = 5)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{configuration}{
%%     ~~Describe \code{configuration} here~~
}
  \item{var_name}{
%%     ~~Describe \code{var_name} here~~
}
  \item{n_results}{
%%     ~~Describe \code{n_results} here~~
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
%%  ~Describe the value returned
%%  If it is a LIST, use
%%  \item{comp1 }{Description of 'comp1'}
%%  \item{comp2 }{Description of 'comp2'}
%% ...
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (configuration, var_name, n_results = 5) 
{
    getBigrams <- function(str) {
        bigramlst <- list()
        for (i in 1:(nchar(str) - 1)) {
            bigramlst[[i]] <- substr(str, i, i + 1)
        }
        return(bigramlst)
    }
    strSimilarity <- function(str1, str2) {
        str1 <- tolower(str1)
        str2 <- tolower(str2)
        if (is.null(str1)) {
            str1 <- ""
        }
        else if (is.na(str1)) {
            str1 <- ""
        }
        if (is.null(str2)) {
            str2 <- ""
        }
        else if (is.na(str2)) {
            str2 <- ""
        }
        if (nchar(str1) <= 1 && nchar(str2) <= 1) {
            return(ifelse(str1 == str2, 1, 0))
        }
        else if (nchar(str1) == 1) {
            return(ifelse(grepl(str1, str2, fixed = TRUE), 1, 
                0))
        }
        else if (nchar(str2) == 1) {
            return(ifelse(grepl(str2, str1, fixed = TRUE), 1, 
                0))
        }
        else if (nchar(str1) == 0 || nchar(str2) == 0) {
            return(0)
        }
        else {
            pairs1 <- getBigrams(str1)
            pairs2 <- getBigrams(str2)
            unionlen <- length(pairs1) + length(pairs2)
            hit_count <- 0
            for (x in 1:length(pairs1)) {
                for (y in 1:length(pairs2)) {
                  if (pairs1[[x]] == pairs2[[y]]) {
                    hit_count <- hit_count + 1
                  }
                }
            }
            return((2 * hit_count)/unionlen)
        }
    }
    similarities <- list()
    similarities$two_d_vars <- as.vector(sapply(configuration$two_d_vars, 
        strSimilarity, var_name))
    similarities$global_mean_vars <- as.vector(sapply(configuration$global_mean_var, 
        strSimilarity, var_name))
    n_results <- min(n_results, length(similarities$two_d_vars) + 
        length(similarities$global_mean_vars))
    threshold <- sort(c(similarities$two_d_vars, similarities$global_mean_vars), 
        decreasing = TRUE)[n_results]
    n_minimums <- sum(sort(c(similarities$two_d_vars, similarities$global_mean_vars), 
        decreasing = TRUE)[1:n_results] == threshold)
    matches <- list()
    n_picked_minimums <- 0
    for (var_type in c("two_d_vars", "global_mean_vars")) {
        matches[[var_type]] <- configuration[[var_type]][which(similarities[[var_type]] > 
            threshold)]
        if (n_picked_minimums < n_minimums) {
            minimums <- configuration[[var_type]][which(similarities[[var_type]] == 
                threshold)]
            if (length(minimums) + n_picked_minimums > n_minimums) {
                minimums <- minimums[1:(n_minimums - n_picked_minimums)]
            }
            matches[[var_type]] <- c(matches[[var_type]], minimums)
            n_picked_minimums <- n_picked_minimums + length(minimums)
        }
    }
    ConfigShowVars(matches)
    invisible(matches)
  }
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
