Skip to content

Commit

Permalink
remove Nettlesome models from JSON schemas
Browse files Browse the repository at this point in the history
inherit the schemas from Nettlesome instead
  • Loading branch information
mscarey committed May 2, 2021
1 parent ba9ddec commit 377403e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 61 deletions.
59 changes: 3 additions & 56 deletions authorityspoke/io/schemas_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@
Should be suitable for generating an OpenAPI specification.
"""

from datetime import date
from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Tuple, Type, Union
from typing import Dict, List, NamedTuple, Optional, Sequence, Tuple, Type, Union

from marshmallow import Schema, fields, validate, EXCLUDE
from marshmallow import Schema, fields, EXCLUDE
from marshmallow import pre_load, post_load
from marshmallow_oneofschema import OneOfSchema

from anchorpoint.textselectors import TextQuoteSelector, TextPositionSelector
from anchorpoint.schemas import SelectorSchema
from legislice import Enactment
from legislice.schemas import EnactmentSchema
from nettlesome.entities import Entity
from nettlesome.predicates import Predicate
from nettlesome.quantities import Comparison, QuantityRange, Quantity
from nettlesome.schemas import PredicateSchema, EntitySchema, RawFactor

from authorityspoke.decisions import CaseCitation, Decision
from authorityspoke.evidence import Exhibit, Evidence
from nettlesome.factors import Factor
from authorityspoke.facts import Fact
from authorityspoke.holdings import Holding
from authorityspoke.io.name_index import RawFactor, RawPredicate
from authorityspoke.opinions import Opinion
from authorityspoke.pleadings import Pleading, Allegation

from authorityspoke.procedures import Procedure
from authorityspoke.rules import Rule

Expand Down Expand Up @@ -123,54 +118,6 @@ def make_object(self, data, **kwargs):
return self.__model__(**data)


def dump_quantity(obj: Predicate) -> Optional[Union[date, float, int, str]]:
"""Convert quantity to string if it's a pint ureg.Quantity object."""
if not hasattr(obj, "quantity"):
return None
if isinstance(obj.quantity, date):
return obj.quantity.isoformat()
if isinstance(obj.quantity, (int, float)):
return obj.quantity
return f"{obj.quantity.magnitude} {obj.quantity.units}"


class PredicateSchema(Schema):
"""Schema for statements, separate from any claim about their truth or who asserts them."""

__model__ = Predicate
content = fields.Str()
truth = fields.Bool(missing=True)
sign = fields.Str(
missing=None,
validate=validate.OneOf([""] + list(QuantityRange.opposite_comparisons.keys())),
)
expression = fields.Function(
dump_quantity, deserialize=Comparison.read_quantity, missing=None
)

@post_load
def make_object(self, data, **kwargs):
"""Make either a Predicate or a Comparison."""
if data.get("expression") is not None:
return Comparison(**data)
data.pop("expression", None)
data.pop("sign", None)
return self.__model__(**data)


class EntitySchema(Schema):
"""Schema for Entities, which shouldn't be at the top level of a FactorGroup."""

__model__: Type = Entity
name = fields.Str(missing=None)
generic = fields.Bool(missing=True)
plural = fields.Bool()

@post_load
def make_object(self, data: Dict[str, Union[bool, str]], **kwargs) -> CaseCitation:
return self.__model__(**data)


class FactSchema(Schema):
"""Schema for Facts, which may contain arbitrary levels of nesting."""

Expand Down
7 changes: 6 additions & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
marshmallow
apispec[validation]~=4.3.0
apispec-oneofschema
legislice>=0.5.0
marshmallow>=3.10
marshmallow-oneofschema
nettlesome>=0.5.0
pint>=0.15
python-slugify
requests
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
anchorpoint>=0.4.4
apispec[validation]~=4.3.0
apispec-oneofschema
legislice>=0.5.0
marshmallow>=3.10
marshmallow-oneofschema
legislice>=0.5.0
git+git://github.com/mscarey/nettlesome.git@56506e16bb50c980705bac98560677f5a089ce05#egg=nettlesome
nettlesome>=0.4.0
nettlesome>=0.5.0
pint>=0.15
python-dotenv
python-slugify
pyyaml
requests
roman
sympy
sympy>=1.7.1

0 comments on commit 377403e

Please sign in to comment.