def _load_wm_map(exclude_auto=None):
    """Load an ontology map for world models.

    exclude_auto : None or list[tuple]
        A list of ontology mappings for which automated mappings should be
        excluded, e.g. [(HUME, UN)] would result in not using mappings
        from HUME to UN.
    """
    exclude_auto = [] if not exclude_auto else exclude_auto
    path_here = os.path.dirname(os.path.abspath(__file__))
    ontomap_file = os.path.join(path_here, '../resources/wm_ontomap.tsv')
    mappings = {}

    def make_hume_prefix_map():
        hume_ont = os.path.join(path_here, '../sources/hume/hume_ontology.rdf')
        graph = rdflib.Graph()
        graph.parse(os.path.abspath(hume_ont), format='nt')
        entry_map = {}
        for node in graph.all_nodes():
            entry = node.split('#')[1]
            # Handle "event" and other top-level entries
            if '/' not in entry:
                entry_map[entry] = None
                continue
            parts = entry.split('/')
            prefix, real_entry = parts[0], '/'.join(parts[1:])
            entry_map[real_entry] = prefix
        return entry_map

    hume_prefix_map = make_hume_prefix_map()

    def add_hume_prefix(hume_entry):
        """We need to do this because the HUME prefixes are missing"""
        prefix = hume_prefix_map[hume_entry]
        return '%s/%s' % (prefix, hume_entry)

    def map_entry(reader, entry):
        """Remap the readers and entries to match our internal standards."""
        if reader == 'eidos':
            namespace = 'UN'
            entry = entry.replace(' ', '_')
            entry_id = entry
        elif reader == 'BBN':
            namespace = 'HUME'
            entry = entry.replace(' ', '_')
            entry_id = add_hume_prefix(entry)
        elif reader == 'sofia':
            namespace = 'SOFIA'
            # First chop off the Event/Entity prefix
            parts = entry.split('/')[1:]
            # Now we split each part by underscore and capitalize
            # each piece of each part
            parts = ['_'.join([p.capitalize() for p in part.split('_')])
                     for part in parts]
            # Finally we stick the entry back together separated by slashes
            entry_id = '/'.join(parts)
        else:
            return reader, entry
        return namespace, entry_id

    with open(ontomap_file, 'r') as fh:
        for line in fh.readlines():
            # Get each entry from the line
            s, se, t, te, score = line.strip().split('\t')
            score = float(score)
            # Map the entries to our internal naming standards
            s, se = map_entry(s, se)
            t, te = map_entry(t, te)
            # Skip automated mappings when they should be excluded
            if (s, t) not in exclude_auto:
                # We first do the forward mapping
                if (s, se, t) in mappings:
                    if mappings[(s, se, t)][1] < score:
                        mappings[(s, se, t)] = ((t, te), score)
                else:
                    mappings[(s, se, t)] = ((t, te), score)
            # Then we add the reverse mapping
            if (t, s) not in exclude_auto:
                if (t, te, s) in mappings:
                    if mappings[(t, te, s)][1] < score:
                        mappings[(t, te, s)] = ((s, se), score)
                else:
                    mappings[(t, te, s)] = ((s, se), score)
    ontomap = []
    for s, ts in mappings.items():
        ontomap.append(((s[0], s[1]), ts[0], ts[1]))

    # Now apply the Hume -> Eidos override
    override_file = os.path.join(path_here, '../resources/wm_ontomap.bbn.tsv')
    override_mappings = []
    with open(override_file, 'r') as fh:
        for row in fh.readlines():
            if 'BBN' not in row:
                continue
            # Order is target first, source second
            _, te, _, se = row.strip().split('\t')
            # Map the entries to our internal naming standards
            s = 'HUME'
            t = 'UN'
            se = se.replace(' ', '_')
            te = te.replace(' ', '_')
            if se.startswith('/'):
                se = se[1:]
            override_mappings.append((s, se, t, te))
    for s, se, t, te in override_mappings:
        found = False
        for idx, ((so, seo), (eo, teo), score) in enumerate(ontomap):
            if (s, se, t) == (so, seo, eo):
                # Override when a match is found
                ontomap[idx] = ((s, se), (t, te), 1.0)
                found = True
        if not found:
            ontomap.append(((s, se), (t, te), 1.0))
    return ontomap
Load an ontology map for world models.

    exclude_auto : None or list[tuple]
        A list of ontology mappings for which automated mappings should be
        excluded, e.g. [(HUME, UN)] would result in not using mappings
        from HUME to UN.