caselawclient.models.documents.comparison
1from typing import TypedDict 2 3import caselawclient.models.documents 4 5 6class AttributeComparison(TypedDict): 7 """Results from a comparison of one attribute across two documents""" 8 9 label: str 10 this_value: str 11 that_value: str 12 match: bool 13 14 15class Comparison(dict[str, AttributeComparison]): 16 def __init__( 17 self, this_doc: "caselawclient.models.documents.Document", that_doc: "caselawclient.models.documents.Document" 18 ): 19 # court, date, title 20 self["court"] = AttributeComparison( 21 label="court", 22 this_value=this_doc.court, 23 that_value=that_doc.court, 24 match=this_doc.court == that_doc.court, 25 ) 26 27 self["date"] = AttributeComparison( 28 label="date", 29 this_value=this_doc.body.document_date_as_string, 30 that_value=that_doc.body.document_date_as_string, 31 match=this_doc.body.document_date_as_string == that_doc.body.document_date_as_string, 32 ) 33 self["name"] = AttributeComparison( 34 label="name", 35 this_value=this_doc.name, 36 that_value=that_doc.name, 37 match=this_doc.name == that_doc.name, 38 ) 39 40 def match(self) -> bool: 41 """Is this comparison an exact match across all attributes?""" 42 return all(x["match"] for x in self.values())
class
AttributeComparison(typing.TypedDict):
7class AttributeComparison(TypedDict): 8 """Results from a comparison of one attribute across two documents""" 9 10 label: str 11 this_value: str 12 that_value: str 13 match: bool
Results from a comparison of one attribute across two documents
class
Comparison(dict[str, caselawclient.models.documents.comparison.AttributeComparison]):
16class Comparison(dict[str, AttributeComparison]): 17 def __init__( 18 self, this_doc: "caselawclient.models.documents.Document", that_doc: "caselawclient.models.documents.Document" 19 ): 20 # court, date, title 21 self["court"] = AttributeComparison( 22 label="court", 23 this_value=this_doc.court, 24 that_value=that_doc.court, 25 match=this_doc.court == that_doc.court, 26 ) 27 28 self["date"] = AttributeComparison( 29 label="date", 30 this_value=this_doc.body.document_date_as_string, 31 that_value=that_doc.body.document_date_as_string, 32 match=this_doc.body.document_date_as_string == that_doc.body.document_date_as_string, 33 ) 34 self["name"] = AttributeComparison( 35 label="name", 36 this_value=this_doc.name, 37 that_value=that_doc.name, 38 match=this_doc.name == that_doc.name, 39 ) 40 41 def match(self) -> bool: 42 """Is this comparison an exact match across all attributes?""" 43 return all(x["match"] for x in self.values())