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_holdings(filename=None, directory=None, filepath=None)

Load list of records from YAML or JSON to create Holdings with text selectors.

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.

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]]]

Returns

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

authorityspoke.io.loaders.read_holdings_from_file(filename=None, directory=None, filepath=None, client=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.

  • client (Optional[Client]) – The client with an API key to download Enactments mentioned in the holding.

Return type

List[Holding]

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

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

This function can accept a file containing authorityspoke.holdings.Holding summaries in the YAML format that may contain abbreviations and expandable named entities.

In the example below, a FakeClient is used to add fields to Enactments in the Holding objects, to avoid using the network or making API calls. The real LegisClient class would also have worked (with an appropriate API key).

>>> from authorityspoke.io.fake_enactments import FakeClient
>>> fake_client = FakeClient.from_file("usc.json")
>>> filepath = filepaths.make_filepath(filename="holding_mazza_alaluf.yaml")
>>> with open(filepath, "r") as f:
...     yaml.safe_load(f)
[{'inputs': [{'type': 'fact', 'content': "{Mazza-Alaluf} used Mazza-Alaluf's business {Turismo Costa Brava} to commit the New York offense of engaging in the business of receiving money for transmission or transmitting the same, without a license therefor"}], 'outputs': [{'type': 'fact', 'content': 'Mazza-Alaluf operated Turismo Costa Brava without an appropriate money transmitting license in a State where such operation was punishable as a misdemeanor or a felony under State law', 'anchors': {'quotes': [{'exact': "we conclude that sufficient evidence supports Mazza-Alaluf's convictions under 18 U.S.C. § 1960(b)(1)(A) for conspiring to operate and operating a money transmitting business without appropriate state licenses."}]}, 'name': 'operated without license'}], 'enactments': [{'name': 'state money transmitting license provision', 'enactment': {'node': '/us/usc/t18/s1960/b/1'}, 'anchors': {'quotes': ['state money transmitting licenses, see |18 U.S.C. § 1960(b)(1)(A)|']}, 'selection': {'quotes': [{'exact': 'is operated without an appropriate money transmitting license in a State where such operation is punishable as a misdemeanor or a felony under State law, whether or not the defendant knew that the operation was required to be licensed or that the operation was so punishable'}]}}], 'universal': True}, {'inputs': ['operated without license', {'type': 'fact', 'content': 'Mazza-Alaluf operated Turismo Costa Brava as a business', 'anchors': {'quotes': 'Mazza-Alaluf does not contest that he owned and managed Turismo'}}, {'type': 'fact', 'content': 'Turismo Costa Brava was a money transmitting business', 'anchors': {'quotes': 'record evidence that Turismo conducted substantial money transmitting business in the three states'}}], 'despite': [{'type': 'fact', 'content': 'Turismo Costa Brava was a domestic financial institution', 'truth': False, 'anchors': {'quotes': 'without respect to whether or not Turismo was a "domestic financial institution"'}}], 'outputs': [{'type': 'fact', 'content': 'Mazza-Alaluf committed the offense of conducting a money transmitting business without a license required by state law', 'anchors': {'quotes': 'a crime to operate a money transmitting business without appropriate state licenses,'}}], 'enactments': ['state money transmitting license provision'], 'enactments_despite': [{'enactment': {'node': '/us/usc/t31/s5312/b/1'}, 'anchors': {'quotes': ['§ 5312(b)(1) (defining "domestic financial institution")']}}], 'anchors': {'quotes': [{'prefix': 'Accordingly, we conclude that the', 'suffix': 'In any event'}]}, 'universal': True, 'mandatory': True}]
>>> result = read_anchored_holdings_from_file(filepath=filepath, client=fake_client)
>>> selection = result.get_term_anchors("the fact it was false that <Turismo Costa Brava> was a domestic financial institution")
>>> selection.quotes[0].exact
'without respect to whether or not Turismo was a "domestic financial institution"'
>>> print(result.holdings[0].holding.outputs[0])
the fact that <Mazza-Alaluf> operated <Turismo Costa Brava> without an appropriate money transmitting license in a State where such operation was punishable as a misdemeanor or a felony under State law
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]]]]

authorityspoke.io.loaders.load_decision_as_reading(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

DecisionReading