class_docstr: Class to read the datasets in RuRED format
docstr: Processes a RuRED data and returns a DeepPavlov relevant output
  
  Args:
      data: List of data units
      num_neg_samples: how many negative samples will be included to positive ones
          Possible values:
              - None: no negative samples will be generated
                  (relevant to the test set which has from neg samples only)
              - equal: there will be one negative sample pro positive sample
              - twice: there will be twice as many negative samples as positive ones
              - all: take all negative samples from the dataset
  Returns:
      one list of processed documents
docstr_tok: ["Processes","a","RuRED","data","and","returns","a","DeepPavlov","relevant","output","Args",":","data",":","List","of","data","units","num_neg_samples",":","how","many","negative","samples","will","be","included","to","positive","ones","Possible","values",":","-","None",":","no","negative","samples","will","be","generated","(","relevant","to","the","test","set","which","has","from","neg","samples","only",")","-","equal",":","there","will","be","one","negative","sample","pro","positive","sample","-","twice",":","there","will","be","twice","as","many","negative","samples","as","positive","ones","-","all",":","take","all","negative","samples","from","the","dataset","Returns",":","one","list","of","processed","documents"]
code: def process_rured_file(
      self, data: List[Dict], num_neg_samples: str
  ) -> Tuple[List, Dict]:
      """
      Processes a RuRED data and returns a DeepPavlov relevant output
  
      Args:
          data: List of data units
          num_neg_samples: how many negative samples will be included to positive ones
              Possible values:
                  - None: no negative samples will be generated
                      (relevant to the test set which has from neg samples only)
                  - equal: there will be one negative sample pro positive sample
                  - twice: there will be twice as many negative samples as positive ones
                  - all: take all negative samples from the dataset
      Returns:
          one list of processed documents
      """
      processed_samples = []
      neg_samples = []  # list of indices of negative samples
      pos_samples = 0  # counter of positive samples
  
      for sample in data:
          # record negative sample ids
          if sample["relation"] == "no_relation":
              neg_samples.append(len(processed_samples))
          else:
              pos_samples += 1
  
          if sample["subj_type"] in self.ner_stat:
              self.ner_stat[sample["subj_type"]] += 1
          else:
              self.ner_stat[sample["subj_type"]] = 1
  
          if sample["obj_type"] in self.ner_stat:
              self.ner_stat[sample["obj_type"]] += 1
          else:
              self.ner_stat[sample["obj_type"]] = 1
  
          processed_samples.append(
              (
                  [
                      sample["token"],
                      [
                          [(sample["subj_start"], sample["subj_end"])],
                          [(sample["obj_start"], sample["obj_end"])],
                      ],
                      [sample["subj_type"], sample["obj_type"]],
                  ],
                  self.label_to_one_hot(
                      self.rel2id[sample["relation"]]
                  ),
              )
          )
  
      # filter out some of negative sample if relevant
      if num_neg_samples == "equal":
          # include the same amount of negative samples as positive ones
          neg_to_eliminate = random.sample(
              neg_samples, (len(neg_samples) - pos_samples)
          )
          processed_samples = [
              sample
              for sample_idx, sample in enumerate(processed_samples)
              if sample_idx not in neg_to_eliminate
          ]
      elif num_neg_samples == "twice":
          # include twice as much negative samples as positive ones
          neg_to_eliminate = random.sample(
              neg_samples, (len(neg_samples) - 2 * pos_samples)
          )
          processed_samples = [
              sample
              for sample_idx, sample in enumerate(processed_samples)
              if sample_idx not in neg_to_eliminate
          ]
      elif num_neg_samples == "none":
          # eliminate all negative samples
          processed_samples = [
              sample
              for sample_idx, sample in enumerate(processed_samples)
              if sample_idx not in neg_samples
          ]
      else:
          raise ValueError(
              "Unknown negative samples amount! Currently available are 'equal', 'twice' and 'none"
          )
  
      # collect statistics
      stat = {}
      for sample in processed_samples:
          rel = [
              rel
              for rel, sample_log in enumerate(sample[1])
              if sample_log == 1
          ][0]
          if rel in stat:
              stat[rel] += 1
          else:
              stat[rel] = 1
  
      return processed_samples, stat
  
file_path: DeepPavlov/deeppavlov/dataset_readers/rured_reader.py
imports: import json
  import os
  import random
  from typing import Dict, List, Tuple
  from pathlib import Path
  from logging import getLogger
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.data.dataset_reader import DatasetReader
label_desc: Use image node_id 2 for calling the RuREDDatasetReader obj's underlying member method code with example usage: obj.process_rured_file(data, num_neg_samples) and returns: processed_samples,  stat