Return a formatted list of acronyms.
164273
def _get_acronyms(acronyms):
    """"""
    acronyms_str = {}
    if acronyms:
        for acronym, expansions in iteritems(acronyms):
            expansions_str = ", ".join(["%s (%d)" % expansion
                                        for expansion in expansions])
            acronyms_str[acronym] = expansions_str

    return [{'acronym': str(key), 'expansion': value.encode('utf8')}
            for key, value in acronyms_str.iteritems()]
1295507
def get_acronyms(fulltext):
    
    acronyms = {}

    for m in ACRONYM_BRACKETS_REGEX.finditer(fulltext):
        acronym = DOTS_REGEX.sub("", m.group(1))
        potential_expansion = fulltext[m.start() - 80:m.start()].replace("\n",
                                                                         " ")
        # Strip
        potential_expansion = re.sub("(\W).(\W)", "\1\2", potential_expansion)
        potential_expansion = re.sub("(\w)\(s\)\W", "\1", potential_expansion)
        potential_expansion = re.sub("""[^\w'"]+$""", "", potential_expansion)
        potential_expansion = re.sub("[[(].+[\])]", "", potential_expansion)
        potential_expansion = re.sub(" {2,}", " ", potential_expansion)

        # LEVEL 0: expansion between quotes
        # Double quotes
        match = re.search(""""([^"]+)["]$""", potential_expansion)
        if match is None:
            # Single quotes
            match = re.search("""'([^"]+)[']$""", potential_expansion)
        if match is not None:
            if acronym in match.group(1):
                continue

            pattern = ""
            for char in acronym[:-1]:
                pattern += "%s\w+\W*" % char
            pattern += "%s\w+" % acronym[-1]

            if re.search(pattern, match.group(1), re.I) is not None:
                _add_expansion_to_acronym_dict(acronym, match.group(1), 0,
                                               acronyms)
            continue

        pattern = "\W("
        for char in acronym[:-1]:
            pattern += "%s\w+\W+" % char
        pattern += "%s\w+)$" % acronym[-1]

        # LEVEL 1: expansion with uppercase initials
        match = re.search(pattern, potential_expansion)
        if match is not None:
            _add_expansion_to_acronym_dict(
                acronym, match.group(1), 1, acronyms)
            continue

        # LEVEL 2: expansion with initials
        match = re.search(pattern, potential_expansion, re.I)
        if match is not None:
            _add_expansion_to_acronym_dict(
                acronym, match.group(1), 2, acronyms)
            continue

        # LEVEL 3: expansion with initials and STOPLIST
        potential_expansion_stripped = " ".join([word for word in
                                                 _words(potential_expansion) if
                                                 word not in STOPLIST])

        match = re.search(pattern, potential_expansion_stripped, re.I)
        if match is not None:
            first_expansion_word = re.search("\w+", match.group(1)).group()
            start = potential_expansion.lower().rfind(first_expansion_word)
            _add_expansion_to_acronym_dict(
                acronym, potential_expansion[start:],
                3, acronyms
            )
            continue

        # LEVEL 4: expansion with fuzzy initials and stoplist
        reversed_words = _words(potential_expansion_stripped)
        reversed_words.reverse()

        reversed_acronym = list(acronym.lower())
        reversed_acronym.reverse()

        index0 = 0
        index1 = 0
        word = ""
        try:
            while index0 < len(reversed_acronym) and index1 < len(
                    reversed_words):
                word = reversed_words[index1]
                if index0 + 1 < len(reversed_words):
                    next_word = reversed_words[index0 + 1]
                else:
                    next_word = "_"

                char = reversed_acronym[index0]
                if index0 + 1 < len(reversed_acronym):
                    next_char = reversed_acronym[index0 + 1]
                else:
                    next_char = "_"

                if char == next_char and \
                        word.startswith(char) and \
                        word.count(char) > 1 and \
                        not next_word.startswith(char):
                    index0 += 2
                    index1 += 1
                if word.startswith(char):
                    index0 += 1
                    index1 += 1
                elif char in word and \
                        not word.endswith(char) and \
                        word.startswith(next_char):
                    index0 += 2
                    index1 += 1
                else:
                    word = ""
                    break
        except IndexError:
            word = ""

        if not word.startswith(char):
            word = ""

        if word:
            start = potential_expansion.lower().rfind(word)

            _add_expansion_to_acronym_dict(acronym,
                                           potential_expansion[start:], 4,
                                           acronyms)
            continue

        # LEVEL 5: expansion with fuzzy initials
        reversed_words = _words(potential_expansion.lower())
        reversed_words.reverse()

        reversed_acronym = list(acronym.lower())
        reversed_acronym.reverse()

        index0 = 0
        index1 = 0
        word = ""
        try:
            while index0 < len(reversed_acronym) and index1 < len(
                    reversed_words):
                word = reversed_words[index1]
                if index0 + 1 < len(reversed_words):
                    next_word = reversed_words[index0 + 1]
                else:
                    next_word = ""

                char = reversed_acronym[index0]
                if index0 + 1 < len(reversed_acronym):
                    next_char = reversed_acronym[index0 + 1]
                else:
                    next_char = ""

                if char == next_char and word.startswith(char) and \
                   word.count(char) > 1 and \
                   not next_word.startswith(char):
                    index0 += 2
                    index1 += 1
                if word.startswith(char):
                    index0 += 1
                    index1 += 1
                elif char in word and \
                        not word.endswith(char) and \
                        word.startswith(next_char):
                    index0 += 2
                    index1 += 1
                else:
                    word = ""
                    break
        except IndexError:
            word = ""

        if not word.startswith(char):
            word = ""

        if word:
            start = potential_expansion.lower().rfind(word)
            _add_expansion_to_acronym_dict(acronym,
                                           potential_expansion[start:], 5,
                                           acronyms)
            continue

    return acronyms
1102373
def names(self):
        """"""
        if getattr(self, 'key', None) is None:
            result = []
        else:
            result = [self.key]
        if hasattr(self, 'aliases'):
            result.extend(self.aliases)
        return result
877198
def to_strings(self):
        
        result = []

        if not self.expansions:
            result.append(self.name)
        else:
            for expansion in self.expansions:
                result.extend('{}.{}'.format(self.name, es) for es in expansion.to_strings())

        return result
469121
def as_list(self):
        """"""
        go_id = self.go_term.id
        
        qual_str = '|'.join(self.qualifier)
        db_ref_str = '|'.join(self.db_ref)
        taxon_str = '|'.join(self.taxon)

        # with_from is currently left as a string
        # with_from = '|'.join()
        with_from_str = self.with_from or ''
        db_name_str = self.db_name or ''
        db_syn_str = '|'.join(self.db_syn)
        ext_str = '|'.join(self.ext)
        product_id_str = self.product_id or ''

        l = [
            self.db,
            self.db_id,
            self.db_symbol,
            qual_str,
            go_id,
            db_ref_str,
            self.ev_code,
            with_from_str,
            self.aspect,
            db_name_str,
            db_syn_str,
            self.db_type,
            taxon_str,
            self.date,
            self.assigned_by,
            ext_str,
            product_id_str,
        ]
        return l
923740
def format_choices(self):
        """"""
        ce = enumerate(self.choices)
        f = lambda i, c: '%s (%d)' % (c, i+1)
        # apply formatter and append help token
        toks = [f(i,c) for i, c in ce] + ['Help (?)']
        return ' '.join(toks)
664691
def _acronym_lic(self, license_statement):
        """"""
        pat = re.compile(r'\(([\w+\W?\s?]+)\)')
        if pat.search(license_statement):
            lic = pat.search(license_statement).group(1)
            if lic.startswith('CNRI'):
                acronym_licence = lic[:4]
            else:
                acronym_licence = lic.replace(' ', '')
        else:
            acronym_licence = ''.join(
                [w[0]
                 for w in license_statement.split(self.prefix_lic)[1].split()])
        return acronym_licence
724607
def columns(self):
        """"""

        try:
            # For resources that are metapack packages.
            r = self.expanded_url.resource.columns()
            return list(r)
        except AttributeError as e:

            pass

        return self.schema_columns
998501
def _get_formated_symbol(self, symbol):
        
        # pylint: disable=no-self-use

        old_symbols = [
            '\\',
            '.',
            '+',
            '*',
            '?',
            '^',
            '$',
            '[',
            ']',
            '{',
            '}',
            '(',
            ')',
            '|',
            '/',
            ',',
            '!',
            '=',
            ':',
            '-'
        ]
        replace_dict = {
            '\\': '\\\\',
            '.': r'\.',
            '+': r'\+',
            '*': r'\*',
            '?': r'\?',
            '^': r'\^',
            '$': r'\$',
            '[': r'\[',
            ']': r'\]',
            '{': r'\{',
            '}': r'\}',
            '(': r'\(',
            ')': r'\)',
            '|': r'\|',
            '/': r'\/',
            ',': r'\,',
            '!': r'\!',
            '=': r'\=',
            ':': r'\:',
            '-': r'\-'
        }
        for old in old_symbols:
            symbol = symbol.replace(old, replace_dict[old])
        return symbol
514282
def filenames(self):
        """"""
        return [p.name for p in self.packets if isinstance(p, FileDescriptionPacket)]
194406
def channel_names(fn, usecols=None):
    """"""

    with open(fn, 'rb') as fo:
        names = dbfreader(fo).next()

    return usecols and [names[i] for i in usecols] or names
1258923
def _format_attrs(self):
        
        attrs = self._get_data_as_items()
        if self.name is not None:
            attrs.append(('name', ibase.default_pprint(self.name)))
        return attrs
766661
def _GetFileNames(self):
    """"""
    if self._zip:
      return self._zip.namelist()
    else:
      return os.listdir(self._path)
548732
def to_list(self):
        """"""

        ret = OrderedDict()
        for attrname in self.attrs:
            ret[attrname] = self.__getattribute__(attrname)
        return ret
1117889
def format_symbol(symbol):
    """"""
    fixed = []
    s = symbol.strip()
    s = s[0].upper() + s[1:].lower()
    for c in s:
        if c.isalpha():
            fixed.append(' ' + c + ' ')
        elif c.isspace():
            fixed.append(' ')
        elif c.isdigit():
            fixed.append(c)
        elif c == '-':
            fixed.append(' ' + c)
        elif c == '/':
            fixed.append(' ' + c)
    s = ''.join(fixed).strip()
    return ' '.join(s.split())
1242320
def scope_to_list(scope):
    """"""
    if isinstance(scope, (tuple, list, set)):
        return [unicode_type(s) for s in scope]
    elif scope is None:
        return None
    else:
        return scope.strip().split(" ")
295727
def _format_invariants(invariants: List[icontract._Contract]) -> List[str]:
    """"""
    if not invariants:
        return []

    result = [":establishes:"]  # type: List[str]
    for invariant in invariants:
        result.append("    * {}".format(_format_contract(contract=invariant)))

    return result