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.

authorityspoke.io.readers.get_code_uri(xml, title)

Build a URI for the Code based on its XML metadata.

Note

This handles California state statutes only with a mockup, which can only refer to the Penal and Evidence Codes.

Return type

str

Returns

The United States Legislative Markup (USLM) identifier that describes the document as a whole, if available in the XML. Otherwise returns a pseudo-USLM identifier.

authorityspoke.io.readers.get_code_title(xml)

Provide “title” identifier for the Code XML.

Return type

str

Returns

the contents of an XML title element that describes the Code, if any. Otherwise returns a descriptive name that may not exactly appear in the XML.

authorityspoke.io.readers.has_uslm_schema(soup)

Determine if the Code XML has the USLM schema.

Return type

bool

authorityspoke.io.readers.read_enactment(record, code=None, regime=None)

Create a new Enactment object using imported JSON data.

The new Enactment can be composed from a Code referenced in the regime parameter.

Parameters
Return type

Enactment

Returns

a new Enactment object, optionally with text links.

authorityspoke.io.readers.read_enactments(record, code=None, regime=None)

Create a new Enactment object using imported JSON data.

The new Enactment can be composed from a Code referenced in the regime parameter.

Parameters
Return type

List[Enactment]

Returns

a list of new Enactment objects, optionally with text links.

authorityspoke.io.readers.read_fact(record)

Construct a Fact after loading a dict from JSON.

Parameters

record (Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]) – parameter values to pass to FactSchema.

Return type

Fact

Returns

a Fact, with optional mentioned factors

authorityspoke.io.readers.read_factor(record, regime=None, **kwargs)

Turn fields from JSON into a Factor object.

Parameters

record (Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]) – parameter values to pass to schema

Parame regime

to look up any Enactment references

Return type

Factor

authorityspoke.io.readers.read_factors(record, regime=None, **kwargs)

Turn fields from JSON into a Factor object.

Parameters

record (List[Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]]) – parameter values to pass to schema

Parame regime

to look up any Enactment references

Return type

Factor

authorityspoke.io.readers.read_holding(record, regime=None)

Create new Holding object from simple datatypes from JSON input.

Will yield multiple items if exclusive: True is present in record.

Parameters
Return type

Holding

Returns

New Holding, and an updated dictionary with mentioned Factors as keys and their TextQuoteSelectors as values.

class authorityspoke.io.readers.HoldingsIndexed(holdings, mentioned, holding_anchors)
property holdings

Alias for field number 0

property mentioned

Alias for field number 1

property holding_anchors

Alias for field number 2

authorityspoke.io.readers.read_holdings(record, regime=None, code=None)

Load a list of Holdingss from JSON, with optional text links.

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[Dict[str, Union[str, List[Union[str, Dict[str, str]]]]]], 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, optionally with an index matching Factors to selectors.

authorityspoke.io.readers.read_decision(decision_dict)

Create and return one or more Opinion objects from a dict API response.

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

This function is a more convenient way to call read_opinions with an entire case from the CAP API as a single parameter.

Parameters

decision_dict (Dict[str, Union[str, int, Sequence[Dict[str, str]]]]) – A dict created from a Caselaw Access Project API response.

Return type

Decision

authorityspoke.io.readers.read_rule(record, regime=None)

Make Rule from a dict of fields and a Regime.

Parameters
Return type

Rule

Returns

iterator yielding Rules with the items from mentioned_entities as context_factors

authorityspoke.io.readers.read_rules(record, regime=None)

Make Rules from a list of fields and a Regime.

Parameters
Return type

Rule

Returns

iterator yielding Rules with the items from mentioned_entities as context_factors