14.5.34. crate_anon.nlp_manager.regex_units
crate_anon/nlp_manager/regex_units.py
Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CRATE.
CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CRATE. If not, see <https://www.gnu.org/licenses/>.
Regular expressions to detect physical units.
- crate_anon.nlp_manager.regex_units.assemble_units(components: List[str | None]) str [source]
Takes e.g.
["ft", "in"]
and makes"ft in"
.
- crate_anon.nlp_manager.regex_units.factor_micromolar_from_mg_per_dl(molecular_mass_g_per_mol: float) float [source]
Returns the conversion factor that you should multiple a “mg/dL” number by to get a “μM” (μmol/L) number.
- Parameters:
molecular_mass_g_per_mol – molecular mass in g/mol
- Returns:
conversion factor
- crate_anon.nlp_manager.regex_units.factor_millimolar_from_mg_per_dl(molecular_mass_g_per_mol: float) float [source]
Returns the conversion factor that you should multiple a “mg/dL” number by to get a “mM” (mmol/L) number.
Principle:
mmol_per_L = 0.001 * mol_per_L = 0.001 * (g_per_L / g_per_mol) = 0.001 * ((10 * g_per_dL) / g_per_mol) = 0.001 * ((10 * 1000 * mg_per_dL) / g_per_mol) = (0.001 * 10 * 1000 / g_per_mol) * mg_per_dL = (10 / g_per_mol) * mg_per_dl Example: glucose, molecular mass 180.156 g/mol => conversion factor is (10 / 180.156) 90 mg/dL -> (10 / 180.156) * 90 mM = 5.0 mM
- Parameters:
molecular_mass_g_per_mol – molecular mass in g/mol
- Returns:
conversion factor
- crate_anon.nlp_manager.regex_units.kg_from_st_lb_oz(stones: float = 0, pounds: float = 0, ounces: float = 0) float | None [source]
Convert Imperial to metric mass.
- Returns:
mass in kg
- crate_anon.nlp_manager.regex_units.m_from_ft_in(feet: float = 0, inches: float = 0) float | None [source]
Converts Imperial to metric length.
- Returns:
length in m
- crate_anon.nlp_manager.regex_units.m_from_m_cm(metres: float = 0, centimetres: float = 0) float | None [source]
Converts metres/centimetres to metres.
- crate_anon.nlp_manager.regex_units.micromolar_from_mg_per_dl(mg_per_dl: float, molecular_mass_g_per_mol: float) float [source]
Converts a concentration from mg/dL to μM (μmol/L).
- Parameters:
mg_per_dl – value in mg/dL
molecular_mass_g_per_mol – molecular mass in g/mol
- Returns:
value in μM = μmol/L
- crate_anon.nlp_manager.regex_units.millimolar_from_mg_per_dl(mg_per_dl: float, molecular_mass_g_per_mol: float) float [source]
Converts a concentration from mg/dL to mM (mmol/L).
- Parameters:
mg_per_dl – value in mg/dL
molecular_mass_g_per_mol – molecular mass in g/mol
- Returns:
value in mM = mmol/L
- crate_anon.nlp_manager.regex_units.out_of(n: int) str [source]
Returns regex text representing “out of N”.
- Parameters:
n – the number N
- crate_anon.nlp_manager.regex_units.out_of_anything() str [source]
- Returns:
regex representing “out of N” where N is any number
- crate_anon.nlp_manager.regex_units.per(numerator: str, denominator: str, include_power_minus1: bool = True, numerator_optional: bool = False) str [source]
Returns regex text representing “X per Y”; e.g. “millimoles per litre”, “cells per cubic millimetre”.
- Parameters:
numerator – regex representing the numerator
denominator – regex representing the denominator
include_power_minus1 – include the “n d -1” format for “n/d”
numerator_optional – presence of the numerator is optional
- crate_anon.nlp_manager.regex_units.power(x: str, n: int, allow_no_operator: bool = False) str [source]
Returns regex text representing “x to the power n”.
- Parameters:
x – base
n – exponent
allow_no_operator – make the operator (like
^
or**
) optional?
- crate_anon.nlp_manager.regex_units.units_by_dimension(*args: Tuple[str, int], allow_no_operator: bool = False) str [source]
Returns regex text for a unit where we specify them by their dimensions.
- Parameters:
*args – each is a tuple
unit, power
allow_no_operator – make the operator (like
^
or**
) optional?