semantic.units

Used to extract and convert between quantites (i.e., magnitudes with units).

class semantic.units.ConversionService
convert(input)

Converts a string representation of some quantity of units into a quantities object.

Args:
input (str): A textual representation of some quantity of units,
e.g., “fifty kilograms”.
Returns:
A quantities object representing the described quantity and its units.
extractUnits(input)

Collects all the valid units from an input string. Works by appending consecutive words from the string and cross-referncing them with a set of valid units.

Args:
input (str): Some text which hopefully contains descriptions
of different units.
Returns:
A list of strings, each entry in which is a valid quantities unit.
isValidUnit(w)

Checks if a string represents a valid quantities unit.

Args:
w (str): A string to be tested against the set of valid
quantities units.
Returns:
True if the string can be used as a unit in the quantities module.
parseUnits(input)

Carries out a conversion (represented as a string) and returns the result as a human-readable string.

Args:
input (str): Text representing a unit conversion, which should
include a magnitude, a description of the initial units, and a description of the target units to which the quantity should be converted.
Returns:
A quantities object representing the converted quantity and its new units.

Previous topic

semantic.solver

Next topic

Tests

This Page