Download pool/shard009/Python/0080308_Utils.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard009/Python/0080308_Utils.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard009/Python/0080308_Utils.py
-
curl -L -o 0080308_Utils.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard009/Python/0080308_Utils.py
1.86 kB
| import re | |
| def _flatten(x): | |
| result = [] | |
| for el in x: | |
| if hasattr(el, "__iter__") and not isinstance(el, basestring): | |
| result.extend(_flatten(el)) | |
| else: | |
| result.append(el) | |
| return result | |
| class Utils: | |
| def _deleteEmpty(str): | |
| return str != "" | |
| def _getInt(val): | |
| if val.replace('.','',1).isdigit(): | |
| val = str(int(float(val))) | |
| return val | |
| # from http://stackoverflow.com/questions/406121/flattening-a-shallow-list-in-python | |
| _flatten = staticmethod(_flatten) | |
| def _isInfinity(value): | |
| return value == "Infinity" or value == "-Infinity" | |
| def _isFromZeroToN(values): | |
| i = 0 | |
| for idx in values: | |
| if idx != i: | |
| return False | |
| i += 1 | |
| return True | |
| def _hasEqualIndices(minVal, maxVal): | |
| minValIndices = sorted(minVal.keys()) | |
| maxValIndices = sorted(maxVal.keys()) | |
| return minValIndices == maxValIndices | |
| def _hasAllIndices(minVal, maxVal): | |
| minValIndices = sorted(minVal.keys()) | |
| maxValIndices = sorted(maxVal.keys()) | |
| if minValIndices != maxValIndices: | |
| return False | |
| if not Utils._isFromZeroToN(minValIndices): | |
| return False | |
| if not Utils._isFromZeroToN(maxValIndices): | |
| return False | |
| return True | |
| def _stripDomains(domains): | |
| return map(lambda el: el.strip(), domains) | |
| def _splitDomain(domain, SEP): | |
| return Utils._stripDomains(domain.split(SEP)) | |
| def _getWords(expression): | |
| if isinstance(expression, str): | |
| return re.sub("[^\w]", " ", expression).split() | |
| return [] | |