code: def test_query_topn():
      X = np.array(
          [
              ["a", "y", "b"],
              ["b", "y", "a"],
              ["a", "y", "c"],
              ["c", "y", "a"],
              ["a", "y", "d"],
              ["c", "x", "d"],
              ["b", "y", "c"],
              ["f", "y", "e"],
              ["a", "z", "f"],
              ["c", "z", "f"],
              ["b", "z", "f"],
          ]
      )
  
      model = ScoringBasedEmbeddingModel(
          eta=5, k=10, scoring_type="ComplEx"
      )
  
      model.compile(optimizer="adam", loss="multiclass_nll")
  
      model.fit(X, batch_size=2, epochs=10)
  
      with pytest.raises(ValueError):  # Model not fitted
          query_topn(model, top_n=2)
  
      with pytest.raises(ValueError):
          query_topn(model, top_n=2)
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, head="a")
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, relation="y")
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, tail="e")
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, head="a", relation="y", tail="e")
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, head="xx", relation="y")
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, head="a", relation="yakkety")
      with pytest.raises(ValueError):
          query_topn(model, top_n=2, head="a", tail="sax")
      with pytest.raises(ValueError):
          query_topn(
              model,
              top_n=2,
              head="a",
              relation="x",
              rels_to_consider=["y", "z"],
          )
      with pytest.raises(ValueError):
          query_topn(
              model,
              top_n=2,
              head="a",
              tail="f",
              rels_to_consider=["y", "z", "error"],
          )
      with pytest.raises(ValueError):
          query_topn(
              model, top_n=2, head="a", tail="e", rels_to_consider="y"
          )
      with pytest.raises(ValueError):
          query_topn(
              model,
              top_n=2,
              head="a",
              relation="x",
              ents_to_consider=["zz", "top"],
          )
      with pytest.raises(ValueError):
          query_topn(
              model,
              top_n=2,
              head="a",
              tail="e",
              ents_to_consider=["a", "b"],
          )
  
      subj, pred, obj, top_n = "a", "x", "e", 3
  
      Y, S = query_topn(model, top_n=top_n, head=subj, relation=pred)
      assert len(Y) == len(S)
      assert len(Y) == top_n
      assert np.all(Y[:, 0] == subj)
      assert np.all(Y[:, 1] == pred)
  
      Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj)
      assert np.all(Y[:, 1] == pred)
      assert np.all(Y[:, 2] == obj)
  
      ents_to_con = ["a", "b", "c", "d"]
      Y, S = query_topn(
          model,
          top_n=top_n,
          relation=pred,
          tail=obj,
          ents_to_consider=ents_to_con,
      )
      assert np.all([x in ents_to_con for x in Y[:, 0]])
  
      rels_to_con = ["y", "x"]
      Y, S = query_topn(
          model,
          top_n=100,
          head=subj,
          tail=obj,
          rels_to_consider=rels_to_con,
      )
      assert np.all([x in rels_to_con for x in Y[:, 1]])
  
      Y, S = query_topn(model, top_n=100, relation=pred, tail=obj)
      assert all(S[i] >= S[i + 1] for i in range(len(S) - 1))
  
file_path: AmpliGraph/tests/ampligraph/discovery/test_discovery.py
imports: import numpy
  import pytest
  from sklearn.cluster import DBSCAN
  from ampligraph.discovery.discovery import discover_facts, generate_candidates, _setdiff2d, find_clusters, find_duplicates, query_topn
  from ampligraph.latent_features import ScoringBasedEmbeddingModel
label_desc: Use image node_id 6 for calling a global function with example usage: test_query_topn() without return types