code: def generateSimilar(corpus, index, method):
      for docNo, topSims in enumerate(index):  # for each document
          # store similarities to the following file
          outfile = os.path.join(
              corpus.articleDir(docNo), "similar_%s.xml" % method
          )
  
          articles = []  # collect similars in this list
          for docNo2, score in topSims:  # for each most similar article
              if score > MIN_SCORE and docNo != docNo2:
                  source, (intId, pathId) = corpus.documents[docNo2]
                  meta = corpus.getMeta(docNo2)
                  suffix, author, title = (
                      "",
                      meta.get("author", ""),
                      meta.get("title", ""),
                  )
                  articles.append(
                      ARTICLE % locals()
                  )  # add the similar article to output
                  if len(articles) >= MAX_SIMILAR:
                      break
  
          # now `articles` holds multiple strings in similar_*.xml format
          if SAVE_EMPTY or articles:
              output = "".join(
                  articles
              )  # concat all similars to one string
              if (
                  not DRY_RUN
              ):  # only open output files for writing if DRY_RUN is false
                  logging.info(
                      "generating %s (%i similars)",
                      outfile,
                      len(articles),
                  )
                  outfile = open(outfile, "w")
                  outfile.write(
                      SIMILAR % output
                  )  # add xml headers and print to file
                  outfile.close()
              else:
                  logging.info(
                      "would be generating %s (%i similars):%s\n",
                      outfile,
                      len(articles),
                      output,
                  )
          else:
              logging.debug("skipping %s (no similar found)", outfile)
  
imports: import logging
  import sys
  import os.path
  from gensim.corpora import dmlcorpus, MmCorpus
  from gensim.similarities import MatrixSimilarity, SparseMatrixSimilarity
  import gensim_build
label_desc: Use image node_id 1 for calling a global function with example usage: generateSimilar(corpus, index, method) without return types