ranked_ids#

scikitplot.corpus.ranked_ids(results, *, id_getter=None)[source]#

Return the identifiers of retrieval results, in rank order.

Parameters:
resultsiterable

A RetrievalResponse, or any iterable of results, best first.

id_gettercallable or None, default=None

id_getter(result) -> str or int. When None, each result gives its identifier by this fixed rule, first match wins:

  1. a str or int is the identifier;

  2. a 2-tuple (identifier, score) gives its first item (the shape of RetrievalIndex.query);

  3. an object with .doc gives .doc.doc_id (RetrievalHit);

  4. an object with .doc_id gives it (a document).

Returns:
list

Identifiers (str or int), possibly repeated (several chunks of one document); the metrics decide what a repeat means.

Raises:
TypeError

If results is a str, bytes or mapping, or a result yields no str/int identifier.

Parameters:
Return type:

list

Examples

>>> ranked_ids([("d2", 0.9), ("d1", 0.4)])
['d2', 'd1']
>>> ranked_ids([{"id": 7}], id_getter=lambda r: r["id"])
[7]