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: Adds given qid and feature_map to the current example.
  
  If the qid matches the current example qid, this will add the features in
  given feature_map to the current example.
  If the qid does not match the current example qid, this will store the
  current example and then create a new one with given qid and feature_map.
  
  Args:
    qid: The query identifier.
    feature_map: A mapping of feature names to feature values.
docstr_tok: ["Adds","given","qid","and","feature_map","to","the","current","example",".","If","the","qid","matches","the","current","example","qid",",","this","will","add","the","features","in","given","feature_map","to","the","current","example",".","If","the","qid","does","not","match","the","current","example","qid",",","this","will","store","the","current","example","and","then","create","a","new","one","with","given","qid","and","feature_map",".","Args",":","qid",":","The","query","identifier",".","feature_map",":","A","mapping","of","feature","names","to","feature","values","."]
code: def _add_to_current_example(
      self, qid: str, feature_map: Mapping[str, float]
  ):
      """Adds given qid and feature_map to the current example.
  
      If the qid matches the current example qid, this will add the features in
      given feature_map to the current example.
      If the qid does not match the current example qid, this will store the
      current example and then create a new one with given qid and feature_map.
  
      Args:
        qid: The query identifier.
        feature_map: A mapping of feature names to feature values.
      """
      if self._current_example is None:
          self._current_example = RankingExample(
              qid, collections.defaultdict(list)
          )
  
      if self._current_example.qid != qid:
          self._store_current_example()
          self._current_example = RankingExample(
              qid, collections.defaultdict(list)
          )
  
      for key, value in feature_map.items():
          self._current_example.features[key].append(value)
  
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 3 for calling the LibSVMRankingParser obj's underlying member method code with example usage: obj._add_to_current_example(qid, feature_map) without return types