def shorthand(token): """Convert a shorthand value like 11-22-33-44:55g.""" trait = Trait(start=token.start, end=token.end) flag = as_value(token, trait, "shorthand_wt", "shorthand_wt_units") trait.is_flag_in_token(token, "estimated_wt", rename="estimated_value") trait.is_shorthand = True return trait if flag else None
def shorthand_length(token, measurement=""): """Handle shorthand length notation like 11-22-33-44:55g.""" trait = Trait(start=token.start, end=token.end) trait.value = to_positive_float(token.group.get(measurement)) if not trait.value: return None trait.units = "mm_shorthand" trait.units_inferred = False trait.is_shorthand = True flag = measurement.split("_")[1] flag = f"estimated_{flag}" trait.is_flag_in_token(token, flag, rename="estimated_value") return trait