Schemas

Marshmallow schemas for loading AuthoritySpoke objects from JSON.

class authorityspoke.io.schemas.ExpandableSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Base schema for classes that can be cross-referenced by name in input JSON.

get_from_mentioned(data, **kwargs)

Replace data to load with any object with same name in “mentioned”.

consume_type_field(data, **kwargs)

Verify that type field is correct and then get rid of it.

wrap_single_element_in_list(data, many_element)

Make a specified field a list if it isn’t already a list.

format_data_to_load(data, **kwargs)

Expand data if it was just a name reference in the JSON input.

Return type

Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]

make_object(data, **kwargs)

Make AuthoritySpoke object out of whatever data has been loaded.

class authorityspoke.io.schemas.CaseCitationSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Decision citations in CAP API response.

make_object(data, **kwargs)

Load citation.

Return type

CaseCitation

class authorityspoke.io.schemas.OpinionSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Opinions, of which there may be several in one Decision.

format_data_to_load(data, **kwargs)

Standardize author name before loading object.

Return type

Dict[str, str]

class authorityspoke.io.schemas.DecisionSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for decisions retrieved from Caselaw Access Project API.

format_data_to_load(data, **kwargs)

Transform data from CAP API response for loading.

Return type

Dict[str, Union[str, int, Sequence[Dict[str, str]]]]

authorityspoke.io.schemas.dump_quantity(obj)

Convert quantity to string if it’s a pint ureg.Quantity object.

Return type

Union[date, float, int, str, None]

class authorityspoke.io.schemas.PredicateSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for statements, separate from any claim about their truth or who asserts them.

split_quantity_from_content(content)

Find any reference to a quantity in the content text.

Return type

Tuple[str, Optional[str], Union[Quantity, int, float, None]]

normalize_comparison(data, **kwargs)

Reduce the number of possible symbols to represent comparisons.

Return type

Dict[str, Union[str, bool]]

format_data_to_load(data, **kwargs)

Expand any reference to a quantity in the content text.

Return type

Dict[str, Union[str, bool]]

class authorityspoke.io.schemas.EntitySchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Entities, which shouldn’t be at the top level of a FactorGroup.

class authorityspoke.io.schemas.FactSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Facts, which may contain arbitrary levels of nesting.

get_references_from_mentioned(content, terms=None, placeholder='{}')

Retrieve known context Factors for new Fact.

Parameters
  • content (str) – the content for the Fact's Predicate

  • mentioned – list of Factors with names that could be referenced in content

  • placeholder (str) – a string to replace the names of referenced Factors in content

Return type

Tuple[str, List[Dict]]

Returns

the content string with any referenced Factors replaced by placeholder, and a list of referenced Factors in the order they appeared in content.

format_data_to_load(data, **kwargs)

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.

Parameters

data (Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]) – a dict representing a Fact

Return type

Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]

Returns

a normalized dict representing a Facts with name references expanded

make_object(data, **kwargs)

Make Fact.

Return type

Fact

class authorityspoke.io.schemas.ExhibitSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for an object that may embody a statement.

make_object(data, **kwargs)

Make Exhibit.

Return type

Exhibit

class authorityspoke.io.schemas.PleadingSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for a document to link Allegations to.

class authorityspoke.io.schemas.AllegationSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for an Allegation of a Fact.

class authorityspoke.io.schemas.EvidenceSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for an Exhibit and a reference to the Fact it would support.

class authorityspoke.io.schemas.FactorSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema that directs data to “one of” the other schemas.

pre_load(data, **kwargs)

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 type

Dict[str, Union[Dict[str, Union[str, bool]], Sequence[Any], str, bool]]

get_obj_type(obj)

Return name of object schema.

Return type

str

class authorityspoke.io.schemas.ProcedureSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Procedure; does not require separate FactorSequence schema.

“FactorSchema, many=True” is an equivalent of a FactorSequence.

format_data_to_load(data, **kwargs)

Handle omission of brackets around single item.

class authorityspoke.io.schemas.RuleSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Holding; can also hold Procedure fields.

format_data_to_load(data, **kwargs)

Prepare to load Rule.

Return type

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

make_object(data, **kwargs)

Make AuthoritySpoke object out of whatever data has been loaded.

class authorityspoke.io.schemas.HoldingSchema(*, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)

Schema for Holding; can also hold Rule and Procedure fields.

nest_fields_inside_rule(data)

Nest fields inside “rule” and “procedure”, if not already nested.

Return type

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

format_data_to_load(data, **kwargs)

Prepare to load Holding.

Return type

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

authorityspoke.io.schemas.get_schema_for_item(item)

Find the Marshmallow schema for an AuthoritySpoke object.

Return type

Schema