code: def test_candidate_generation(nlp):
      """Test correct candidate generation"""
      mykb = InMemoryLookupKB(nlp.vocab, entity_vector_length=1)
      doc = nlp("douglas adam Adam shrubbery")
  
      douglas_ent = doc[0:1]
      adam_ent = doc[1:2]
      Adam_ent = doc[2:3]
      shrubbery_ent = doc[3:4]
  
      # adding entities
      mykb.add_entity(entity="Q1", freq=27, entity_vector=[1])
      mykb.add_entity(entity="Q2", freq=12, entity_vector=[2])
      mykb.add_entity(entity="Q3", freq=5, entity_vector=[3])
  
      # adding aliases
      mykb.add_alias(
          alias="douglas",
          entities=["Q2", "Q3"],
          probabilities=[0.8, 0.1],
      )
      mykb.add_alias(alias="adam", entities=["Q2"], probabilities=[0.9])
  
      # test the size of the relevant candidates
      assert len(get_candidates(mykb, douglas_ent)) == 2
      assert len(get_candidates(mykb, adam_ent)) == 1
      assert (
          len(get_candidates(mykb, Adam_ent)) == 0
      )  # default case sensitive
      assert len(get_candidates(mykb, shrubbery_ent)) == 0
  
      # test the content of the candidates
      assert get_candidates(mykb, adam_ent)[0].entity_ == "Q2"
      assert get_candidates(mykb, adam_ent)[0].alias_ == "adam"
      assert_almost_equal(
          get_candidates(mykb, adam_ent)[0].entity_freq, 12
      )
      assert_almost_equal(
          get_candidates(mykb, adam_ent)[0].prior_prob, 0.9
      )
  
imports: from typing import Any, Callable, Dict, Iterable, Tuple
  import pytest
  from numpy.testing import assert_equal
  from spacy import Language, registry, util
  from spacy.attrs import ENT_KB_ID
  from spacy.compat import pickle
  from spacy.kb import Candidate, InMemoryLookupKB, KnowledgeBase, get_candidates
  from spacy.lang.en import English
  from spacy.ml import load_kb
  from spacy.ml.models.entity_linker import build_span_maker
  from spacy.pipeline import EntityLinker
  from spacy.pipeline.legacy import EntityLinker_v1
  from spacy.pipeline.tok2vec import DEFAULT_TOK2VEC_MODEL
  from spacy.scorer import Scorer
  from spacy.tests.util import make_tempdir
  from spacy.tokens import Doc, Span
  from spacy.training import Example
  from spacy.util import ensure_path
  from spacy.vocab import Vocab
label_desc: Use image node_id 21 for calling a global function with example usage: test_candidate_generation(nlp) without return types