semantic.numbers

Used to extract numbers and floats described as text.

class semantic.numbers.NumberService
exception NumberException(msg)
NumberService.isValid(input)
NumberService.longestNumber(input)

Extracts the longest valid numerical description from a string. Not guaranteed to return a result even if some valid numerical description exists (i.e., method is not particularly advanced).

Args:
input (str): An arbitrary string, hopefully containing a number.
Returns:
The number with the longest string description in input, or None if not found.
NumberService.parse(words)

A general method for parsing word-representations of numbers. Supports floats and integers.

Args:
words (str): Description of an arbitrary number.
Returns:
A double representation of the words.
NumberService.parseFloat(words)

Convert a floating-point number described in words to a double.

Supports two kinds of descriptions: those with a ‘point’ (e.g., “one point two five”) and those with a fraction (e.g., “one and a quarter”).

Args:
words (str): Description of the floating-point number.
Returns:
A double representation of the words.
NumberService.parseInt(words)

Parses words to the integer they describe.

Args:
words (str): Description of the integer.
Returns:
An integer representation of the words.
static NumberService.parseMagnitude(m)

Parses a number m into a human-ready string representation. For example, crops off floats if they’re too accurate.

Arguments:
m (float): Floating-point number to be cleaned.
Returns:
Human-ready string description of the number.

Previous topic

semantic.dates

Next topic

semantic.solver

This Page