original_docstring: Return a KB, which is a nested dictionary so that kb[rel][entity1]
    is mapped to the set of entities entity2 such that
    rel(entity1,entity2) is true.
    
docstring: Return a KB, which is a nested dictionary so that kb[rel][entity1]
  is mapped to the set of entities entity2 such that
  rel(entity1,entity2) is true.
docstring_tokens: Return a KB which is a nested dictionary so that kb [ rel ] [ entity1 ] is mapped to the set of entities entity2 such that rel ( entity1 entity2 ) is true .
code: def load_kb():
    """Return a KB, which is a nested dictionary so that kb[rel][entity1]
    is mapped to the set of entities entity2 such that
    rel(entity1,entity2) is true.
    """
    kb = collections.defaultdict(lambda:collections.defaultdict(set))
    for line in open('movieqa/knowledge_source/wiki_entities/wiki_entities_kb.txt'):
      line = line.strip()
      if len(line)>0:
        line = trim_digits(line)
        for rel in RELS:
          k = line.find(rel)
          if k>=0:
            sub = line[:k-1]
            sub = " ".join(simple_tokenize(sub))
            assert len(sub)>0, "empty movie in line %r" % line
            obj = line[k+len(rel)+1:]
            assert len(obj)>0, "empty object part in line %r" % line
            if rel=='has_plot':
              objs = set(simple_tokenize(obj.lower())) - STOP_WORDS
            else:
              objs = obj.split(", ")
            for o in objs:
              assert len(obj)>0, "empty object in object part %r in line %r" % (objs,line)
              kb[rel][sub].add(o)
    # Duplicate some things that are named wrong in the answers files,
    # i.e. give them aliases that match the incorrect versions of these
    # entities.
    for rel in RELS:
      for sub in ERRORS:
        kb[rel][ERRORS[sub]] = kb[rel][sub]
    print('loaded kb')
    return kb
code_tokens: def load_kb ( ) : kb = collections . defaultdict ( lambda : collections . defaultdict ( set ) ) for line in open ( 'movieqa/knowledge_source/wiki_entities/wiki_entities_kb.txt' ) : line = line . strip ( ) if len ( line ) > 0 : line = trim_digits ( line ) for rel in RELS : k = line . find ( rel ) if k >= 0 : sub = line [ : k - 1 ] sub = " " . join ( simple_tokenize ( sub ) ) assert len ( sub ) > 0 , "empty movie in line %r" % line obj = line [ k + len ( rel ) + 1 : ] assert len ( obj ) > 0 , "empty object part in line %r" % line if rel == 'has_plot' : objs = set ( simple_tokenize ( obj . lower ( ) ) ) - STOP_WORDS else : objs = obj . split ( ", " ) for o in objs : assert len ( obj ) > 0 , "empty object in object part %r in line %r" % ( objs , line ) kb [ rel ] [ sub ] . add ( o ) for rel in RELS : for sub in ERRORS : kb [ rel ] [ ERRORS [ sub ] ] = kb [ rel ] [ sub ] print ( 'loaded kb' ) return kb
short_docstring: Return a KB, which is a nested dictionary so that kb[rel][entity1]
  is mapped to the set of entities entity2 such that
  rel(entity1,entity2) is true.
short_docstring_tokens: Return a KB which is a nested dictionary so that kb [ rel ] [ entity1 ] is mapped to the set of entities entity2 such that rel ( entity1 entity2 ) is true .
comment: """Return a KB, which is a nested dictionary so that kb[rel][entity1]
    is mapped to the set of entities entity2 such that
    rel(entity1,entity2) is true.
    """$SEP$# Duplicate some things that are named wrong in the answers files,$SEP$# i.e. give them aliases that match the incorrect versions of these$SEP$# entities.