def _getConfigSoundingLike(self, config_name):
        """return a list of existing server config names sounding like config_name"""
        available_configs = self._list_available_server_config_files()

        clean_config_name = config_name.strip().lower()

        # exact match
        if clean_config_name in available_configs:
            return [clean_config_name]

        # substring match
        matching_subset = [x for x in available_configs if clean_config_name in x.lower()]
        if len(matching_subset) == 1:
            matches = [matching_subset[0]]
        elif len(matching_subset) > 1:
            matches = matching_subset
        else:
            # no luck with subset search, fallback on soundex magic
            soundex_query = soundex(clean_config_name)
            matches = [name for name in available_configs if soundex(name) == soundex_query]

        # got nothing ? suggest available config names
        if not len(matches):
            matches = available_configs

        # order what we came up with by levenshtein distance
        if len(matches):
            matches.sort(key=lambda name: levenshteinDistance(clean_config_name, name))

        return matches
Пример #2
0
    def getMapsSoundingLike(self, mapname):
        """found matching level names for the given mapname (which can either
        be a level name or map name)
        If no exact match is found, then return close candidates using soundex
        and then LevenshteinDistance algoritms
        """
        supportedMaps = self.getSupportedMaps()
        supportedEasyNames = {}
        for m in supportedMaps:
            supportedEasyNames[self.getEasyName(m)] = m

        data = mapname.strip()
        soundex1 = soundex(data)
        #self.debug('soundex %s : %s' % (data, soundex1))

        match = []
        if data in supportedMaps:
            match = [data]
        elif data in supportedEasyNames:
            match = [supportedEasyNames[data]]
        else:
            for m in supportedEasyNames:
                s = soundex(m)
                #self.debug('soundex %s : %s' % (m, s))
                if s == soundex1:
                    #self.debug('probable map : %s', m)
                    match.append(supportedEasyNames[m])

        if len(match) == 0:
            # suggest closest spellings
            shortmaplist = []
            for m in supportedEasyNames:
                if m.find(data) != -1:
                    shortmaplist.append(m)
            if len(shortmaplist) > 0:
                shortmaplist.sort(key=lambda map: levenshteinDistance(
                    data, string.replace(map.strip())))
                self.debug("shortmaplist sorted by distance : %s" %
                           shortmaplist)
                match = shortmaplist[:3]
            else:
                easyNames = supportedEasyNames.keys()
                easyNames.sort(
                    key=lambda map: levenshteinDistance(data, map.strip()))
                self.debug("maplist sorted by distance : %s" % easyNames)
                match = easyNames[:3]
        return match
Пример #3
0
    def getMapsSoundingLike(self, mapname, client=None):
        maplist = self._getMapList(client)

        data = mapname.strip()

        soundex1 = soundex(
            string.replace(string.replace(data, 'ut4_', ''), 'ut_', ''))

        match = []
        if data in maplist:
            match = [data]
        else:
            for m in maplist:
                s = soundex(
                    string.replace(string.replace(m, 'ut4_', ''), 'ut_', ''))
                if s == soundex1:
                    match.append(m)

        if len(match) == 0:
            # suggest closest spellings
            shortmaplist = []
            for m in maplist:
                if m.find(data) != -1:
                    shortmaplist.append(m)
            if len(shortmaplist) > 0:
                shortmaplist.sort(key=lambda map: levenshteinDistance(
                    data,
                    string.replace(string.replace(map.strip(), 'ut4_', ''),
                                   'ut_', '')))
                self.debug("shortmaplist sorted by distance : %s" %
                           shortmaplist)
                match = shortmaplist[:3]
            else:
                maplist.sort(key=lambda map: levenshteinDistance(
                    data,
                    string.replace(string.replace(map.strip(), 'ut4_', ''),
                                   'ut_', '')))
                self.debug("maplist sorted by distance : %s" % maplist)
                match = maplist[:3]
            # we have the list sorted by distance. check if the first one match
            if len(match) > 1:
                if string.replace(string.replace(match[0].lower(), 'ut4_', ''),
                                  'ut_', '') == data.lower():
                    return match[0]

        return match
Пример #4
0
 def getMapsSoundingLike(self, mapname):
     """found matching level names for the given mapname (which can either
     be a level name or map name)
     If no exact match is found, then return close candidates using soundex
     and then LevenshteinDistance algoritms
     """
     supportedMaps = self.getSupportedMaps()
     supportedEasyNames = {}
     for m in supportedMaps:
         supportedEasyNames[self.getEasyName(m)] = m
         
     data = mapname.strip()
     soundex1 = soundex(data)
     #self.debug('soundex %s : %s' % (data, soundex1))
     
     match = []
     if data in supportedMaps:
         match = [data]
     elif data in supportedEasyNames:
         match = [supportedEasyNames[data]]
     else:
         for m in supportedEasyNames:
             s = soundex(m)
             #self.debug('soundex %s : %s' % (m, s))
             if s == soundex1:
                 #self.debug('probable map : %s', m)
                 match.append(supportedEasyNames[m])
     
     if len(match) == 0:
         # suggest closest spellings
         shortmaplist = []
         for m in supportedEasyNames:
             if m.find(data) != -1:
                 shortmaplist.append(m)
         if len(shortmaplist) > 0:
             shortmaplist.sort(key=lambda map: levenshteinDistance(data, string.replace(map.strip())))
             self.debug("shortmaplist sorted by distance : %s" % shortmaplist)
             match = shortmaplist[:3]
         else:
             easyNames = supportedEasyNames.keys()
             easyNames.sort(key=lambda map: levenshteinDistance(data, map.strip()))
             self.debug("maplist sorted by distance : %s" % easyNames)
             match = easyNames[:3]
     return match
Пример #5
0
def locateMap(maplist, mapname):
    data = mapname.strip()

    soundex1 = soundex(string.replace(string.replace(data, "ut4_", ""), "ut_", ""))

    match = []
    if data in maplist:
        match = [data]
    else:
        for m in maplist:
            s = soundex(string.replace(string.replace(m, "ut4_", ""), "ut_", ""))
            if s == soundex1:
                match.append(m)

    if len(match) == 0:
        # suggest closest spellings
        shortmaplist = []
        for m in maplist:
            if m.find(data) != -1:
                shortmaplist.append(m)
        if len(shortmaplist) > 0:
            shortmaplist.sort(
                key=lambda map: levenshteinDistance(
                    data, string.replace(string.replace(map.strip(), "ut4_", ""), "ut_", "")
                )
            )
            match = shortmaplist[:3]
        else:
            maplist.sort(
                key=lambda map: levenshteinDistance(
                    data, string.replace(string.replace(map.strip(), "ut4_", ""), "ut_", "")
                )
            )
            match = maplist[:3]

    if len(match) > 1:
        raise Exception("do you mean : %s" % string.join(match, ", "))
    if len(match) == 1:
        mapname = match[0]
    else:
        raise Exception("^7cannot find any map like [^4%s^7]." % data)

    return mapname
Пример #6
0
def locateMap(maplist, mapname):
    data = mapname.strip()

    soundex1 = soundex(
        string.replace(string.replace(data, 'ut4_', ''), 'ut_', ''))

    match = []
    if data in maplist:
        match = [data]
    else:
        for m in maplist:
            s = soundex(
                string.replace(string.replace(m, 'ut4_', ''), 'ut_', ''))
            if s == soundex1:
                match.append(m)

    if len(match) == 0:
        # suggest closest spellings
        shortmaplist = []
        for m in maplist:
            if m.find(data) != -1:
                shortmaplist.append(m)
        if len(shortmaplist) > 0:
            shortmaplist.sort(key=lambda map: levenshteinDistance(
                data,
                string.replace(string.replace(map.strip(), 'ut4_', ''), 'ut_',
                               '')))
            match = shortmaplist[:3]
        else:
            maplist.sort(key=lambda map: levenshteinDistance(
                data,
                string.replace(string.replace(map.strip(), 'ut4_', ''), 'ut_',
                               '')))
            match = maplist[:3]

    if len(match) > 1:
        raise Exception('do you mean : %s' % string.join(match, ', '))
    if len(match) == 1:
        mapname = match[0]
    else:
        raise Exception('^7cannot find any map like [^4%s^7].' % data)

    return mapname
Пример #7
0
    def _getConfigSoundingLike(self, config_name):
        """return a list of existing server config names sounding like config_name"""
        available_configs = self._list_available_server_config_files()

        clean_config_name = config_name.strip().lower()

        # exact match
        if clean_config_name in available_configs:
            return [clean_config_name]

        # substring match
        matching_subset = [
            x for x in available_configs if clean_config_name in x.lower()
        ]
        if len(matching_subset) == 1:
            matches = [matching_subset[0]]
        elif len(matching_subset) > 1:
            matches = matching_subset
        else:
            # no luck with subset search, fallback on soundex magic
            soundex_query = soundex(clean_config_name)
            matches = [
                name for name in available_configs
                if soundex(name) == soundex_query
            ]

        # got nothing ? suggest available config names
        if not len(matches):
            matches = available_configs

        # order what we came up with by levenshtein distance
        if len(matches):
            matches.sort(
                key=lambda name: levenshteinDistance(clean_config_name, name))

        return matches
Пример #8
0
    def getMapsSoundingLike(self, mapname, client=None):
        maplist = self._parent.getMapList()
                
        data = mapname.strip()

        soundex1 = soundex(string.replace(string.replace(data, 'ut4_',''), 'ut_',''))

        match = []
        if data in maplist:
            match = [data]
        else:
            for m in maplist:
                s = soundex(string.replace(string.replace(m, 'ut4_',''), 'ut_',''))
                if s == soundex1:
                    match.append(m)

        if len(match) == 0:
        # suggest closest spellings
            shortmaplist = []
            for m in maplist:
                if m.find(data) != -1:
                    shortmaplist.append(m)
            if len(shortmaplist) > 0:
                shortmaplist.sort(key=lambda map: levenshteinDistance(data, string.replace(string.replace(map.strip(), 'ut4_',''), 'ut_','')))
                self._parent.debug("shortmaplist sorted by distance : %s" % shortmaplist)
                match = shortmaplist[:3]
            else:
                maplist.sort(key=lambda map: levenshteinDistance(data, string.replace(string.replace(map.strip(), 'ut4_',''), 'ut_','')))
                self._parent.debug("maplist sorted by distance : %s" % maplist)
                match = maplist[:3]
            # we have the list sorted by distance. check if the first one match
            if len(match)>1:
                if string.replace(string.replace(match[0].lower(), 'ut4_',''), 'ut_','') == data.lower():
                    return match[0]
        
        return match