Segment#
- class caf.base.Segment(*, name, values, alias=None, description=None, values_aliases=<factory>, exclusions=<factory>, lookups=<factory>)[source]#
Bases:
BaseConfigClass containing info on a Segment, which combined with other Segments form a segmentation.
- Parameters:
name (str) – The name of the segmentation. Generally this is short form (e.g. ‘p’ instead of ‘purpose’)
values (dict[int, str]) – The values forming the segment. Keys are the values, and values are descriptions, e.g. for ‘p’, 1: ‘HB work’. Descriptions don’t tend to get used in DVectors so can be as verbose as desired for clarity.
description (str | None) – Optional description of the segment, with explanation of the source or usecases.
alias (str | None) – Optional alias to use when producing filenames (or other names) from segmentation slices, if not given then name will be used.
values_aliases (dict[int, str]) – Optional separate aliases for each value, can be used instead of name and value, e.g. “nhb” for direction 0.
exclusions (list[Exclusion]) – Define incompatibilities between segments. See Correspondence class
lookups (list[Exclusion]) – Define lookups between segments, essentially the reverse of exclusions. More efficient for segments with mappings, e.g. different defintions of age.
Attributes
List the names of segs excluded by this one.
Return integer values of segment.
List names of segs with lookups from self.
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Methods
add_corr_from_df(to_seg[, exclusion])Add either a lookup or exclusion to a segment from a lookup file.
drop_indices(other_seg)Return indices to drop based on exclusions.
extract_values(text)Extract segment values from string.
Get segment alias for use in filenames, if available.
get_value_alias(value)Get value alias if exists, otherwise return name and value int.
lookup_indices(other_seg)Return indices to include based on lookups.
translate_exclusion(new_seg)Translate an exclusion from one segment to another.
translate_segment(new_seg[, reverse])Translate self to new_seg.
Generate a regular expression to extract segment values.
Attributes Documentation
- exclusion_segs#
List the names of segs excluded by this one.
- int_values#
Return integer values of segment.
- lookup_segs#
List names of segs with lookups from self.
- model_config = {'arbitrary_types_allowed': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].