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”.
- __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
- operate(left, right)
Generate further explanations for applying self.operation to a new Factor pair.
- Return type
- reversed_context()
Make new copy of self, swapping keys and values of context.
- Return type
- with_context(context)
Make new copy of self, replacing context.
- Return type
- with_match(match)
Add a pair of compared objects that has been found to satisfy operation, given context.
- Return type
Context Registers
- class nettlesome.terms.ContextRegister
A mapping of corresponding
Factor
s from two different contexts.When
Factor
s are matched in a ContextRegister, it indicates that their relationship can be described by a comparison function likemeans()
,Factor.implies()
, orFactor.consistent_with()
.- __hash__ = None
- __init__()
Index Comparables on each side by names of Comparables on the other side.
- __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
- check_insert_pair(key, value)
Raise exception if a pair of corresponding Terms can’t be added to register.
- Return type
- check_match(key, value)
Test if key and value are in
matches
as corresponding to one another.- Return type
- 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
- 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
- get(query)
Get value corresponding to the key named
query
.- Return type
- get_factor(query)
Get value corresponding to the key
query
.- Return type
- property matches: Dict[str, nettlesome.terms.Term]
Get names of
self
’s Terms matched toother
’s Terms.
- merged_with(incoming_mapping)
Create a new merged
ContextRegister
.- Parameters
incoming_mapping (
ContextRegister
) – an incoming mapping ofFactor
s fromself
toFactor
s.- Return type
- Returns
None
if the sameFactor
in one mapping appears to match to two differentFactor
s in the other. Otherwise returns an updatedContextRegister
of matches.
- property reason: str
Make statement matching analagous context factors of self and other.
- Return type
- 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
- property reverse_matches: Dict[str, nettlesome.terms.Term]
Get names of
other
’s Terms matched toself
’s Terms.
- reversed()
Swap keys for values and vice versa.
- values()
Get values from
matches
mapping.- Return type