def _group_version_id_relationship_types_by_relationship_type( version_id_relationship_type_tuples: List[Tuple[VersionId, RelationshipType]] ) -> Dict[RelationshipType, Set[VersionId]]: return applymap_dict(groupby_to_dict( version_id_relationship_type_tuples, lambda x: x[1], lambda x: x[0] ), set)
def _group_by_person_id_then_relationship_type( person_id_version_id_relationship_type_tuples: List[ Tuple[PersonId, VersionId, RelationshipType] ] ) -> Dict[PersonId, Dict[RelationshipType, Set[VersionId]]]: return applymap_dict(groupby_to_dict( person_id_version_id_relationship_type_tuples, lambda x: x[0], lambda x: x[1:] ), _group_version_id_relationship_types_by_relationship_type)
def get_person_ids_by_version_id_for_stage_names(self, version_ids, stage_names): db = self._db stage_table = db.manuscript_stage.table return applymap_dict( groupby_to_dict( db.session.query( stage_table.version_id, stage_table.person_id).filter( sqlalchemy.and_( stage_table.version_id.in_(version_ids), stage_table.stage_name.in_(stage_names))).all(), lambda row: row[0], lambda row: row[1]), set)
def dedup_map_values(values_map): return applymap_dict(values_map, lambda values: sorted(set(values)))
def normalise_subject_area_map(subject_area_map): return applymap_dict( subject_area_map, lambda subject_areas: [normalise_subject_area(s) for s in subject_areas])