def import_data_from_sheet( sheet, sheet_header, language_id: str, implicit: t.Mapping[Literal["languageReference", "id", "value"], str] = {}, concept_column: t.Tuple[str, str] = ("Concept_ID", "Concept_ID"), ) -> t.Iterable[Form]: row_iter = sheet.iter_rows() # TODO?: compare header of this sheet to format of given dataset process # row. Maybe unnecessary. In any case, do not complain about the unused # variable. header = next(row_iter) # noqa: F841 assert ( concept_column[1] in sheet_header ), f"Could not find concept column {concept_column[1]} in your excel sheet {sheet.title}." for row in row_iter: data = Form({k: clean_cell_value(cell) for k, cell in zip(sheet_header, row)}) if "?" in data.values(): continue if "value" in implicit: data[implicit["value"]] = "\t".join(map(str, data.values())) concept_entry = data.pop(concept_column[1]) data[concept_column[0]] = concept_entry if "id" in implicit: data[implicit["id"]] = None if "languageReference" in implicit: data[implicit["languageReference"]] = language_id yield data
def import_data_from_sheet( sheet, sheet_header, implicit: t.Mapping[Literal["languageReference", "id", "value"], str] = {}, entries_to_concepts: t.Mapping[str, str] = KeyKeyDict(), concept_column: t.Tuple[str, str] = ("Concept_ID", "Concept_ID"), ) -> t.Iterable[Form]: row_iter = sheet.iter_rows() # TODO?: compare header of this sheet to format of given data set process # row. Maybe unnecessary. In any case, do not complain about the unused # variable. header = next(row_iter) # noqa: F841 assert ( concept_column[1] in sheet_header ), f"Could not find concept column {concept_column[0]} in your excel sheet {sheet.title}." for row in row_iter: data = Form({k: clean_cell_value(cell) for k, cell in zip(sheet_header, row)}) if "value" in implicit: data[implicit["value"]] = "\t".join(map(str, data.values())) try: concept_entry = data.pop(concept_column[1]) data[concept_column[0]] = entries_to_concepts[concept_entry] except KeyError: logger.warning( f"Concept {concept_entry} was not found. Please add it to the concepts table manually. The corresponding form was ignored and not added to the dataset." ) data[concept_column[0]] = concept_entry continue if "id" in implicit: data[implicit["id"]] = None if "languageReference" in implicit: data[implicit["languageReference"]] = sheet.title yield data