Loaders

Functions to load JSON or XML files for conversion into authorityspoke objects.

Will usually hand off data to the io.readers module to create authorityspoke objects.

authorityspoke.io.loaders.load_code(filename=None, directory=None, filepath=None)

Create a new Code from an XML filepath.

Defers parsing of the XML until later, which makes “read” in the function name misleading.

Parameters
  • filename (Optional[str]) – Name of the XML file representing the Code. Ignored if filepath is given.

  • directory (Optional[Path]) – Directory where the XML file can be found. Ignored if filepath is given.

  • filepath (Optional[Path]) – Complete path to the XML file representing the Code, including filename.

Return type

BeautifulSoup

Returns

new Code object that can be used to parse the XML to find text of Enactments.

authorityspoke.io.loaders.load_holdings(filename=None, directory=None, filepath=None)

Load a list of records from JSON to create Holdings.

Parameters
  • filename (Optional[str]) – the name of the JSON file to look in for Holding data in the format that lists mentioned_factors followed by a list of holdings.

  • directory (Optional[Path]) – the path of the directory containing the JSON file.

  • filepath (Optional[Path]) – Complete path to the XML file representing the Code, including filename.

Parame regime

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[Dict[str, Union[str, List[Union[str, Dict[str, str]]]]]], str, bool]], str, bool]]]

Returns

a list of Holdings from a JSON file in the example_data/holdings subdirectory, from a JSON file.

authorityspoke.io.loaders.load_rules_with_index(filename=None, directory=None, filepath=None, regime=None, many=True)

Read Rules from a file.

Even though this function will generate Rules instead of Holdings, it uses the load_holding() function. Some fields that can exist in a Holding object (rule_valid, decided, exclusive) are not applicable to Rules.

Parameters
  • filename (Optional[str]) – The name of the input JSON file.

  • directory (Optional[Path]) – The directory where the input JSON file is located.

  • filepath (Optional[Path]) – Complete path to the JSON file representing the Opinion, including filename.

  • regime (Optional[Regime]) – The regime to reference for the Enactments mentioned in the holding.

Return type

Tuple[List[Rule], Mentioned]

authorityspoke.io.loaders.load_and_read_holdings(filename=None, directory=None, filepath=None, regime=None)

Read holdings from a file.

Parameters
  • filename (Optional[str]) – The name of the input JSON file.

  • directory (Optional[Path]) – The directory where the input JSON file is located.

  • filepath (Optional[Path]) – Complete path to the JSON file representing the Opinion, including filename.

  • regime (Optional[Regime]) – The regime to reference for the Enactments mentioned in the holding.

Return type

List[Holding]

authorityspoke.io.loaders.load_holdings_with_index(filename=None, directory=None, filepath=None, regime=None)

Read holdings with factor index from a file.

Return type

HoldingsIndexed

authorityspoke.io.loaders.load_holdings_with_anchors(filename=None, directory=None, filepath=None, regime=None)

Read holdings from file, with Opinion text anchors for holdings and factors.

Return type

AnchoredHoldings

authorityspoke.io.loaders.load_decision(filename=None, directory=None, filepath=None)

Load file containing a judicial decision with one or more opinions.

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

Parameters
  • filename (Optional[str]) – The name of the input JSON file.

  • directory (Optional[Path]) – The directory where the input JSON file is located.

  • filepath (Optional[Path]) – Complete path to the JSON file representing the Opinion, including filename.

Return type

Dict[str, Union[str, int, Sequence[Dict[str, str]]]]