Skip to content

Commit

Permalink
update doctest about making contradictory Rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Oct 12, 2021
1 parent 5352e16 commit e3ad0b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion authorityspoke/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from nettlesome.quantities import Comparison

from .decisions import DecisionReading
from .facts import Fact
from .facts import Fact, Exhibit, Evidence, Allegation, Pleading
from .holdings import Holding
from .opinions import Opinion, OpinionReading
from .rules import Rule
Expand Down
47 changes: 23 additions & 24 deletions docs/guides/statute_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ contradict one another.
For instance, if we create a new Rule that’s identical to the first Rule
in the Beard Tax Act except that it applies to facial hair that’s
exactly 8 millimeters long instead of “no shorter than 5 millimetres”,
we can determine that the original “chin rule” implies our new Rule.
we can determine that the original “chin rule”
:meth:`~authorityspoke.rules.Rule.implies` our new :class:`~authorityspoke.rules.Rule`\.

>>> from authorityspoke.io import readers
>>> beard_rule_data[0]['inputs'][1]['content'] = 'the length of the suspected beard was = 8 millimetres'
Expand Down Expand Up @@ -166,30 +167,28 @@ thanks to the `pint <https://pint.readthedocs.io/en/stable/>`__
library). And we can show that this new Rule contradicts a Rule that
came from the Beard Tax Act.

>>> beard_rule_data[1]["despite"] = [
... beard_rule_data[1]["inputs"][0],
... beard_rule_data[1]["inputs"][2]]
>>> beard_rule_data[1]["inputs"] = {
... "type": "fact",
... "content": "the length of the suspected beard was >= 12 inches"}
>>> beard_rule_data[1]["outputs"][0]["truth"] = False
>>> beard_rule_data[1]["mandatory"] = True
>>> changed_holdings = readers.read_holdings(beard_rule_data, client=legis_client)
>>> long_means_not_beard = changed_holdings[1]
>>> from authorityspoke import Fact, Entity
>>> changed_holdings = loaders.read_holdings_from_file("beard_rules.yaml", client=legis_client)
>>> long_means_not_beard = changed_holdings[1].rule
>>> long_means_not_beard.set_despite([ear_rule.inputs[0], ear_rule.inputs[2]])
>>> long_means_not_beard.set_inputs(Fact(
... content="the length of ${the_suspected_beard} was >= 12 inches",
... terms=[Entity(name="the suspected beard")]))
>>> long_means_not_beard.set_outputs(long_means_not_beard.outputs[0].negated())
>>> long_means_not_beard.mandatory = True
>>> print(long_means_not_beard)
the Holding to ACCEPT
the Rule that the court MUST ALWAYS impose the
RESULT:
the fact that <the suspected beard> was a beard
GIVEN:
the fact that the length of <the suspected beard> was at least 12 inch
DESPITE:
the fact that <the suspected beard> was facial hair
the fact that <the suspected beard> existed in an uninterrupted line
from the front of one ear to the front of the other ear below the nose
GIVEN the ENACTMENTS:
"In this Act, beard means any facial hair no shorter than 5 millimetres in length that: occurs on or below the chin…" (/test/acts/47/4 1935-04-01)
"exists in an uninterrupted line from the front of one ear to the front of the other ear below the nose." (/test/acts/47/4/b 1935-04-01)
the Rule that the court MUST ALWAYS impose the
RESULT:
the fact it was false that <the suspected beard> was a beard
GIVEN:
the fact that the length of <the suspected beard> was at least 12 inch
DESPITE:
the fact that <the suspected beard> was facial hair
the fact that <the suspected beard> existed in an uninterrupted line
from the front of one ear to the front of the other ear below the nose
GIVEN the ENACTMENTS:
"In this Act, beard means any facial hair no shorter than 5 millimetres in length that: occurs on or below the chin…" (/test/acts/47/4 1935-04-01)
"exists in an uninterrupted line from the front of one ear to the front of the other ear below the nose." (/test/acts/47/4/b 1935-04-01)
>>> long_means_not_beard.contradicts(ear_rule)
True

Expand Down
19 changes: 19 additions & 0 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,25 @@ def test_greater_than_implies_equal(self, beard_response, make_beard_rule):
longer_hair_rule = readers.read_holdings([beard_dictionary[0]], client=client)
assert make_beard_rule[0].implies(longer_hair_rule[0])

def test_reset_inputs_to_create_contradiction(
self, beard_response, make_beard_rule
):
"""Test missing 'False' truth value in output of long_means_not_beard"""
ear_rule = make_beard_rule[1]
client = FakeClient(responses=beard_response)
beard_rule_data = loaders.load_holdings("beard_rules.yaml")[:2]
changed_holdings = readers.read_holdings(beard_rule_data, client=client)
long_means_not_beard = changed_holdings[1]
long_means_not_beard.set_despite([ear_rule.inputs[0], ear_rule.inputs[2]])
fact = Fact(
content="the length of ${the_suspected_beard} was >= 12 inches",
terms=[Entity(name="the suspected beard")],
)
long_means_not_beard.set_inputs(fact)
long_means_not_beard.set_outputs(long_means_not_beard.outputs[0].negated())
long_means_not_beard.rule.mandatory = True
assert long_means_not_beard.contradicts(ear_rule)

def test_greater_than_contradicts_not_greater(
self, beard_response, make_beard_rule
):
Expand Down

0 comments on commit e3ad0b3

Please sign in to comment.