Readers

Converting simple structured data from XML or JSON into authorityspoke objects.

These functions will usually be called by functions from the io.loaders module after they import some data from a file.

class authorityspoke.io.readers.HoldingsIndexed(holdings: List[authorityspoke.holdings.Holding], mentioned: authorityspoke.io.name_index.Mentioned, holding_anchors: List[List[anchorpoint.textselectors.TextQuoteSelector]])

Lists Holding objects with corresponding text selectors.

holdings: List[authorityspoke.holdings.Holding]

Alias for field number 0

mentioned: authorityspoke.io.name_index.Mentioned

Alias for field number 1

holding_anchors: List[List[anchorpoint.textselectors.TextQuoteSelector]]

Alias for field number 2

authorityspoke.io.readers.collect_anchors_from_index(object_index, field_name)

Get text anchors out of an index of terms or enactments.

authorityspoke.io.readers.read_holdings_with_anchors(record, client=None)

Load a list of Holdings from JSON, with text links.

Parameters
Return type

AnchoredHoldings

Returns

a namedtuple listing Holding objects with a list matching Holdings to selectors and an index matching Factors to selectors.

authorityspoke.io.readers.expand_factor(record, factor_index)

Expand fields of Factor from index of mentioned factors.

Return type

Union[str, Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]]

authorityspoke.io.readers.expand_names(record, factor_index)

Expand a list of names into a list of factors.

Return type

List[Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]]

authorityspoke.io.readers.expand_enactments(record, enactment_index)

Expand a list of enactments into a list of dicts.

Parameters
Return type

List[RawEnactment]

Returns

a list of dicts representing enactments

authorityspoke.io.readers.walk_tree_and_expand(obj, mentioned, ignore=())

Traverse tree of dicts and lists, and modify each node.

Parameters
  • obj (Union[Dict, List]) – the object to traverse

  • func – the function to call on each dict node, returning a dict

  • ignore (Sequence[str]) – the names of keys that should not be explored

Return type

Union[Dict, List]

Returns

a version of the tree with every node modified by func

authorityspoke.io.readers.expand_holding(record, factor_index, enactment_index)

Expand one holding from index of expanded terms and enactments.

Return type

Dict[str, Union[Dict[str, Union[Dict[str, Sequence[Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]]], Sequence[RawEnactment], str, bool]], str, bool]]

authorityspoke.io.readers.expand_holdings(record, factor_index, enactment_index)

Expand holdings from index of expanded terms and enactments.

Return type

List[Dict[str, Union[Dict[str, Union[Dict[str, Sequence[Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]]], Sequence[RawEnactment], str, bool]], str, bool]]]

authorityspoke.io.readers.extract_anchors_from_holding_record(record, client=None)

Load a list of Holdings from JSON, with text links.

Parameters
Return type

Tuple[List[Holding], List[EnactmentWithAnchors], List[TermWithAnchors], List[Dict[str, str]]]

Returns

a tuple of four objects containing holdings, terms, enactments, and anchors.

authorityspoke.io.readers.read_holdings(record, client=None)

Load a list of Holdingss from JSON.

Parameters

record (List[Dict[str, Union[Dict[str, Union[Dict[str, Sequence[Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]]], Sequence[RawEnactment], str, bool]], str, bool]]]) – a list of dicts representing holdings, in the JSON input format

Parame regime

A collection of Jurisdictions and the Codes that have been enacted in each. Used for constructing Enactments referenced by Holdings.

Return type

List[Holding]

Returns

a list of Holding objects

authorityspoke.io.readers.read_decision(decision)

Create and return a Decision from a dict API response.

Relies on the JSON format from the Caselaw Access Project API.

Parameters

decision_dict – A dict created from a Caselaw Access Project API response.

Return type

DecisionReading