File size: 1,859 Bytes
8d55ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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:
    @staticmethod
    def _deleteEmpty(str):
        return str != ""

    @staticmethod
    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)

    @staticmethod
    def _isInfinity(value):
        return value == "Infinity" or value == "-Infinity"

    @staticmethod
    def _isFromZeroToN(values):
        i = 0
        for idx in values:
            if idx != i:
                return False

            i += 1

        return True

    @staticmethod
    def _hasEqualIndices(minVal, maxVal):
        minValIndices = sorted(minVal.keys())
        maxValIndices = sorted(maxVal.keys())

        return minValIndices == maxValIndices

    @staticmethod
    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

    @staticmethod
    def _stripDomains(domains):
        return map(lambda el: el.strip(), domains)

    @staticmethod
    def _splitDomain(domain, SEP):
        return Utils._stripDomains(domain.split(SEP))

    @staticmethod
    def _getWords(expression):
        if isinstance(expression, str):
            return re.sub("[^\w]", " ", expression).split()

        return []