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
Factors can be consistent.Works by first determining whether one
Factorpotentiallycontradicts()another, and then determining whether it’s possible to make context assignments match between the contradictoryFactors.- Parameters
other (
Optional[Comparable]) –context (
Optional[ContextRegister]) – correspondences betweenFactors 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_factorsandother_factors, given that someFactors have already been assigned as described bymatches.
- contradicts(other, context=None)
Find whether two sets of
Factors can be contradictory.- Parameters
other (
Optional[Comparable]) – a second set ofFactors with context factors that are internally consistent, but may not be consistent withself_factors.context (
Optional[ContextRegister]) – correspondences betweenFactors in self and other that can’t be changed in seeking a contradiction
- Return type
- Returns
whether any
Factorassignment can be found that makes aFactorin the output ofothercontradict aFactorin 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
selfto 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
selfto 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
selfcan have the same meaning asother.- Return type
- explanations_union(other, context=None)
Yield contexts that allow
selfandotherto 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
selfandother.- Return type
- @nettlesome.groups.unique_explanations(func)
Filter out any duplicate Explanations before yielding them from func.