Analogies
¶
Two groups of
Factor
s and a function that must hold between them.Can be used to find ways to assign the
Factor
s’ context assignments consistently with theAnalogy
.- Parameters
need_matches (Sequence[Optional[Factor]]) –
Factor
s that all need to satisfy thecomparison
with someFactor
ofavailable
for the relation to hold.available (Sequence[Optional[Factor]]) –
Factor
s available for matching with theneed_matches
Factor
s, but that don’t all need to be matched themselves for the relation to hold.comparison (Callable) – a function defining the comparison that must be
True
between eachneed_matches
and someavailable
for the relation to hold. Could beFactor.means()
orFactor.__ge__()
.
Find ways for a series of pairs of
Factor
s to satisfy a comparison.- Parameters
context (
Optional
[ContextRegister
]) – keys representingFactor
s inself
and values representingFactor
s inother
. The keys and values have been found in corresponding positions inself
andother
.- Yields
every way that
matches
can be updated to be consistent with each element ofself.need_matches
having the relationshipself.comparison
with the item at the corresponding index ofself.available
.- Return type
Iterator
[ContextRegister
]
Find ways for two unordered sets of
Factor
s to satisfy a comparison.- Parameters
matches (
ContextRegister
) – a mapping ofFactor
s that have already been matched to each other in the recursive search for a complete group of matches. Starts empty when the method is first called.still_need_matches (
Optional
[List
[Factor
]]) –Factor
s that need to satisfy the comparisoncomparison
with someFactor
ofavailable
for the relation to hold, and have not yet been matched.
- Yields
context registers showing how each
Factor
inneed_matches
can have the relationcomparison
with someFactor
inavailable_for_matching
, with matching context.- Return type
Iterator
[ContextRegister
]
Filter context assignments with
unordered_comparison()
.- Parameters
matchlist (
List
[ContextRegister
]) – possible ways to match genericFactor
s ofneed_matches
withavailable
.- Return type
List
[ContextRegister
]- Returns
a new version of
matchlist
filtered to be consistent withself
’sunordered_comparison()
.
Find all context registers consistent with multiple
Analogy
comparisons.- Parameters
relations (
Tuple
[Analogy
, …]) – a series ofAnalogy
comparisons in which theneed_matches
Factor
s all refer to one context (for instance, the sameOpinion
), and theavailable
Factor
s all refer to another context.- Return type
List
[ContextRegister
]- Returns
a list of all context registers consistent with all of the
Analogy
s.