Factor Groups
- class nettlesome.groups.FactorGroup(factors=())
Terms to be used together in a comparison.
- add(other)
Combine all Factors into a single FactorGroup.
- Return type
- add_or_raise_error(other)
Combine all Factors into a single FactorGroup.
- Return type
- consistent_with(other, context=None)
Find whether two sets of
Factor
s can be consistent.Works by first determining whether one
Factor
potentiallycontradicts()
another, and then determining whether it’s possible to make context assignments match between the contradictoryFactor
s.- Parameters
other (
Optional
[Comparable
]) –context (
Optional
[ContextRegister
]) – correspondences betweenFactor
s in self and other that can’t be changed in seeking a way to interpret the groups as consistent
- Return type
- Returns
whether unassigned context factors can be assigned in such a way that there’s no contradiction between any factor in
self_factors
andother_factors
, given that someFactor
s have already been assigned as described bymatches
.
- contradicts(other, context=None)
Find whether two sets of
Factor
s can be contradictory.- Parameters
other (
Optional
[Comparable
]) – a second set ofFactor
s with context factors that are internally consistent, but may not be consistent withself_factors
.context (
Optional
[ContextRegister
]) – correspondences betweenFactor
s in self and other that can’t be changed in seeking a contradiction
- Return type
- Returns
whether any
Factor
assignment can be found that makes aFactor
in the output ofother
contradict aFactor
in the output ofself
.
>>> from nettlesome import Statement, Entity >>> nafta = FactorGroup([ ... Statement(predicate="$country1 signed a treaty with $country2", ... terms=[Entity(name="Mexico"), Entity(name="USA")]), ... Statement(predicate="$country2 signed a treaty with $country3", ... terms=[Entity(name="USA"), Entity(name="Canada")]), ... Statement(predicate="$country3 signed a treaty with $country1", ... terms=[Entity(name="USA"), Entity(name="Canada")])]) >>> brexit = FactorGroup([ ... Statement(predicate="$country1 signed a treaty with $country2", ... terms=[Entity(name="UK"), Entity(name="European Union")]), ... Statement(predicate="$country2 signed a treaty with $country3", ... terms=[Entity(name="European Union"), Entity(name="Germany")]), ... Statement(predicate="$country3 signed a treaty with $country1", ... terms=[Entity(name="Germany"), Entity(name="UK")], truth=False)]) >>> nafta.contradicts(brexit) True
- drop_implied_factors()
Reduce group by removing redundant members implied by other members.
- Return type
- Returns
new group with any redundant items remomved
- explanations_contradiction(other, context=None)
Find contexts that would cause
self
to contradictother
.In this example, by adding a context parameter to this method’s comparison of two FactorGroups for contradiction, we can narrow down how nettlesome discovers analogies between the Entity objects. The result is that nettlesome finds only two Explanations for how a contradiction can exist.
>>> from nettlesome import Statement, Entity >>> nafta = FactorGroup([ ... Statement(predicate="$country1 signed a treaty with $country2", ... terms=[Entity(name="Mexico"), Entity(name="USA")]), ... Statement(predicate="$country2 signed a treaty with $country3", ... terms=[Entity(name="USA"), Entity(name="Canada")]), ... Statement(predicate="$country3 signed a treaty with $country1", ... terms=[Entity(name="USA"), Entity(name="Canada")])]) >>> brexit = FactorGroup([ ... Statement(predicate="$country1 signed a treaty with $country2", ... terms=[Entity(name="UK"), Entity(name="European Union")]), ... Statement(predicate="$country2 signed a treaty with $country3", ... terms=[Entity(name="European Union"), Entity(name="Germany")]), ... Statement(predicate="$country3 signed a treaty with $country1", ... terms=[Entity(name="Germany"), Entity(name="UK")], truth=False)]) >>> explanations_usa_like_uk = nafta.explanations_contradiction( ... brexit, ... context=([Entity(name="USA")], [Entity(name="UK")])) >>> len(list(explanations_usa_like_uk)) 2
- Return type
- explanations_implication(other, context=None)
Find contexts that would cause
self
to implyother
.- Return type
- explanations_implied_by(other, context=None)
Generate explanations for how other may imply self.
- Return type
- explanations_same_meaning(other, context=None)
Yield explanations for how
self
can have the same meaning asother
.- Return type
- explanations_union(other, context=None)
Yield contexts that allow
self
andother
to be combined with the union operation.- Return type
- from_comparable(value)
Create a FactorGroup from a Factor or sequence of Factors.
- Return type
- generic_terms_by_str()
Index Terms that can be replaced without changing
self
’s meaning.
- internally_consistent()
Check for contradictions among the Factors in self.
- Return type
- Returns
bool indicating whether self is internally consistent
- likely_contexts(other, context=None)
Yield likely contexts based on similar Factor meanings.
- Return type
- new_context(changes)
Use ContextRegister to choose changes to
self
’s context.- Return type
- property recursive_terms: Dict[str, nettlesome.terms.Term]
Collect self’s
terms
, and theirterms
, recursively.
Find whether all of
self
’s Factors are inother
.- Return type
- term_class
alias of
nettlesome.factors.Factor
- union(other, context=None)
Make new FactorGroup with the set of unique Factors from both
self
andother
.- Return type
- @nettlesome.groups.unique_explanations(func)
Filter out any duplicate Explanations before yielding them from func.