Turn excel into dict.
    Args:
        :excel_filepath: path to excel file to turn into dict.
        :limits: path to csv file to turn into dict
422316
def excel_to_dict(excel_filepath, encapsulate_filepath=False, **kwargs):
    
    result = {}
    try:
        callbacks = {'to_dictlist': excel_todictlist}  # Default callback
        callbacks.update(kwargs.get('alt_callbacks', {}))

        # Retrieve excel data as dict of sheets lists
        excel_data = callbacks.get('to_dictlist')(excel_filepath, **kwargs)
        for sheet in excel_data.keys():
            try:
                kwargs['rows'] = excel_data.get(sheet, [])
                result[sheet] = csv_to_dict(excel_filepath, **kwargs)
            except Exception as ex:
                logger.error('Fail to parse sheet {} - {}'.format(sheet, ex))
                result[sheet] = []
                continue

        if encapsulate_filepath:
            result = {excel_filepath: result}

    except Exception as ex:
        msg = 'Fail transform excel to dict - {}'.format(ex)
        logger.error(msg, excel_filepath=excel_filepath)

    return result
1174397
def load_spacy_rule(file_path: str) -> Dict:
        
        with open(file_path) as fp:
            return json.load(fp)
773969
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'limit') and self.limit is not None:
            _dict['limit'] = self.limit
        return _dict
1337112
def dictionary(self) -> dict:
        """"""
        self.config.read(self.filepath)
        return self.config._sections
1043792
def to_excel(self, *args):
        
        path = os.getcwd()
        fname = self.fname.replace(".ppl", "_ppl") + ".xlsx"
        if len(args) > 0 and args[0] != "":
            path = args[0]
            if os.path.exists(path) == False:
                os.mkdir(path)
        xl_file = pd.ExcelWriter(path + os.sep + fname)
        for idx in self.filter_data(""):
            self.extract(idx)
        labels = list(self.filter_data("").values())
        for prof in self.data:
            data_df = pd.DataFrame()
            data_df["X"] = self.data[prof][0]
            for timestep, data in zip(self.time, self.data[prof][1]):
                data_df[timestep] = data
            myvar = labels[prof-1].split(" ")[0]
            br_label = labels[prof-1].split("\'")[5]
            unit = labels[prof-1].split("\'")[7].replace("/", "-")
            mylabel = "{} - {} - {}".format(myvar, br_label, unit)
            data_df.to_excel(xl_file, sheet_name=mylabel)
        xl_file.save()
624275
def csv_to_matrix(csv_file_path):
    
    mtx = []
    with open(csv_file_path) as csv_data_file:
        for row in csv_data_file:
            mtx.append(row.split(','))
    return mtx
355921
def retrieve_data(file_paths):

    
    data_dict = {}
    for file_path in file_paths:
        with open(file_path) as fh:
            try:
                content = yaml.load(fh.read())
            except yaml.YAMLError as e:
                raise MiuraException(
                    "Unable to parse yaml at {0}: \n {1}".format(
                        file_path,
                        str(e)
                    ))
            if not isinstance(content, dict):
                raise MiuraException(
                    "{0} is does not translate to a dictionary!".format(file_path)
                )
            data_dict.update(content)
    return data_dict
1213781
def to_xlsx_file(file_path="tmp", file_name="export")
      path = "#{file_path}/#{file_name}_#{Time.now.to_i}_#{SecureRandom.hex}.xlsx"
      workbook = FastExcel.open(path, constant_memory: true)
      worksheet = workbook.add_worksheet("Default")

      bold = workbook.bold_cell_format
      worksheet.set_row(0, FastExcel::DEF_COL_WIDTH, bold)

      rows! do |columns, model, x|
        worksheet.write_row(x, columns)
      end

      workbook.close
      path
    end
1225063
def get_help_data(filepath):
    

    try:
        with open(filepath, 'r') as file:
            return _json.load(file, object_pairs_hook=OrderedDict)
    except Exception as e:
        logger.error("Could not load file {}".format(filepath))
        logger.exception(e)
        return {}
1157414
def pdf_to_dict(pdf_filepath, **kwargs):

    

    callbacks = {
        'pdf_to_text': pdf_to_text,
        'pdf_row_format': pdf_row_format,
        'pdf_row_limiter': pdf_row_limiter,
        'pdf_row_parser': pdf_row_parser,
        'pdf_row_cleaner': pdf_row_cleaner
        }

    callbacks.update(kwargs.get('alt_callbacks', {}))
    rows = kwargs.get('rows', [])

    if not rows:
        # pdf to string
        rows_str = callbacks.get('pdf_to_text')(pdf_filepath, **kwargs)

        # string to list of rows
        rows = callbacks.get('pdf_row_format')(rows_str, **kwargs)

    # apply limits
    rows = callbacks.get('pdf_row_limiter')(rows, **kwargs)

    # Parse data from rows to dict
    rows = callbacks.get('pdf_row_parser')(rows, **kwargs)

    # apply cleaner
    rows = callbacks.get('pdf_row_cleaner')(rows)

    return rows
1177297
def fromFile(cls, filepath):
        
        xdata = ElementTree.parse(nstr(filepath))
        xroot = xdata.getroot()

        # collect variable information
        name = xroot.get('name')
        ver = float(xroot.get('version', '1.0'))

        if not name:
            name = os.path.basename(filepath).split('.')
            if name == '__init__':
                name = os.path.normpath(filepath).split(os.path.sep)[-2]
            name = projex.text.pretty(name)

        icon = xroot.get('icon', './icon.png')

        ximport = xroot.find('import')
        if ximport is not None:
            importpath = ximport.get('path', './__init__.py')
        else:
            importpath = './__init__.py'

        params = {'description': '', 'author': '', 'email': '', 'url': ''}
        for param, default in params.items():
            xdata = xroot.find(param)
            if xdata is not None:
                params[param] = xdata.text

        # generate the proxy information
        proxy = PluginProxy(cls, name, ver)
        proxy.setImportPath(importpath)
        proxy.setDescription(params['description'])
        proxy.setAuthor(params['author'])
        proxy.setEmail(params['email'])
        proxy.setUrl(params['url'])
        proxy.setFilepath(filepath)

        return proxy
46002
def load_embedding(path):
    '''
    
    '''
    EMBEDDING_DIM = 300
    embedding_dict = {}
    with open(path, 'r', encoding='utf-8') as file:
        pairs = [line.strip('\r\n').split() for line in file.readlines()]
        for pair in pairs:
            if len(pair) == EMBEDDING_DIM + 1:
                embedding_dict[pair[0]] = [float(x) for x in pair[1:]]
    logger.debug('embedding_dict size: %d', len(embedding_dict))
    return embedding_dict
182203
def make_param_dict_from_file(self,path_to_params):
        
        # then we were given a path to a parameter file
        param_list = list(csv.reader(open(path_to_params,"rb")))
        # delete empty elements (if any)
        param_file = [x for x in param_list if x != []]
        # make dict of [wavenames] = raw_params
        name_list = []
        param_list = []
        # get header names for each param (names of param_list columns)
        param_colnames = param_file[0][1:] # 0th element is "Name" or "Wavename"
        # start from 1.  (row 0 is the header)
        for i in np.arange(1, len(param_file)):
            name_list.append(param_file[i][0])
            param_list.append(param_file[i][1:])
        # remove ' ' blank spaces from param_list
        param_list = [[x.strip() for x in y] for y in param_list]
        param_dict = {}
        # i loops through param_colnames, j loops thru param values per wave
        for i in np.arange(0, len(param_colnames)):
            param_dict[param_colnames[i]] = []
            for j in np.arange(0,len(name_list)):
                param_dict[param_colnames[i]].append(param_list[j][i])
        # now we have param_dict, and name_list
        self._param_dict = param_dict
        self._row_names = name_list
1172753
def get_dicts(self):
        
        reader = csv.DictReader(open(self.path, "r", encoding=self.encoding))
        for row in reader:
            if row:
                yield row
1001053
def load(self, filepath, file_encoding=None):
        
        with open(filepath, encoding=file_encoding) as inf:
            for line in inf:
                current_line = str(line).strip()
                if current_line.startswith("@prefix"):
                    self._add_ttl_ns(current_line.replace("\n",""))
                elif len(current_line) > 10:
                    break
        self.__make_dicts__
845662
def csv_to_dicts(file, header=None):
    """"""
    with open(file) as csvfile:
        return [row for row in csv.DictReader(csvfile, fieldnames=header)]
578253
def _generate_examples(self, filepath):
    
    # Simultaneously iterating through the different data sets in the hdf5
    # file is >100x slower and the data set is small (26.7MB). Hence, we first
    # load everything into memory before yielding the samples.
    image_array, class_array, values_array = _load_data(filepath)
    for image, classes, values in moves.zip(image_array, class_array,
                                            values_array):
      yield dict(
          image=np.expand_dims(image, -1),
          label_shape=classes[1],
          label_scale=classes[2],
          label_orientation=classes[3],
          label_x_position=classes[4],
          label_y_position=classes[5],
          value_shape=values[1],
          value_scale=values[2],
          value_orientation=values[3],
          value_x_position=values[4],
          value_y_position=values[5])