def convert(token): """Convert parsed token into a trait producer.""" trait = Trait(value=token.group["value"].lower(), start=token.start, end=token.end) trait.is_flag_in_token(token, "ambiguous_key") return trait
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 convert(token): """Convert parsed token into a trait.""" value = token.group["value"].lower() if regex.match(r"^[\s\d]+$", value): return None trait = Trait(value=value, start=token.start, end=token.end) trait.is_flag_in_token(token, "ambiguous_key") trait.is_value_in_token(token, "side") return trait
def convert(token): """Convert parsed token into a trait product.""" trait = Trait(start=token.start, end=token.end) flag = as_value(token, trait, unit_field="len_units") trait.is_flag_in_token(token, "ambiguous_char", rename="ambiguous_key") trait.is_flag_in_token(token, "ambiguous_key") trait.is_value_in_token(token, "dimension") trait.is_value_in_token(token, "dim", rename="dimension") trait.is_value_in_token(token, "side") 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