A generalization of IntervalCell to non-numeric symbols
| Parameters: |
|
|---|---|
| Raises: | CellConstructionFailure |
Takes one or more values in the domain and returns a LinearOrderedCell with that domain. If the input is a single value, the low and high bounds will both be set to that value. If the input is a list or a tuple, the low and high bounds will be set to the min and max elements of the list or tuple.
Note
Unlike the coerce methods in many of the other modules, this is not a static method.
| Parameters: | value – A single value in the domain, or a list or tuple of values in the domain |
|---|---|
| Returns: | LinearOrderedCell |
| Raises: | Exception |
Maps value to position in domain
| Parameters: | val – value in the domain |
|---|---|
| Returns: | int – index of value in the domain. Returns -1 if val is None |
>>> v = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'animal', 'toy poodle')
>>> v.to_i('dog')
1
>>> v.to_i('toy poodle')
3
Whether other and self can coexist. Two LinearOrderedCells are contradictory if there is on overlap between their boundaries.
| Parameters: | other – A LinearOrderedCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> x = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'animal', 'dog')
>>> y = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'animal', 'toy poodle')
>>> z = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'poodle', 'toy poodle')
>>> x.is_contradictory(z)
True
>> x.is_contradictory(y)
False
>>> y.is_contradictory(z)
False
Returns true if Other is more specific than self or if Other is bounded within self.
| Parameters: | other – A LinearOrderedCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> x = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'animal', 'poodle')
>>> y = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'dog', 'dog')
>>> z = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'poodle', 'toy poodle')
>>> x.is_entailed_by(z)
False
>>> x.is_entailed_by(y)
True
>>> y.is_entailedy_by(x)
False
>>> z.is_entailed_by(y)
False
Determines whether two intervals are the same, i.e. every element of each domain is also an element of the other domain, and the low and high of each domain correspond to the low and high of the other
| Parameters: | other – A LinearOrderedCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> x = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'animal', 'poodle')
>>> y = LinearOrderedCell(['animal','dog'], 'dog', 'dog')
>>> z = LinearOrderedCell(['dog','toy poodle','animal','poodle'], 'animal', 'poodle')
>>> x.is_equal(y)
False
>>> x.is_equal(z)
True
Merges the two values
Note
This method will modify the self parameter
| Parameters: | other – A LinearOrderedCell or coercible value |
|---|---|
| Returns: | LinearOrderedCell |
| Raises: | Exception, Contradiction |
>>> x = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'animal', 'poodle')
>>> y = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'dog', 'poodle')
>>> z = LinearOrderedCell(['animal','dog','poodle','toy poodle'], 'poodle', 'toy poodle')
>>> x.merge(y)
[dog,poodle]
>>> x
[dog, poodle]
>>> x.merge(z)
[poodle,poodle]
PrefixCells contain ordered elements
| Parameters: | value (list) – Optional parameter specifying initial list. Defaults to the empty list. |
|---|---|
| Raises: | CellContstructionFailure |
Turns a value into a PrefixCell
| Parameters: | value (list, PrefixCell) – The value to be coerced |
|---|---|
| Returns: | PrefixCell |
Returns the number of elements in the list
| Returns: | int – number of elements in the list |
|---|
>>> x = PrefixCell(['red','blue','green'])
>>> x.size()
3
Two lists are contradictory if the shorter one is not a prefix of the other. (Very strict definition – could be generalized to subsequence) It does not matter whether self or other is the shorter one.
Empty lists are never contradictory.
| Parameters: | other (list) – The PrefixCell to test |
|---|---|
| Returns: | bool |
>>> x = PrefixCell([1,2,3])
>>> y = PrefixCell([1,2])
>>> z = PrefixCell(['a','b','c'])
>>> x.is_contradictory(y)
False
>>> y.is_contradictory(z)
True
>>> z.is_contradictory(PrefixCell([]))
False
Returns True iff the values in this list can be entailed by the other list (ie, this list is a prefix of the other)
| Parameters: | other – PrefixCell or coercible value |
|---|---|
| Returns: | bool |
>>> x = PrefixCell(['red','orange','yellow'])
>>> y = PrefixCell(['red','orange','yellow','green','blue','indigo','violet'])
>>> x.is_entailed_by(y)
True
>>> y.is_entailed_by(x)
False
Whether the lists are equal
| Parameters: | other – The value or PrefixCell to test |
|---|---|
| Returns: | bool |
>>> x = PrefixCell([1,2])
>>> y = PrefixCell([2,1])
>>> x.is_equal(y)
False
>>> x.is_equal([1,2])
True
Merges two Lists.
Note
This method will modify the self parameter.
| Parameters: | other – A PrefixCell or coercible value |
|---|---|
| Returns: | PrefixCell |
| Raises: | Contradiction |
>>> x = PrefixCell([1,2])
>>> y = PrefixCell([1,2,3])
>>> z = x.merge(y)
>>> z
[1,2,3]
>>> x
[1,2,3]