code: def gen_knowledge_relations(
      InFile_RelatedFieldOfStudy,
      OutFile_dirname,
      entity2idx,
      relation2idx,
  ):
      print(
          "processing file {0}...".format(
              os.path.basename(InFile_RelatedFieldOfStudy)
          ),
          end=" ",
      )
      OutFile_relation_triples = os.path.join(
          OutFile_dirname, "train2id.txt"
      )
      lines = []
      with open(
          InFile_RelatedFieldOfStudy,
          "r",
          encoding="utf-8",
          newline="\r\n",
      ) as rd:
          while True:
              line = rd.readline()
              if not line:
                  break
              words = line.strip("\r\n").split("\t")
              field_idx01 = add2dict(words[0], entity2idx)
              field_idx02 = add2dict(words[2], entity2idx)
              relation_name = "{0}_TO_{1}".format(words[1], words[3])
              relation_idx = add2dict(relation_name, relation2idx)
              lines.append(
                  "{0} {1} {2}\n".format(
                      field_idx01, field_idx02, relation_idx
                  )
              )
      print("done.")
      with open(
          OutFile_relation_triples,
          "w",
          encoding="utf-8",
          newline="\r\n",
      ) as wt:
          wt.write("{0}\n".format(len(lines)))
          for line in lines:
              wt.write(line)
      dump_dict_as_txt(
          entity2idx, os.path.join(OutFile_dirname, "entity2id.txt")
      )
      dump_dict_as_txt(
          relation2idx, os.path.join(OutFile_dirname, "relation2id.txt")
      )
  
imports: import codecs
  import pickle
  import time
  import os
  from datetime import datetime
  import random
  import numpy
  import math
  from multiprocessing import Process
  from utils.general import *
  from utils.data_helper import *
label_desc: Use image node_id 4 for calling a global function with example usage: gen_knowledge_relations(InFile_RelatedFieldOfStudy, OutFile_dirname, entity2idx, relation2idx) without return types