class_docstr: A parser for LibSVM-formatted ranking files.
  
  This parser can parse an iterable of lines into an iterable of
  `RankingExampleTuple`s that contain the per-query labels and features.
  
  Example usage:
  >>> lines = ["1 qid:1 1:5.0 2:3.0", "2 qid:1 1:2.0 2:1.0"]
  >>> feature_names = {1: "bm25", 2: "tfidf"}
  >>> parser = LibSVMRankingParser(lines, feature_names)
  >>> for example in parser:
  ...   print(example[0])
  {'bm25': array([5., 2.]), 'tfidf': array([3., 1.]), 'label': array([1, 2])}
  
  The parser will raise a ParserError with an informative error message if the
  content being parsed does not match LibSVM ranking format.
class_docstr_tok: ["A","parser","for","LibSVM-formatted","ranking","files",".","This","parser","can","parse","an","iterable","of","lines","into","an","iterable","of","`","RankingExampleTuple","`","s","that","contain","the","per-query","labels","and","features",".","Example","usage",":",">",">",">","lines","=","[","``","1","qid:1","1:5.0","2:3.0","''",",","``","2","qid:1","1:2.0","2:1.0","''","]",">",">",">","feature_names","=","{","1",":","``","bm25","''",",","2",":","``","tfidf","''","}",">",">",">","parser","=","LibSVMRankingParser","(","lines",",","feature_names",")",">",">",">","for","example","in","parser",":","...","print","(","example","[","0","]",")","{","'bm25","'",":","array","(","[","5.",",","2",".","]",")",",","'tfidf","'",":","array","(","[","3.",",","1",".","]",")",",","'label","'",":","array","(","[","1",",","2","]",")","}","The","parser","will","raise","a","ParserError","with","an","informative","error","message","if","the","content","being","parsed","does","not","match","LibSVM","ranking","format","."]
docstr: Store the current ranking example in numpy format.
  
  This method converts the current example to a RankingExampleTuple and stores
  it in `self._available_examples` so that it can be yielded by
  `self.__iter__`.
docstr_tok: ["Store","the","current","ranking","example","in","numpy","format",".","This","method","converts","the","current","example","to","a","RankingExampleTuple","and","stores","it","in","`","self._available_examples","`","so","that","it","can","be","yielded","by","`","self.__iter__","`","."]
code: def _store_current_example(self):
      """Store the current ranking example in numpy format.
  
      This method converts the current example to a RankingExampleTuple and stores
      it in `self._available_examples` so that it can be yielded by
      `self.__iter__`.
      """
      if not self._current_example:
          return
      qid = self._current_example.qid
      np_features_dict = {
          key: np.array(value)
          for key, value in self._current_example.features.items()
      }
  
      # Extracts the individual features, sorted by their numerical indices, and
      # re-adds them as a single feature with shape (list_size, feature_size).
      if self._combine_features:
          features = [
              np_features_dict.pop(self._feature_names[idx])
              for idx in sorted(self._feature_names)
          ]
          np_features_dict["float_features"] = np.stack(
              features, axis=-1
          )
  
      # Add query identifier.
      np_features_dict[self._query_id_feature_name] = qid
  
      self._available_examples.append((qid, np_features_dict))
  
file_path: datasets/tensorflow_datasets/ranking/libsvm_ranking_parser.py
imports: import collections
  import dataclasses
  import re
  from typing import Iterable, List, Mapping, Tuple
  import numpy
label_desc: Use image node_id 4 for calling the LibSVMRankingParser obj's underlying member method code with example usage: obj._store_current_example() without return types