Predicates

Phrases that contain meanings of Statements.

Can contain references to other Statements, to numeric values, to dates, or to quantities (with the use of the pint library).

class nettlesome.predicates.PhraseABC

Abstract base class for phrases that can be compared like Predicates.

__ge__(other)

Test whether self either implies or has the same meaning as other.

Parameters

other (Any) – an object to compare

Return type

bool

Returns

whether other is another Predicate that self either means() or implies()

__gt__(other)

Alias for implies().

Return type

bool

__len__()

Get the number of Terms expected.

Also called the linguistic valency, arity, or adicity.

Returns

the number of Terms that can fit in the placeholders in the StatementTemplate.

__weakref__

list of weak references to the object (if defined)

content_without_placeholders()

Get template text with placeholders replaced by identical bracket pairs.

Produces a string that will evaluate equal for two templates with identical non-placedholder text.

Return type

str

contradicts(other)

Test whether other and self have contradictory meanings.

This is determined only by the truth value, the exact template content, and whether the placeholders indicate interchangeable terms.

Return type

bool

implies(other)

Test whether self implies other.

A Predicate implies another Predicate only if it means() the other Predicate, or if the other Predicate has the same text but a truth value of None.

>>> lived_at = Predicate(
...     content="$person lived at $place",
...     truth=True)
>>> whether_lived_at = Predicate(
...     content="$person lived at $place",
...     truth=None)
>>> str(whether_lived_at)
'whether $person lived at $place'
>>> lived_at.implies(whether_lived_at)
True
>>> whether_lived_at.implies(lived_at)
False
Parameters

other (Any) – an object to compare for implication.

Return type

bool

Returns

whether other is another Predicate with the same text, and the same truth value or no truth value.

means(other)

Test if self and other have identical meanings.

The means method will return False based on any difference in the Predicate’s template text, other than the placeholder names.

>>> talked = Predicate(content="$speaker talked to $listener")
>>> spoke = Predicate(content="$speaker spoke to $listener")
>>> talked.means(spoke)
False

The means method will also return False if there are differences in which placeholders are marked as interchangeable.

>>> game_between_others = Predicate(
...     content="$organizer1 and $organizer2 planned for $player1 to play $game against $player2.")
>>> game_between_each_other = Predicate(
...     content="$organizer1 and $organizer2 planned for $organizer1 to play $game against $organizer2.")
>>> game_between_others.means(game_between_each_other)
False
Parameters

other (Any) – an object to compare

Return type

bool

Returns

whether other is another Predicate with the same text, truth value, and pattern of interchangeable placeholders

same_content_meaning(other)

Test if content strings of self and other have same meaning.

Parameters

other (PhraseABC) – another Predicate being compared to self

Return type

bool

Returns

whether self and other have content strings similar enough to be considered to have the same meaning.

same_term_positions(other)

Test if self and other have same positions for interchangeable Terms.

Return type

bool

property template: nettlesome.predicates.StatementTemplate

A text template for the predicate.

Return type

StatementTemplate

Returns

a StatementTemplate object

term_index_permutations()

Get the arrangements of all this Predicate’s terms that preserve the same meaning.

Return type

List[Tuple[int, …]]

term_positions()

Create list of positions that each term could take without changing Predicate’s meaning.

Assumes that if placeholders are the same except for a final digit, that means they’ve been labeled as interchangeable with one another.

Return type

Dict[str, Set[int]]

class nettlesome.predicates.Predicate(**data)

A statement about real events or about a legal conclusion.

Should contain an English-language phrase in the past tense. The past tense is used because legal analysis is usually backward-looking, determining the legal effect of past acts or past conditions.

Don’t use capitalization or end punctuation to signal the beginning or end of the phrase, because the phrase may be used in a context where it’s only part of a longer sentence.

If you need to mention the same term more than once in a Predicate, use the same placeholder for that term each time. If you later create a Fact object using the same Predicate, you will only include each unique term once.

>>> # the template has two placeholders referring to the identical term
>>> opened = Predicate(content="$applicant opened a bank account for $applicant and $cosigner")

Sometimes, a Predicate or Comparison needs to mention two terms that are different from each other, but that have interchangeable positions in that particular phrase. To convey interchangeability, the template string should use identical text for the placeholders for the interchangeable terms, except that the different placeholders should each end with a different digit.

>>> # the template has two placeholders referring to different but interchangeable terms
>>> members = Predicate(content="$relative1 and $relative2 both were members of the same family")
Parameters
  • template – a clause containing an assertion in English in the past tense, with placeholders showing where references to specific terms from the case can be inserted to make the clause specific. This string must be a valid Python string.Template.

  • truth – indicates whether the clause in content is asserted to be true or false. None indicates an assertion as to “whether” the clause is true or false, without specifying which.

__hash__ = None
__str__()

Return str(self).

__weakref__

list of weak references to the object (if defined)

negated()

Copy self, with the opposite truth value.

Return type

Predicate

class nettlesome.predicates.StatementTemplate(template, make_singular=True)

A text template for a Predicate.

Should include placeholders for any replaceable Terms that can be substituted into the Predicate.

__init__(template, make_singular=True)

Identify placeholders in template text, and make verbs singular if needed.

>>> school_template = StatementTemplate(
... "$group were at school", make_singular=True)
>>> str(school_template)
'StatementTemplate("$group was at school")'

The make_singular flag only affects verbs immediately after Terms.

>>> text = "$group thought the exams were difficult"
>>> exams_template = StatementTemplate(text, make_singular=True)
>>> str(exams_template)
'StatementTemplate("$group thought the exams were difficult")'
Parameters
  • template (str) – text for creating a string.Template

  • make_singular (bool) – whether “were” after a placeholder should be converted to singular “was”

__str__()

Return str(self).

Return type

str

get_template_with_plurals(context)

Get a version of self with “was” replaced by “were” for any plural terms.

Does not modify this object’s template attribute.

Return type

str

get_term_sequence_from_mapping(term_mapping)

Get an ordered list of terms from a mapping of placeholder names to terms.

Return type

TermSequence

make_content_singular()

Convert template text for self.context to singular “was”.

Return type

None

mapping_placeholder_to_term(context)

Get a mapping of template placeholders to context terms.

Parameters

context (Sequence[Term]) – a list of context factors.Factor/s, in the same order they appear in the template string.

Return type

Dict[str, Comparable]

mapping_placeholder_to_term_name(context)

Get a mapping of template placeholders to the names of their context terms.

Parameters

context (Sequence[Term]) – a list of Comparable context terms in the same order they appear in the template string.

Return type

Dict[str, str]

property placeholders: List[str]

List substrings of template text marked as placeholders.

Return type

List[str]

substitute_with_plurals(terms)

Update template text with strings representing Comparable terms.

Parameters

context – terms with .short_string() methods to substitute into template, and optionally with plural attributes to indicate whether to change the word “was” to “were”

Return type

str

Returns

updated version of template text