Generate example dicts.
7835
def dataset_generator(filepath,
                      dataset,
                      chunk_size=1,
                      start_idx=None,
                      end_idx=None):
  """"""
  encoder = dna_encoder.DNAEncoder(chunk_size=chunk_size)
  with h5py.File(filepath, "r") as h5_file:
    # Get input keys from h5_file
    src_keys = [s % dataset for s in ["%s_in", "%s_na", "%s_out"]]
    src_values = [h5_file[k] for k in src_keys]
    inp_data, mask_data, out_data = src_values
    assert len(set([v.len() for v in src_values])) == 1

    if start_idx is None:
      start_idx = 0
    if end_idx is None:
      end_idx = inp_data.len()

    for i in range(start_idx, end_idx):
      if i % 100 == 0:
        print("Generating example %d for %s" % (i, dataset))
      inputs, mask, outputs = inp_data[i], mask_data[i], out_data[i]
      ex_dict = to_example_dict(encoder, inputs, mask, outputs)
      # Original data has one output for every 128 input bases. Ensure that the
      # ratio has been maintained given the chunk size and removing EOS.
      assert (len(ex_dict["inputs"]) - 1) == ((
          128 // chunk_size) * ex_dict["targets_shape"][0])
      yield ex_dict
307834
def mk_dict(results,description):
    """"""
    
    rows=[]
    for row in results:
        row_dict={}
        for idx in range(len(row)):
            col=description[idx][0]
            row_dict[col]=row[idx]
        rows.append(row_dict)
    return rows
263718
def _generate_examples(self, filepath):
    """"""
    logging.info("generating examples from = %s", filepath)
    with tf.io.gfile.GFile(filepath) as f:
      squad = json.load(f)
      for article in squad["data"]:
        if "title" in article:
          title = article["title"].strip()
        else:
          title = ""
        for paragraph in article["paragraphs"]:
          context = paragraph["context"].strip()
          for qa in paragraph["qas"]:
            question = qa["question"].strip()
            id_ = qa["id"]

            answer_starts = [answer["answer_start"] for answer in qa["answers"]]
            answers = [answer["text"].strip() for answer in qa["answers"]]

            # Features currently used are "context", "question", and "answers".
            # Others are extracted here for the ease of future expansions.
            example = {
                "title": title,
                "context": context,
                "question": question,
                "id": id_,
                "answer_starts": answer_starts,
                "answers": answers,
            }
            yield {
                "question": example["question"],
                # TODO(b/121176753): return all the answers.
                "first_answer": example["answers"][0],
                "context": example["context"]
            }
51789
def to_dicts(recarray):
    """"""
    for rec in recarray:
        yield dict(zip(recarray.dtype.names, rec.tolist()))
766348
def generate_sample_json():
    """"""

    check = EpubCheck(samples.EPUB3_VALID)
    with open(samples.RESULT_VALID, 'wb') as jsonfile:
        jsonfile.write(check._stdout)

    check = EpubCheck(samples.EPUB3_INVALID)
    with open(samples.RESULT_INVALID, 'wb') as jsonfile:
        jsonfile.write(check._stdout)
353448
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'examples') and self.examples is not None:
            _dict['examples'] = [x._to_dict() for x in self.examples]
        if hasattr(self, 'pagination') and self.pagination is not None:
            _dict['pagination'] = self.pagination._to_dict()
        return _dict
1007258
def example():
    """"""
    proc = [[2,3,1],[4,2,3],[1,4,1]]
    p = {}
    for i in range(3):
        for j in range(3):
            p[i+1,j+1] = proc[j][i]
    return p
1013670
def _generate_examples(self, filepath):
    """"""
    rows_per_pair_id = collections.defaultdict(list)

    with tf.io.gfile.GFile(filepath) as f:
      reader = csv.DictReader(f, delimiter='\t', quoting=csv.QUOTE_NONE)
      for row in reader:
        rows_per_pair_id[row['pairID']].append(row)

    for rows in six.itervalues(rows_per_pair_id):
      premise = {row['language']: row['sentence1'] for row in rows}
      hypothesis = {row['language']: row['sentence2'] for row in rows}
      yield {
          'premise': premise,
          'hypothesis': hypothesis,
          'label': rows[0]['gold_label'],
      }
264813
def p_examples_create(self, p):
        """"""
        p[0] = OrderedDict()
        if p[1] is not None:
            p[0][p[1].label] = p[1]
49972
def _generate_examples(self, file_id, extracted_dirs):
    """"""
    filedir = os.path.join(extracted_dirs["img_align_celeba"],
                           "img_align_celeba")
    img_list_path = extracted_dirs["list_eval_partition"]
    landmarks_path = extracted_dirs["landmarks_celeba"]
    attr_path = extracted_dirs["list_attr_celeba"]

    with tf.io.gfile.GFile(img_list_path) as f:
      files = [
          line.split()[0]
          for line in f.readlines()
          if int(line.split()[1]) == file_id
      ]

    attributes = self._process_celeba_config_file(attr_path)
    landmarks = self._process_celeba_config_file(landmarks_path)

    for file_name in sorted(files):
      path = os.path.join(filedir, file_name)

      yield {
          "image": path,
          "landmarks": {
              k: v for k, v in zip(landmarks[0], landmarks[1][file_name])
          },
          "attributes": {
              # atributes value are either 1 or -1, so convert to bool
              k: v > 0 for k, v in zip(attributes[0], attributes[1][file_name])
          },
      }
882990
def _create_examples(self, lines, set_type):
        """"""
        examples = []
        for (i, line) in enumerate(lines):
            if i == 0:
                continue
            guid = "%s-%s" % (set_type, i)
            text_a = line[3]
            text_b = line[4]
            label = line[0]
            examples.append(
                InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
        return examples
527262
def generate_ini(self):
        
        example = []
        example.append("[settings]")
        for key in sorted(list(self.spec.keys())):
            if self.spec[key]['type'] in [list, dict]:
                value = json.dumps(self.spec[key].get('example', ''))
            else:
                value = self.spec[key].get('example', '')
            string = f"{key.lower()}={value}"
            example.append(string)
        print("\n".join(example))
880177
def generate_example():
    
    cmd_args = sys.argv[1:]
    parser = argparse.ArgumentParser(description='Confpy example generator.')
    parser.add_argument(
        '--module',
        action='append',
        help='A python module which should be imported.',
    )
    parser.add_argument(
        '--file',
        action='append',
        help='A python file which should be evaled.',
    )
    parser.add_argument(
        '--format',
        default='JSON',
        choices=('JSON', 'INI'),
        help='The output format of the configuration file.',
    )

    args = parser.parse_args(cmd_args)

    for module in args.module or ():

        __import__(module)

    for source_file in args.file or ():

        cfg = pyfile.PythonFile(path=source_file).config

    cfg = config.Configuration()

    print(example.generate_example(cfg, ext=args.format))
231380
def generate_command(self):
        
        example = []
        example.append(f"{sys.argv[0]}")
        for key in sorted(list(self.spec.keys())):
            if self.spec[key]['type'] == list:
                value = " ".join(self.spec[key].get('example', ''))
            elif self.spec[key]['type'] == dict:
                value = f"\'{json.dumps(self.spec[key].get('example', ''))}\'"
            else:
                value = self.spec[key].get('example', '')
            string = f"     --{key.lower()} {value}"
            example.append(string)
        print(" \\\n".join(example))
1164470
def generate_example(self):
        
        data = javabridge.call(self.jobject, "generateExample", "()Lweka/core/Instance;")
        if data is None:
            return None
        else:
            return Instance(data)
367322
def fetchFirstExample(self, exampleDict, rawResults = False) :
        """"""
        return self.simpleQuery('first-example', rawResults = rawResults, example = exampleDict)
235227
def dict_to_object(d):
    """"""
    top = type('CreateSendModel', (object,), d)
    seqs = tuple, list, set, frozenset
    for i, j in d.items():
        if isinstance(j, dict):
            setattr(top, i, dict_to_object(j))
        elif isinstance(j, seqs):
            setattr(top, i, type(j)(dict_to_object(sj) if isinstance(sj, dict) else sj for sj in j))
        else:
            setattr(top, i, j)
    return top