@@ -39,6 +39,11 @@ class FuzzyWarning(UserWarning):
39
39
pass
40
40
41
41
42
+ NO_DOMAIN_TO_COMPARE = FuzzyWarning ("No domains to compare." )
43
+ CANT_COMPARE_DOMAINS = "Can't compare different domains."
44
+ NO_DOMAIN = FuzzyWarning ("No domain." )
45
+
46
+
42
47
class Domain :
43
48
"""
44
49
A domain is a 'measurable' dimension of 'real' values like temperature.
@@ -83,8 +88,8 @@ def __init__(
83
88
"""Define a domain."""
84
89
assert low < high , "higher bound must be greater than lower."
85
90
assert res > 0 , "resolution can't be negative or zero"
86
- assert isinstance (name , str ), "Name must be a string."
87
- assert str .isidentifier (name ), "Name must be a valid identifier."
91
+ assert isinstance (name , str ), "Domain Name must be a string."
92
+ assert str .isidentifier (name ), "Domain Name must be a valid identifier."
88
93
self ._name = name
89
94
self ._high = high
90
95
self ._low = low
@@ -303,50 +308,50 @@ def __eq__(self, other: object) -> bool:
303
308
304
309
def __le__ (self , other : Set ) -> bool :
305
310
"""If this <= other, it means this is a subset of the other."""
306
- assert self .domain == other .domain
311
+ assert self .domain == other .domain , CANT_COMPARE_DOMAINS
307
312
if self .domain is None or other .domain is None :
308
- raise FuzzyWarning ( "Can't compare without Domains." )
313
+ raise NO_DOMAIN_TO_COMPARE
309
314
return all (np .less_equal (self .array (), other .array ()))
310
315
311
316
def __lt__ (self , other : Set ) -> bool :
312
317
"""If this < other, it means this is a proper subset of the other."""
313
- assert self .domain == other .domain
318
+ assert self .domain == other .domain , CANT_COMPARE_DOMAINS
314
319
if self .domain is None or other .domain is None :
315
- raise FuzzyWarning ( "Can't compare without Domains." )
320
+ raise NO_DOMAIN_TO_COMPARE
316
321
return all (np .less (self .array (), other .array ()))
317
322
318
323
def __ge__ (self , other : Set ) -> bool :
319
324
"""If this >= other, it means this is a superset of the other."""
320
- assert self .domain == other .domain
325
+ assert self .domain == other .domain , CANT_COMPARE_DOMAINS
321
326
if self .domain is None or other .domain is None :
322
- raise FuzzyWarning ( "Can't compare without Domains." )
327
+ raise NO_DOMAIN_TO_COMPARE
323
328
return all (np .greater_equal (self .array (), other .array ()))
324
329
325
330
def __gt__ (self , other : Set ) -> bool :
326
331
"""If this > other, it means this is a proper superset of the other."""
327
- assert self .domain == other .domain
332
+ assert self .domain == other .domain , CANT_COMPARE_DOMAINS
328
333
if self .domain is None or other .domain is None :
329
- raise FuzzyWarning ( "Can't compare without Domains." )
334
+ raise NO_DOMAIN_TO_COMPARE
330
335
return all (np .greater (self .array (), other .array ()))
331
336
332
337
def __len__ (self ) -> int :
333
338
"""Number of membership values in the set, defined by bounds and resolution of domain."""
334
339
if self .domain is None :
335
- raise FuzzyWarning ( "No domain." )
340
+ raise NO_DOMAIN
336
341
return len (self .array ())
337
342
338
343
@property
339
344
def cardinality (self ) -> float :
340
345
"""The sum of all values in the set."""
341
346
if self .domain is None :
342
- raise FuzzyWarning ( "No domain." )
347
+ raise NO_DOMAIN
343
348
return sum (self .array ())
344
349
345
350
@property
346
351
def relative_cardinality (self ) -> float :
347
352
"""Relative cardinality is the sum of all membership values by float of all values."""
348
353
if self .domain is None :
349
- raise FuzzyWarning ( "No domain." )
354
+ raise NO_DOMAIN
350
355
if len (self ) == 0 :
351
356
# this is highly unlikely and only possible with res=inf but still..
352
357
raise FuzzyWarning ("The domain has no element." )
0 commit comments