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.
Load list of records from YAML or JSON to create
Holding
s with text selectors.- Parameters
filename (
Optional
[str
]) – the name of the JSON file to look in forHolding
data in the format that listsmentioned_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 theCode
, including filename.
- Return type
Dict
[str
,Union
[Dict
[str
,Dict
[str
,Union
[Dict
[str
,Union
[str
,bool
]],Sequence
[Any
],str
,bool
]]],Dict
[str
,Dict
[str
,Union
[str
,List
[Union
[str
,Dict
[str
,str
]]]]]],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
Holding
s from a JSON file in theexample_data/holdings
subdirectory, from a JSON file.
Load a list of records from JSON to create
Holding
s.- Parameters
filename (
Optional
[str
]) – the name of the JSON file to look in forHolding
data in the format that listsmentioned_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 theCode
, including filename.
- Return type
Dict
[str
,Union
[Dict
[str
,Dict
[str
,Union
[Dict
[str
,Union
[str
,bool
]],Sequence
[Any
],str
,bool
]]],Dict
[str
,Dict
[str
,Union
[str
,List
[Union
[str
,Dict
[str
,str
]]]]]],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
Holding
s from a JSON file in theexample_data/holdings
subdirectory, from a JSON file.
Read
Rule
s from a file.Even though this function will generate
Rule
s instead ofHolding
s, it uses theload_holding()
function. Some fields that can exist in aHolding
object (rule_valid, decided, exclusive) are not applicable toRule
s.
Read holdings from a file.
- Parameters
- Return type
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 toEnactment
s in the Holding objects, to avoid using the network or making API calls. The realLegisClient
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) {'holdings': [{'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': "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': [{'node': '/us/usc/t18/s1960/b/1', 'anchors': 'state money transmitting licenses, see |18 U.S.C. § 1960(b)(1)(A)|', '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', 'name': 'state money transmitting license provision'}], 'universal': True}, {'inputs': ['operated without license', {'type': 'fact', 'content': 'Mazza-Alaluf operated Turismo Costa Brava as a business', 'anchors': 'Mazza-Alaluf does not contest that he owned and managed Turismo'}, {'type': 'fact', 'content': 'Turismo Costa Brava was a money transmitting business', 'anchors': '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': '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': 'a crime to operate a money transmitting business without appropriate state licenses,'}], 'enactments': ['state money transmitting license provision'], 'enactments_despite': [{'node': '/us/usc/t31/s5312/b/1', 'anchors': ['§ 5312(b)(1) (defining "domestic financial institution")']}], 'anchors': [{'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) >>> selector = result.named_anchors["the fact it was false that <Turismo Costa Brava> was a domestic financial institution"][0] >>> selector.exact 'without respect to whether or not Turismo was a "domestic financial institution"' >>> print(result.holdings[0].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
Load file containing a judicial decision with one or more opinions.
Relies on the JSON format from the Caselaw Access Project API.
- Parameters
- Return type
Load file containing a judicial decision and make an Opinion object.
- Return type