Skip to content

Commit

Permalink
delete enactment_index module
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Oct 14, 2021
1 parent a9b9900 commit 0462a9d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 103 deletions.
80 changes: 0 additions & 80 deletions authorityspoke/io/enactment_index.py

This file was deleted.

40 changes: 25 additions & 15 deletions authorityspoke/io/name_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,10 @@ def update_name_index_with_factor(
return obj, mentioned


def ensure_enactment_has_name(obj: RawEnactment) -> RawEnactment:
"""Create "name" field for unloaded Enactment data, if needed."""
if not obj.get("name"):
new_name = create_name_for_enactment(obj)
if new_name:
obj["name"] = new_name
return obj


def collect_mentioned(
obj: Union[RawFactor, List[Union[RawFactor, str]]],
mentioned: Optional[Mentioned] = None,
keys_to_ignore: Sequence[str] = (
ignore: Sequence[str] = (
"predicate",
"anchors",
"factor_anchors",
Expand All @@ -364,18 +355,16 @@ def collect_mentioned(
if isinstance(obj, List):
new_list = []
for item in obj:
new_item, new_mentioned = collect_mentioned(item, mentioned, keys_to_ignore)
new_item, new_mentioned = collect_mentioned(item, mentioned, ignore)
mentioned.update(new_mentioned)
new_list.append(new_item)
obj = new_list
if isinstance(obj, Dict):
obj, mentioned = update_name_index_from_fact_content(obj, mentioned)
new_dict = {}
for key, value in obj.items():
if key not in keys_to_ignore and isinstance(value, (Dict, List)):
new_value, new_mentioned = collect_mentioned(
value, mentioned, keys_to_ignore
)
if key not in ignore and isinstance(value, (Dict, List)):
new_value, new_mentioned = collect_mentioned(value, mentioned, ignore)
mentioned.update(new_mentioned)
new_dict[key] = new_value
else:
Expand All @@ -397,6 +386,27 @@ def collect_mentioned(
return obj, mentioned


def collect_enactments(
obj: Union[RawFactor, List[Union[RawFactor, str]]],
mentioned: Optional[Mentioned] = None,
ignore: Sequence[str] = (
"predicate",
"anchors",
"children",
"inputs",
"despite",
"outputs",
"selection",
),
) -> Tuple[RawFactor, Mentioned]:
"""
Make a dict of all nested objects labeled by name, creating names if needed.
To be used during loading to expand name references to full objects.
"""
return collect_mentioned(obj=obj, mentioned=mentioned, ignore=ignore)


def index_names(record: Union[List, Dict]) -> Mentioned:
"""
Call all functions to prepare "mentioned" index.
Expand Down
3 changes: 1 addition & 2 deletions authorityspoke/io/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from authorityspoke.facts import RawFactor
from authorityspoke.procedures import Procedure

from authorityspoke.io.name_index import index_names, Mentioned
from authorityspoke.io.enactment_index import collect_enactments
from authorityspoke.io.name_index import index_names, Mentioned, collect_enactments
from authorityspoke.io.text_expansion import expand_shorthand

RawSelector = Union[str, Dict[str, str]]
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
import pytest

from authorityspoke.decisions import DecisionReading
from authorityspoke.facts import Allegation, Fact, build_fact, Evidence
from authorityspoke.facts import Allegation, Fact, build_fact, Evidence, RawFactor
from authorityspoke.facts import Exhibit, Pleading
from authorityspoke.holdings import Holding, RawHolding
from authorityspoke.opinions import Opinion, OpinionReading, AnchoredHoldings
from authorityspoke.rules import Procedure, Rule

from authorityspoke.io import loaders, readers
from authorityspoke.io.enactment_index import RawFactor
from authorityspoke.io.fake_enactments import FakeClient

load_dotenv()
Expand Down
7 changes: 5 additions & 2 deletions tests/io/test_enactment_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

from legislice.enactments import Enactment

from authorityspoke.io.enactment_index import Mentioned, collect_enactments
from authorityspoke.io.name_index import update_name_index_with_factor
from authorityspoke.io.name_index import (
update_name_index_with_factor,
Mentioned,
collect_enactments,
)

load_dotenv()

Expand Down
4 changes: 2 additions & 2 deletions tests/io/test_name_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from legislice.download import Client

from authorityspoke.io import loaders, readers
from authorityspoke.io import name_index, text_expansion, enactment_index
from authorityspoke.io import name_index, text_expansion


load_dotenv()
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_enactment_name_index(self):
'Name "securing the right to writings" not found in the index of mentioned Factors'
"""
feist_records = loaders.load_holdings("holding_feist.yaml")
record, mentioned = enactment_index.collect_enactments(feist_records)
record, mentioned = name_index.collect_enactments(feist_records)
assert "securing the right to writings" in mentioned

def test_context_factor_not_collapsed(self, fake_usc_client):
Expand Down

0 comments on commit 0462a9d

Please sign in to comment.