unitxt.parsing_utils module¶
- unitxt.parsing_utils.consume_overwrites(instring: str, valid_follower: str) Tuple[Any, str] [source]¶
- unitxt.parsing_utils.parse_key_equals_value_string_to_dict(args: str) dict [source]¶
Parses a query string of the form ‘key1=value1,key2=value2,…’ into a dictionary.
The function converts numeric values into integers or floats as appropriate, and raises an exception if the query string is malformed or does not conform to the expected format.
- param query:
The query string to be parsed.
- return:
A dictionary with keys and values extracted from the query string, with spaces stripped from keys.
- unitxt.parsing_utils.separate_inside_and_outside_square_brackets(s: str) Tuple[str, any] [source]¶
Separates the content inside and outside the first level of square brackets in a string.
Allows text before the first bracket and nested brackets within the first level. Raises a ValueError for: - Text following the closing bracket of the first bracket pair - Unmatched brackets - Multiple bracket pairs at the same level
- Parameters:
s – The input string to be parsed.
- Returns:
A tuple (outside, inside) where ‘outside’ is the content outside the first level of square brackets, and ‘inside’ is the content inside the first level of square brackets. If there are no brackets, ‘inside’ will be None.