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

Code

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, regime=None, mentioned=None, report_mentioned=False)

Load a list of Holdings from JSON.

Parameters
  • filename (Optional[str]) – the name of the JSON file to look in for Rule 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.

  • mentioned (Optional[List[Factor]]) – A list of Factors that the method needs to expect to find in the Opinion’s holdings, but that won’t be provided within the JSON, if any.

  • report_mentioned (bool) –

Parame regime

Return type

Union[List[Holding], Tuple[List[Holding], Dict[Factor, List[TextQuoteSelector]]]]

Returns

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

authorityspoke.io.loaders.load_opinion(filename=None, directory=None, filepath=None, lead_only=True, as_generator=False)

Create and return one or more Opinion objects from JSON.

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.

  • lead_only (bool) – If True, returns a single Opinion object, otherwise returns an iterator that yields every Opinion in the case.

  • as_generator (bool) – if True, returns a generator that yields all opinions meeting the query.

Return type

Union[Opinion, Iterator[Opinion], List[Opinion]]