YAML Schemas¶
Marshmallow schemas for loading AuthoritySpoke objects from YAML.
Intended for use with human-generated files. Some shortened syntax is allowed.
Base schema for classes that can be cross-referenced by name in input JSON.
Replace data to load with any object with same name in “mentioned”.
Verify that type field is correct and then get rid of it.
Make a specified field a list if it isn’t already a list.
Expand data if it was just a name reference in the JSON input.
Make AuthoritySpoke object out of whatever data has been loaded.
Schema to load Enactments from JSON created from user-created YAML.
>>> enactment_data = { ... "name": "original works", ... "node": "/us/usc/t17/s102", ... "start_date": "1990-12-01", ... "content": ( ... "Copyright protection subsists, in accordance with this title, " ... "in original works of authorship fixed in any tangible medium of expression, " ... "now known or later developed."), ... "selection": [{"suffix": ", in accordance"}, "title,|in original works of authorship|fixed"]} >>> schema = EnactmentSchema() >>> enactment_index = EnactmentIndex() >>> enactment_index.insert_by_name(enactment_data) >>> schema.context["enactment_index"] = enactment_index >>> enactment = schema.load("original works") >>> enactment.selected_text() 'Copyright protection subsists…in original works of authorship…'
Replace data to load with any object with same name in “enactment_index”.
Prepare Enactment to load.
Schema for statements, separate from any claim about their truth or who asserts them.
>>> data = { ... "content": "the distance that $officer pursued $suspect was >= 5 miles" ... } >>> schema = PredicateSchema() >>> predicate = schema.load(data) >>> predicate.quantity <Quantity(5, 'mile')>
Find any reference to a quantity in the content text.
Reduce the number of possible symbols to represent comparisons.
Schema for Entities, which shouldn’t be at the top level of a FactorGroup.
>>> entity = {"name": "Lotus Development Corporation", "generic": False} >>> schema = EntitySchema() >>> factor_index = Mentioned() >>> factor_index.insert_by_name(entity) >>> schema.context["mentioned"] = factor_index >>> loaded = schema.load("Lotus Development Corporation") >>> loaded.generic False
Schema for Facts, which may contain arbitrary levels of nesting.
>>> data = {"content": "the distance that {Officer Lin} pursued {Al} was >= 5 miles"} >>> schema = FactSchema() >>> fact = schema.load(data) >>> print(fact) the fact that the distance that {Officer Lin} pursued {Al} was at least 5 mile
Retrieve known context
Factor
s for newFact
.- Parameters
- Return type
- Returns
the content string with any referenced
Factor
s replaced by placeholder, and a list of referencedFactor
s in the order they appeared in content.
Prepare
RawFact
to load, replacing name references with full objects.Unlike the
name_index.collect_mentioned()
function, this function can’t add any entries to the “mentioned” name index (due to limitations in the Marshmallow serialization library). That means all shorthand references to factors need to have been expanded before using the schema to load new objects.
Make Fact.
- Return type
Schema for an object that may embody a statement.
>>> fact_data = { ... "content": "the distance that $officer pursued $suspect was >= 5 miles", ... "terms": [ ... {"type": "Entity", "name": "Officer Lin"}, ... {"type": "Entity", "name": "Al"}, ... ], ... } >>> exhibit_data = { ... "form": "testimony", ... "statement": fact_data, ... "statement_attribution": {"name": "Officer Lin"}, ... } >>> schema = ExhibitSchema() >>> exhibit = schema.load(exhibit_data) >>> print(exhibit) the testimony attributed to <Officer Lin>, asserting the fact that the distance that <Officer Lin> pursued <Al> was at least 5 mile,
Make Exhibit.
- Return type
Schema for a document to link Allegations to.
Schema for an Allegation of a Fact.
Schema for an Exhibit and a reference to the Fact it would support.
Schema that directs data to “one of” the other schemas.
>>> factor_data = [{"type": "Entity", "name": "Al"}, {"type": "Entity", "name": "Bob"}] >>> schema = FactorSchema(many=True) >>> factors = schema.load(factor_data) >>> factors[1].name 'Bob'
Preprocess data before selecting from among the linked schema options.
To be replaced by a function that would have used the @pre_load decorator, if it was available for OneOfSchema objects.
Return name of object schema.
- Return type
Schema for Procedure; does not require separate TermSequence schema.
“FactorSchema, many=True” is an equivalent of a TermSequence.
Handle omission of brackets around single item.
Schema for Holding; can also hold Procedure fields.
Prepare to load Rule.
Make AuthoritySpoke object out of whatever data has been loaded.
Schema for Holding; can also hold Rule and Procedure fields.
Nest fields inside “rule” and “procedure”, if not already nested.
Alias for field number 0
Alias for field number 1
Expand data if it was just a name reference in the JSON input.
Alias for field number 0
Alias for field number 1
Expand data if it was just a name reference in the JSON input.