def load_decision( filename: Optional[str] = None, directory: Optional[pathlib.Path] = None, filepath: Optional[pathlib.Path] = None, ) -> RawDecision: r""" Load file containing a judicial decision with one or more opinions. Relies on the JSON format from the `Caselaw Access Project API <https://api.case.law/v1/cases/>`_. :param filename: The name of the input JSON file. :param directory: The directory where the input JSON file is located. :param filepath: Complete path to the JSON file representing the :class:`.Opinion`, including filename. """ validated_filepath = filepaths.make_filepath( filename, directory, filepath, default_folder="cases" ) with open(validated_filepath, "r") as f: decision_dict = json.load(f) return decision_dict
def test_get_yaml_filepath(self): directory = filepaths.get_directory_path("holdings") path = filepaths.make_filepath( filename="holding_feist.yaml", directory=directory ) raw_holdings = loaders.load_holdings(filepath=path) assert raw_holdings[0]["outputs"]["type"] == "fact"
def test_load_from_fake_client(self): fake_client = FakeClient.from_file("usc.json") filepath = filepaths.make_filepath(filename="holding_mazza_alaluf.yaml") result = read_anchored_holdings_from_file(filepath=filepath, client=fake_client) key = "the fact it was false that <Turismo Costa Brava> was a domestic financial institution" anchors = result.get_term_anchors(key) assert anchors.quotes[0].exact.startswith( "without respect to whether or not Turismo" ) assert len(result.holdings) == 2
def load_holdings( filename: Optional[str] = None, directory: Optional[pathlib.Path] = None, filepath: Optional[pathlib.Path] = None, ) -> List[RawHolding]: r""" Load list of records from YAML or JSON to create :class:`.Holding`\s with text selectors. :param filename: the name of the JSON file to look in for :class:`Holding` data in the format that lists ``mentioned_factors`` followed by a list of holdings. :param directory: the path of the directory containing the JSON file. :param filepath: Complete path to the XML file representing the :class:`.Code`, including filename. :returns: a list of :class:`Holding`\s from a JSON file in the ``example_data/holdings`` subdirectory, from a JSON file. """ validated_filepath = filepaths.make_filepath( filename, directory, filepath, default_folder="holdings" ) with open(validated_filepath, "r") as f: if validated_filepath.suffix == ".yaml": holdings = yaml.safe_load(f) else: holdings = json.load(f) return holdings
filename: Optional[str] = None, directory: Optional[pathlib.Path] = None, filepath: Optional[pathlib.Path] = None, ) -> None: r""" Save one case from an API response as a JSON file. :param results: A dict representing a case, in the format of the Caselaw Access Project API. :param filename: Filename (not including the directory) for the file where the downloaded opinion should be saved. :param directory: A :py:class:`~pathlib.Path` object specifying the directory where the downloaded opinion should be saved. If ``None`` is given, the current default is ``example_data/cases``\. :param filepath: Complete path to the location where the JSON file should be saved, including filename. """ validated_filepath = filepaths.make_filepath(filename, directory, filepath, default_folder="cases") with open(validated_filepath, "w") as fp: fp.write(case.json(indent=4))