Strings

class StringCell(value=None)[source]

A cell representation of a string. All strings will be represented in lowercase, with leading and trailing whitespace removed. Two strings can be merged when one is a subsequence of the other

static coerce(value)[source]

Turns value into a string

Parameters:value (str) – The string to be turned into a StringCell
Returns:StringCell
Raises:CoercionFailure
is_contradictory(other)[source]

Can these two strings coexist? Two StringCells are contradictory if neither string is a substring of the other.

Parameters:other (str,StringCell) – The string to test against
Returns:bool
Raises:CoercionFailure
>>> w = StringCell("words")
>>> x = StringCell("word")
>>> y = StringCell("saying")
>>> x.is_contradictory(y)
True
>>> x.is_contradictory(w)
False
is_entailed_by(other)[source]

Returns True iff self’s string is None or is a substring of Other’s string

Parameters:other (str,StringCell) – The string or StringCell to test
Returns:bool
Raises:CoercionFailure
>>> w = StringCell("sentence")
>>> x = StringCell("sentences")
>>> y = StringCell("text")
>>> w.is_entailed_by(x)
True
>>> y.is_entailed_by(x)
False
is_equal(other)[source]

Whether two strings are equal

Parameters:other (str, StringCell) – The string or StringCell to be tested
Returns:bool
Raises:CoercionFailure
>>> x = StringCell("phrase")
>>> x.is_equal("phrase")
True
>>> x.is_equal(StringCell("word"))
False
merge(other)[source]

Merges two strings. Two strings can only be merged if one is a substring of the other, in which case the more general string is returned. The method will modify the self argument.

Parameters:other (str,StringCell) – The string or StringCell to merge with self
Returns:StringCell
Raises:CoercionFailure,Contradiction
>>> x = StringCell("word")
>>> y = StringCell("words")
>>> x.merge(y)
words

Note

merge will modify self‘s string to match the return value.

>>> x = StringCell("verb")
>>> y = StringCell("adverb")
>>> x.merge(y)
adverb
>>> x
adverb
get_value()[source]

Returns value if it exists or an empty string

Returns:str

Previous topic

Spatial

This Page