Skip to content

Commit

Permalink
update example in statute_rules guide
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Jan 2, 2020
1 parent 46ede28 commit 17f144a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion authorityspoke/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .rules import Rule
from .io.dump import to_dict, to_json

__version__ = "0.3.3"
__version__ = "0.3.4"
20 changes: 13 additions & 7 deletions authorityspoke/holdings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from itertools import chain
import operator
from typing import Any, Dict, Iterator, List, Tuple
from typing import Optional, Union
from typing import Any, Dict, Iterator, List
from typing import Optional, Sequence, Tuple, Union

from dataclasses import dataclass

Expand Down Expand Up @@ -282,7 +282,10 @@ def _explanations_implies_if_not_exclusive(
self.explanations_same_meaning(other.negated(), context),
)

def implies(self, other: Factor, context: ContextRegister = None) -> bool:
def __ge__(self, other: Optional[Factor]) -> bool:
return self.implies(other)

def implies(self, other: Optional[Factor], context: ContextRegister = None) -> bool:
r"""
Test for implication.
Expand Down Expand Up @@ -349,9 +352,6 @@ def implied_by(
return Holding(rule=other).implies(self, context=context)
return other.implies(self, context=context)

def __ge__(self, other: Union[Holding, Rule]) -> bool:
return self.implies(other)

def _implies_if_decided(
self, other: Holding, context: Optional[ContextRegister] = None
) -> Iterator[ContextRegister]:
Expand Down Expand Up @@ -407,7 +407,7 @@ def inferred_from_exclusive(self) -> List[Holding]:
]
return []

def evolve(self, changes: Union[str, Tuple[str, ...], Dict[str, Any]]) -> Holding:
def evolve(self, changes: Union[str, Sequence[str], Dict[str, Any]]) -> Holding:
"""
Make new object with attributes from ``self.__dict__``, replacing attributes as specified.
Expand Down Expand Up @@ -523,6 +523,9 @@ def _union_with_holding(
def union(
self, other: Union[Rule, Holding], context: Optional[ContextRegister] = None
) -> Optional[Holding]:
"""
Infer a Holding from all inputs and outputs of self and other, in context.
"""
context = context or ContextRegister()
if isinstance(other, Rule):
other = Holding(rule=other)
Expand All @@ -531,6 +534,9 @@ def union(
return self._union_with_holding(other, context=context)

def __or__(self, other: Union[Rule, Holding]) -> Optional[Holding]:
"""
Infer a Holding from all inputs and outputs of self and other.
"""
return self.union(other)

def own_attributes(self) -> Dict[str, Any]:
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

0.3.4 (2020-01-02)
-----------
- Create broader conditions for Procedure.contradicts()

0.3.3 (2020-01-01)
-----------
- Add `__init__.py` to utils folder
Expand Down
21 changes: 12 additions & 9 deletions docs/guides/statute_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,15 @@ contradicts a Rule that came from the Beard Tax Act.

.. code:: python
beard_dictionary[1]['inputs'][1]['content'] = 'the length of the suspected beard was >= 12 inches'
beard_dictionary[1]['outputs'][0]['truth'] = False
beard_dictionary[1]['mandatory'] = True
long_hair_is_not_a_beard = readers.read_rule(beard_dictionary[1], beard_act)
print(long_hair_is_not_a_beard)
beard_dictionary[1]["despite"] = beard_dictionary[1]["inputs"][0]
beard_dictionary[1]["inputs"] = {
"type": "fact",
"content": "the length of the suspected beard was >= 12 inches",
}
beard_dictionary[1]["outputs"][0]["truth"] = False
beard_dictionary[1]["mandatory"] = True
long_thing_is_not_a_beard = readers.read_rule(beard_dictionary[1], beard_act)
print(long_thing_is_not_a_beard)
.. parsed-literal::
Expand All @@ -215,10 +219,9 @@ contradicts a Rule that came from the Beard Tax Act.
RESULT:
the Fact it is false that <the suspected beard> was a beard
GIVEN:
the Fact that <the suspected beard> was facial hair
the Fact that the length of <the suspected beard> was at least 12 inch
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
DESPITE:
the Fact that <the suspected beard> was facial hair
GIVEN the ENACTMENTS:
"In this Act, beard means any facial hair no shorter than 5
millimetres in length that:" (Australian Beard Tax (Promotion of
Expand All @@ -230,7 +233,7 @@ contradicts a Rule that came from the Beard Tax Act.
.. code:: python
long_hair_is_not_a_beard.contradicts(ear_rule)
long_thing_is_not_a_beard.contradicts(ear_rule)
Expand Down
21 changes: 12 additions & 9 deletions notebooks/statute_rules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,9 @@
" RESULT:\n",
" the Fact it is false that <the suspected beard> was a beard\n",
" GIVEN:\n",
" the Fact that <the suspected beard> was facial hair\n",
" the Fact that the length of <the suspected beard> was at least 12 inch\n",
" the Fact that <the suspected beard> existed in an uninterrupted line\n",
" from the front of one ear to the front of the other ear below the nose\n",
" DESPITE:\n",
" the Fact that <the suspected beard> was facial hair\n",
" GIVEN the ENACTMENTS:\n",
" \"In this Act, beard means any facial hair no shorter than 5\n",
" millimetres in length that:\" (Australian Beard Tax (Promotion of\n",
Expand All @@ -267,11 +266,15 @@
}
],
"source": [
"beard_dictionary[1]['inputs'][1]['content'] = 'the length of the suspected beard was >= 12 inches'\n",
"beard_dictionary[1]['outputs'][0]['truth'] = False\n",
"beard_dictionary[1]['mandatory'] = True\n",
"long_hair_is_not_a_beard = readers.read_rule(beard_dictionary[1], beard_act)\n",
"print(long_hair_is_not_a_beard)"
"beard_dictionary[1][\"despite\"] = beard_dictionary[1][\"inputs\"][0]\n",
"beard_dictionary[1][\"inputs\"] = {\n",
" \"type\": \"fact\",\n",
" \"content\": \"the length of the suspected beard was >= 12 inches\",\n",
"}\n",
"beard_dictionary[1][\"outputs\"][0][\"truth\"] = False\n",
"beard_dictionary[1][\"mandatory\"] = True\n",
"long_thing_is_not_a_beard = readers.read_rule(beard_dictionary[1], beard_act)\n",
"print(long_thing_is_not_a_beard)"
]
},
{
Expand All @@ -291,7 +294,7 @@
}
],
"source": [
"long_hair_is_not_a_beard.contradicts(ear_rule)"
"long_thing_is_not_a_beard.contradicts(ear_rule)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="AuthoritySpoke",
version="0.3.3",
version="0.3.4",
author="Matt Carey",
author_email="[email protected]",
description="tool for managing structured data about legal authority",
Expand Down
8 changes: 2 additions & 6 deletions tests/test_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ def test_procedure_string_with_entities(self, make_procedure):
make_procedure["c2_irrelevant_inputs"]
)

def test_generic_factors(
self, watt_factor, make_entity, make_evidence, make_procedure
):
def test_generic_factors(self, make_entity, make_procedure, make_evidence):
"""
Finds that for factor f["f7"], it would be consistent with the
other group of factors for f["f7"]'s two slots to be assigned
(0, 1) or (1, 0).
"""
e = make_entity
f = watt_factor
c = make_procedure
assert set(make_procedure["c3"].generic_factors) == {
e["motel"],
e["tree_search"],
Expand All @@ -75,7 +71,7 @@ def test_entities_of_inputs_for_identical_procedure(

def test_wrong_role_for_added_factor(self, watt_factor, make_procedure):
with pytest.raises(ValueError):
new = make_procedure["c1"].add_factor(
_ = make_procedure["c1"].add_factor(
incoming=watt_factor["f8"], role="generic"
)

Expand Down

0 comments on commit 17f144a

Please sign in to comment.