Lists

class LinearOrderedCell(ordered_domain, low=None, high=None)[source]

A generalization of IntervalCell to non-numeric symbols

Parameters:
  • ordered_domain (list) – An ordered sequence of symbols. Must not contain duplicate entries.
  • low,high – Symbols in the domain that mark the lower and upper bounds
Raises:

CellConstructionFailure

stem()[source]

Creates a new instance without any values

Returns:LinearOrderedCell
coerce(value)[source]

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
to_i(val)[source]

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
is_contradictory(other)[source]

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
is_entailed_by(other)[source]

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
is_equal(other)[source]

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
merge(other)[source]

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]
class PrefixCell(value=None)[source]

PrefixCells contain ordered elements

Parameters:value (list) – Optional parameter specifying initial list. Defaults to the empty list.
Raises:CellContstructionFailure
static coerce(value)[source]

Turns a value into a PrefixCell

Parameters:value (list, PrefixCell) – The value to be coerced
Returns:PrefixCell
size()[source]

Returns the number of elements in the list

Returns:int – number of elements in the list
>>> x = PrefixCell(['red','blue','green'])
>>> x.size()
3
is_contradictory(other)[source]

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
is_entailed_by(other)[source]

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
is_equal(other)[source]

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
merge(other)[source]

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]
append(el)[source]

Idiosynractic method for adding an element to a list. Modifies the self parameter.

>>> x = PrefixCell(['a','b'])
>>> x.append('c')
>>> x
[a,b,c]
get_values()[source]

Returns a list containing the elements.

Returns:list
>>> x = PrefixCell(['big','blue','ball'])
>>> x.get_values()
['big','blue','ball']

Previous topic

Dicts

Next topic

Sets

This Page