If species name was "Homo sapiens" then replace spaces with underscores
    and return "homo_sapiens". Also replace common names like "human" with
    "homo_sapiens".
181177
def normalize_species_name(name):
    
    lower_name = name.lower().strip()

    # if given a common name such as "human", look up its latin equivalent
    if lower_name in Species._common_names_to_species:
        return Species._common_names_to_species[lower_name].latin_name

    return lower_name.replace(" ", "_")
178917
def _process_name(name):
    """"""

    # Unescape HTML entities
    name = unescape(name)

    # Remove bracketed stuff on the end
    name = NG_RE.sub('', name).strip()  # Nomenclature groups
    name = END_RE.sub('', name).strip(', ')  # Words
    name = RATIO_RE.sub('', name).strip(', ')  # Ratios

    # Remove stuff off start
    name = START_RE.sub('', name).strip()

    # Remove balanced start and end brackets if none in between
    name = BRACKET_RE.sub('\g<1>', name)

    # Un-invert CAS style names
    comps = name.split(', ')
    if len(comps) == 2:
        if comps[1].endswith('-'):
            name = comps[0]
            name = '%s%s' % (comps[1], name)
    elif len(comps) > 2:
        name = comps[0]
        for i in range(1, len(comps)):
            if comps[i].endswith('-'):
                name = '%s%s' % (comps[i], name)
            else:
                name = '%s %s' % (name, comps[i])
    return name
935471
def normalize_whitespace(self, value):
        """"""
        if isinstance(value, unicode):
            return u" ".join(
                x for x in re.split(r'\s+', value, flags=re.UNICODE) if
                len(x)
            )
        else:
            return " ".join(value.split())
1121377
def _normalize(self, name):
        
        name = re.sub(
            r'^(Senator|Representative|Sen\.?|Rep\.?|'
            'Hon\.?|Right Hon\.?|Mr\.?|Mrs\.?|Ms\.?|L\'hon\.?|'
            'Assembly(member|man|woman)) ',
            '',
            name)
        return name.strip().lower().replace('.', '')
738120
def decode_name(s):
    """"""
    # Some names contain XML-like entity codes
    return re.sub(r'&#(\d+);', lambda x: chr(int(x.group(1))), s)
1363756
def _filter_name(name):
    """"""
    # Remove if length 3 or less
    if len(name) <= 3:
        return False
    # Remove if starts with IL-
    if name.startswith('IL-'):
        return False
    lowname = name.lower()
    # Remove if contains certain sequences
    if any(c in lowname for c in STOP_SUB):
        return False
    # Remove if (case-insensitive) exact match to stoplist
    if lowname in STOPLIST:
        return False
    comps = re.split('[ -]', lowname)
    # Remove if just single character + digits separated by spaces or hyphens (or the word compound)
    if all(c.isdigit() or len(c) == 1 or c == 'compound' for c in comps):
        return False
    # Remove if 3 or fewer letters with 2 or fewer digits
    if len(comps) == 2 and len(comps[0]) <= 3 and comps[0].isalpha() and len(comps[1]) <= 3 and comps[1].isdigit():
        return False
    # Remove if just greek characters and numbrs
    if re.match('^[Α-Ωα-ω0-9]+$', name):
        return False
    # Filter registry numbers? No real size benefit in DAWG.
    # if REG_RE.search(name):
    #     keep = False
    # Handle this at the token level
    # if name.endswith(' derivative') or name.endswith(' analog') or name.endswith(' solution'):
    #     keep = False
    # Filter this after matching and expanding boundaries
    # if name.startswith('-') or name.endswith('-'):
    #     keep = False
    # Filter this after matching and expanding boundaries
    # if not bracket_level(name) == 0:
    #     print(name)
    return True
1319103
def namespace_to_regex(namespace):
    """"""
    db_name, coll_name = namespace.split(".", 1)
    # A database name cannot contain a '.' character
    db_regex = re.escape(db_name).replace(r"\*", "([^.]*)")
    # But a collection name can.
    coll_regex = re.escape(coll_name).replace(r"\*", "(.*)")
    return re.compile(r"\A" + db_regex + r"\." + coll_regex + r"\Z")
831862
def match_replace_regex(regex, src_namespace, dest_namespace):
    """"""
    match = regex.match(src_namespace)
    if match:
        return dest_namespace.replace("*", match.group(1))
    return None
1241344
def replace_name(expr: AST, old_name: str, new_name: str) -> AST:
    """"""
    return _NameReplacer(old_name, new_name).visit(deepcopy(expr))
249101
function(result){
  if(!result) return result;
  result.index = result.index + 2;
  var s = result[0];  
  result[0] = s
    .substr(2,s.length-4) // Skip the first two chars ([[) and omit the last ones (]])
    .replace(/\s+/g, '_'); // Every space will be replaced by an underscore
  return result;
}
1270644
def untranslateName(s):
    """"""

    s = s.replace('DOT', '.')
    s = s.replace('DOLLAR', '$')
    # delete 'PY' at start of name components
    if s[:2] == 'PY': s = s[2:]
    s = s.replace('.PY', '.')
    return s
639164
def _reduce_name(cls, name, parse_dict):
        
        # Now remove all found entries to make basename regex have an easier time
        removal_indices = []
        for section, match in iteritems(parse_dict):
            try:
                matches = []
                if isinstance(match, dict) and 'compound_matches' in match:
                    matches = match.get('compound_matches')
                elif not isinstance(match, list) and match is not None:
                    matches = [match]

                for m in matches:
                    valid_slice = True
                    slice_a, slice_b = m.get('position')
                    # Adjust slice positions from previous slices
                    if removal_indices is []:
                        removal_indices.append((slice_a, slice_b))

                    for r_slice_a, r_slice_b in removal_indices:
                        if slice_a == r_slice_a and slice_b == r_slice_b:
                            valid_slice = False
                        if slice_a > r_slice_a or slice_a > r_slice_b or slice_b > r_slice_b or slice_b > r_slice_a:
                            slice_delta = r_slice_b - r_slice_a
                            slice_a -= slice_delta
                            slice_b -= slice_delta

                    if valid_slice:
                        name = cls._string_remove_slice(name, slice_a, slice_b)
                        removal_indices.append((slice_a, slice_b))
            except (IndexError, TypeError):
                pass
        return name
601686
def _name_matches(name, matches):
    '''
    
    '''
    for m in matches:
        if name.endswith(m):
            return True
        if name.lower().endswith('_' + m.lower()):
            return True
        if name.lower() == m.lower():
            return True
    return False
1131843
def sanitizer(name, replacements=[(':','_'), ('/','_'), ('\\','_')]):
    
    for old,new in replacements:
        name = name.replace(old,new)
    return name
746507
function replace(targetStr, searchStr, replaceStr, nPrev, nNext) {
  let result = targetStr;
  for (let i = 0; i < result.length; ++i) {
    if (result.substr(i, searchStr.length) === searchStr &&
      checkSubStr(result, i - nPrev.length, nPrev) === false &&
      checkSubStr(result, i + searchStr.length, nNext) === false) {
      result = result.slice(0, i) + replaceStr + result.slice(i + searchStr.length);
    }
  }
  return result;
}
191197
private boolean matchesSpecies(final NamespaceHeader hdr, int species) {
        final String speciesHdr = hdr.getNamespaceBlock().getSpeciesString();

        // empty header, no match
        if (noLength(speciesHdr)) {
            return false;
        }

        // non-numeric, no match
        if (!isNumeric(speciesHdr)) {
            return false;
        }

        // convert and match
        int v = Integer.parseInt(speciesHdr);
        return v == species;
    }
1243959
def convert_to_humanized_name(name, suffix)
      name.gsub(/\.#{::Regexp.quote(suffix)}$/i, '').tr('_', ' ').strip
    end