Explanations

class nettlesome.terms.Explanation(reasons, context=None, operation=<built-in function ge>)

Explanation of how a comparison method between Comparables can succeed.

__init__(reasons, context=None, operation=<built-in function ge>)

Set pairs of corresponding Factors as “reasons”, and corresponding generic Terms as “context”.

__repr__()

Return repr(self).

Return type

str

__str__()

Return str(self).

__weakref__

list of weak references to the object (if defined)

classmethod from_context(context=None, current=None, incoming=None)

Return new Explanation with self as context but no reasons.

Return type

Explanation

means(other)

Test if both Explanations have the same context and reasons.

Return type

bool

operate(left, right)

Generate further explanations for applying self.operation to a new Factor pair.

Return type

Iterator[Explanation]

reversed_context()

Make new copy of self, swapping keys and values of context.

Return type

Explanation

property short_string: str

Summarize self without line breaks.

Return type

str

with_context(context)

Make new copy of self, replacing context.

Return type

Explanation

with_match(match)

Add a pair of compared objects that has been found to satisfy operation, given context.

Return type

Explanation

Context Registers

class nettlesome.terms.ContextRegister

A mapping of corresponding Factors from two different contexts.

When Factors are matched in a ContextRegister, it indicates that their relationship can be described by a comparison function like means(), Factor.implies(), or Factor.consistent_with().

__eq__(other)

Return self==value.

Return type

bool

__hash__ = None
__init__()

Index Comparables on each side by names of Comparables on the other side.

__repr__()

Return repr(self).

Return type

str

__str__()

Return str(self).

Return type

str

__weakref__

list of weak references to the object (if defined)

assigns_same_value_to_key_factor(other, key_factor)

Check if both ContextRegisters assign same value to the key for this factor.

Return type

bool

check_insert_pair(key, value)

Raise exception if a pair of corresponding Terms can’t be added to register.

Return type

None

check_match(key, value)

Test if key and value are in matches as corresponding to one another.

Return type

bool

classmethod create(changes, current=None, incoming=None, terms_to_replace=None)

Convert changes to factor, expressed as built-in Python objects, to a ContextRegister.

Return type

ContextRegister

factor_pairs()

Get pairs of corresponding Comparables.

Return type

Iterator[Tuple[Term, Term]]

classmethod from_changes_and_current(changes, current, incoming=None)

Make new ContextRegister from a list of replacement generic Terms.

classmethod from_lists(to_replace, replacements, current=None, incoming=None)

Make new ContextRegister from two lists of Comparables.

Return type

ContextRegister

get(query)

Get value corresponding to the key named query.

Return type

Optional[Comparable]

get_factor(query)

Get value corresponding to the key query.

Return type

Optional[Comparable]

get_reverse_factor(query)

Get key corresponding to the value query.

Return type

Optional[Term]

insert_pair(key, value)

Add a pair of corresponding Comparables.

Return type

None

items()

Get items from matches mapping.

Return type

ItemsView

keys()

Get keys from matches mapping.

Return type

KeysView

property matches: Dict[str, nettlesome.terms.Term]

Get names of self’s Terms matched to other’s Terms.

Return type

Dict[str, Term]

means(other)

Determine if self and other have the same Factor matches.

Return type

bool

merged_with(incoming_mapping)

Create a new merged ContextRegister.

Parameters

incoming_mapping (ContextRegister) – an incoming mapping of Factors from self to Factors.

Return type

Optional[ContextRegister]

Returns

None if the same Factor in one mapping appears to match to two different Factors in the other. Otherwise returns an updated ContextRegister of matches.

property reason: str

Make statement matching analagous context factors of self and other.

Return type

str

replace_keys(replacements)

Construct new ContextRegister by replacing keys.

Used when making permutations of the key orders because some are interchangeable.

e.g. in “Amy and Bob were married” the order of “Amy” and “Bob” is interchangeable.

Return type

ContextRegister

property reverse_matches: Dict[str, nettlesome.terms.Term]

Get names of other’s Terms matched to self’s Terms.

Return type

Dict[str, Term]

reversed()

Swap keys for values and vice versa.

values()

Get values from matches mapping.

Return type

ValuesView