Skip to content

Commit

Permalink
remove get_named_anchors
Browse files Browse the repository at this point in the history
The JSON loading process doesn't include this feature anymore
  • Loading branch information
mscarey committed Mar 7, 2021
1 parent 6b5b1e6 commit ba586df
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 55 deletions.
46 changes: 0 additions & 46 deletions authorityspoke/io/anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,6 @@ def read_selector(record: RawSelector) -> TextQuoteSelector:
return selector_schema.load(record)


def read_selectors(record: Iterable[RawSelector]) -> List[TextQuoteSelector]:
r"""
Create list of :class:`.TextQuoteSelector`\s from JSON user input.
If the input is a :class:`str`, tries to break up the string
into :attr:`~TextQuoteSelector.prefix`, :attr:`~TextQuoteSelector.exact`,
and :attr:`~TextQuoteSelector.suffix`, by splitting on the pipe characters.
:param record:
a string or dict representing a text passage, or list of
strings and dicts.
:returns: a list of :class:`TextQuoteSelector`\s
"""
selector_schema = SelectorSchema(many=True)
return selector_schema.load(record)


def collect_anchors(obj: Dict) -> List[TextQuoteSelector]:
r"""Get list containing any available text anchors."""
anchors = obj.get("anchors") or []
Expand All @@ -58,34 +40,6 @@ def collect_anchors(obj: Dict) -> List[TextQuoteSelector]:
return selector_schema.load(anchors)


def get_named_anchors(mentioned: Mentioned) -> TextLinkDict:
r"""
Move anchors fields to a dict linking object names to lists of anchors.
To be used during loading of :class:`.Holding`\s.
Keys are :class:`.Factor`\s, :class:`.Enactment`\s, or :class:`.Holding`\s,
and values are lists of the :class:`.Opinion` passages that reference them.
Assumes that the value of the anchors field is a list (not a dict representing a
single text anchor, and not a string in the "shorthand" anchor format).
:param mentioned:
a dict representing named :class:`.Factor`\s and :class:`.Enactment`\s
:returns:
a dict with keys from the mentioned dict, where each key has as its value
just the "anchors" field from the corresponding dict in "mentioned"
"""
anchors: TextLinkDict = defaultdict(list)
for key, value in mentioned.items():
if "anchors" in value:
for anchor in value["anchors"]:
anchors[key].append(anchor)
for key in anchors:
anchors[key] = read_selectors(anchors[key])
return anchors


def get_holding_anchors(
record: Union[RawHolding, List[RawHolding]]
) -> List[List[TextQuoteSelector]]:
Expand Down
2 changes: 1 addition & 1 deletion authorityspoke/io/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def load_and_read_holdings(
filepath: Optional[pathlib.Path] = None,
client: Optional[Client] = None,
) -> List[Holding]:
"""
r"""
Read holdings from a file.
:param filename: The name of the input JSON file.
Expand Down
4 changes: 2 additions & 2 deletions authorityspoke/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def __add__(self, other) -> Optional[Rule]:
The new ``universal`` and ``mandatory`` values are the
lesser of the old values for each.
Don't test whether ``self`` could be triggered by the outputs
of other. Let user do ``other + self`` for that.
Does not test whether ``self`` could be triggered by the outputs
of other. Use ``other + self`` for that.
:param other:
another :class:`Rule` to try to add to ``self``
Expand Down
6 changes: 0 additions & 6 deletions tests/io/test_anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,3 @@ def test_anchor_not_wrapped_in_list(self):
"""
selector = anchors.read_selector(self.fact_string_anchor["anchors"])
assert selector.exact.startswith("In preparing")

def test_make_enactment_anchor(self):
record, mentioned = index_names(self.enactment_anchor)
named_anchors = anchors.get_named_anchors(mentioned)
enactment_anchors = named_anchors["copyright protection provision"]
assert enactment_anchors[0].exact == "17 U.S.C. § 102(a)"

0 comments on commit ba586df

Please sign in to comment.