@staticmethod
def _build_char_trie(lexicon):
    """
        Builds a char trie, to cater for wildcard ('*') matches.
        """
    trie = {}
    for pattern, cat_names in lexicon.items():
        cursor = trie
        for char in pattern:
            if char == '*':
                cursor['*'] = cat_names
                break
            if char not in cursor:
                cursor[char] = {}
            cursor = cursor[char]
        cursor['$'] = cat_names
    return trie
