code: def build_kb_db(babi):
      """
      Build a searchable database from the kb files to be used in interactive mode
      """
      with open(babi.kb_file, "r") as f:
          kb_text = f.readlines()
  
      kb_text = [x.replace("\t", " ") for x in kb_text]
  
      db = {}
  
      property_types = set(x.split(" ")[2] for x in kb_text)
  
      for ptype in property_types:
          unique_props = set(
              x.split(" ")[3].strip()
              for x in kb_text
              if ptype in x.strip().split(" ")
          )
  
          db[ptype] = {
              prop: [
                  x
                  for idx, x in enumerate(kb_text)
                  if prop in x.strip().split(" ")
              ]
              for prop in unique_props
          }
          db[ptype][ptype] = kb_text
  
      resto_names = set(x.split(" ")[1] for x in kb_text)
      names_to_idxs = {}
      for name in resto_names:
          names_to_idxs[name] = [
              idx
              for idx, x in enumerate(kb_text)
              if name in x.strip().split(" ")
          ]
  
      kb_text_clean = np.array(
          [" ".join(x.strip().split(" ")[1:]) for x in kb_text]
      )
  
      return db, names_to_idxs, kb_text_clean
  
file_path: nlp-architect/examples/memn2n_dialogue/interactive_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import itertools
  from builtins import input
  from copy import copy
  from functools import reduce
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: build_kb_db(babi) and returns: db,  names_to_idxs,  kb_text_clean