sanitize a word by removing its accents, special characters, etc
346602
def sanitize_word(word):
    
    # use an unicode string for `unidecode`
    if type(word) == str:
        try:
            word = word.decode()
        except AttributeError:
            pass  # Python3

    # remove trailing spaces
    word = word.strip()

    # remove stuff between parentheses
    word = re.sub(r'\([^)]*\)', '', word)

    # remove accents, hyphens & other special chars
    word = re.sub(r'[ "\'-;.]+', '', unidecode(word))

    # only lowercase
    return word.lower()
567095
def remove_accent_string(string):
    
    return utils.join([add_accent_char(c, Accent.NONE) for c in string])
565205
def clean_text(s):
    """"""
    SPACES_RE = re.compile(r'\s+')
    SPECIAL_CHARS_RE = re.compile(r'[^\w\s\.\-\(\)]')
    s = SPACES_RE.sub(' ', s)
    s = s.strip()
    s = SPECIAL_CHARS_RE.sub('', s)
    return s
65552
def _normalize(self, string):
		'''  '''

		string = string.replace(u'\xa0', '')
		string = string.strip()
		return string
1336307
def clean_string(text):
    
    if isinstance(text, six.string_types):
        return text.translate(UNI_SPECIAL_CHARS).strip()
    return text.translate(None, STR_SPECIAL_CHARS).strip()
791623
def _remove_accents(filename):
    
    # noinspection PyBroadException
    try:
        filename = filename.replace(" ", "_")
        if isinstance(filename, type(six.u(''))):
            unicode_filename = filename
        else:
            unicode_filename = six.u(filename)
        cleaned_filename = unicodedata.normalize('NFKD', unicode_filename).encode('ASCII', 'ignore').decode('ASCII')

        cleaned_filename = re.sub(r'[^\w\s-]', '', cleaned_filename.strip().lower())
        cleaned_filename = re.sub(r'[-\s]+', '-', cleaned_filename)

        return cleaned_filename
    except:
        traceback.print_exc()
        return filename
1148052
def strip_accents(s, encoding= 'utf-8'):
    """"""
    if sys.version < '3':
        if isinstance(s,unicode):
           return unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore')
        else:
           return unicodedata.normalize('NFKD', unicode(s,encoding)).encode('ASCII', 'ignore')
    else:
        if isinstance(s,bytes): s = str(s,encoding)
        return str(unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore'),'ascii')
750324
private static String sanitizeString(final String in) {
    String result = null;
    if (in != null) {
      result = in.replace(':', '_');
      result = result.replace('/', '_');
      result = result.replace('\\', '_');
    }
    return result;
  }
237370
def clean(self, text):
        """"""
        return ''.join([c for c in text if c in self.alphabet])
425400
function sanitize(lang, filter) {
  if(!(typeof lang == 'string')) return lang;
  lang = lang.replace(/\..*$/, '').toLowerCase();
  if(typeof filter == 'function') {
    lang = filter(lang);
  }
  return lang;
}
983435
def sanitize(meta, diagnostics=False):
    
    bad_encodings, bad_fields = set(), set()

    def sane_encoding(field, text):
        "Transcoding helper."
        for encoding in ('utf-8', meta.get('encoding', None), 'cp1252'):
            if encoding:
                try:
                    u8_text = text.decode(encoding).encode("utf-8")
                    if encoding != 'utf-8':
                        bad_encodings.add(encoding)
                        bad_fields.add(field)
                    return u8_text
                except UnicodeError:
                    continue
        else:
            # Broken beyond anything reasonable
            bad_encodings.add('UNKNOWN/EXOTIC')
            bad_fields.add(field)
            return str(text, 'utf-8', 'replace').replace('\ufffd', '_').encode("utf-8")

    # Go through all string fields and check them
    for field in ("comment", "created by"):
        if field in meta:
            meta[field] = sane_encoding(field, meta[field])

    meta["info"]["name"] = sane_encoding('info name', meta["info"]["name"])

    for entry in meta["info"].get("files", []):
        entry["path"] = [sane_encoding('file path', i) for i in entry["path"]]

    return (meta, bad_encodings, bad_fields) if diagnostics else meta
634979
def clean(some_string, uppercase=False):
    
    if uppercase:
        return some_string.strip().upper()
    else:
        return some_string.strip().lower()
474260
def normalize(name):
    """"""

    # Name should not contain some specials chars (issue #1068)
    ret = name.replace(':', '')
    ret = ret.replace('%', '')
    ret = ret.replace(' ', '_')

    return ret
920559
function sanitiseString($string)
    {
        $search = array('–', '’');
        $replace = array('-', '\'');
        $string = str_replace($search, $replace, $string);
        return $string;
    }
466337
def clean_text(text):
    """"""
    # Replace a few nasty unicode characters with their ASCII equivalent
    maps = {u'×': u'x', u'–': u'-', u'−': '-'}
    for element in maps:
        text = text.replace(element, maps[element])

    # Replace genitives
    text = re.sub(r'(?<=\w)\'s\b|(?<=\w)s\'(?!\w)', '  ', text)

    logging.debug(u'Clean text: "%s"', text)

    return text
595777
def _sanitize_to_unicode(obj):
        
        if isinstance(obj, dict):
            return dict((BaseGELFHandler._sanitize_to_unicode(k), BaseGELFHandler._sanitize_to_unicode(v)) for k, v in obj.items())
        if isinstance(obj, (list, tuple)):
            return obj.__class__([BaseGELFHandler._sanitize_to_unicode(i) for i in obj])
        if isinstance(obj, data):
            obj = obj.decode('utf-8', errors='replace')
        return obj
252558
private String sanitizeWord(String word) {
    String result = word;

    //Find the last part of the word that is not nothing
    //Skip words ending in a dash as they'll be misrecognized
    if (!word.endsWith("-")) {
      String[] splitWord = word.split("-");
      String lastPart = splitWord.length > 1 && !splitWord[splitWord.length - 1].trim().equals("") ? splitWord[splitWord.length - 1] : word;

      //Find only the actual important part of the word
      List<String> compoundedWord = compoundTokenizer.tokenize(lastPart);
      if (compoundedWord.size() > 1) {
        lastPart = StringTools.uppercaseFirstChar(compoundedWord.get(compoundedWord.size() - 1));
      } else {
        lastPart = compoundedWord.get(compoundedWord.size() - 1);
      }

      //Only give result if the last part is either a noun or an adjective (or adjective written in Uppercase)
      List<TaggedWord> tagged = tag(lastPart);
      if (tagged.size() > 0 && (StringUtils.startsWithAny(tagged.get(0).getPosTag(), "SUB", "ADJ") || matchesUppercaseAdjective(lastPart))) {
        result = lastPart;
      }
    }
    return result;
  }