caselawclient.models.judgments

 1import importlib
 2from functools import cached_property
 3from typing import TYPE_CHECKING, Any, Optional
 4
 5from ds_caselaw_utils.types import NeutralCitationString
 6
 7from caselawclient.errors import DocumentNotFoundError
 8from caselawclient.identifier_resolution import IdentifierResolutions
 9from caselawclient.models.neutral_citation_mixin import NeutralCitationMixin
10
11if TYPE_CHECKING:
12    from caselawclient.models.press_summaries import PressSummary
13
14from caselawclient.types import DocumentURIString
15
16from .documents import Document
17
18
19class Judgment(NeutralCitationMixin, Document):
20    """
21    Represents a judgment document.
22    """
23
24    document_noun = "judgment"
25    document_noun_plural = "judgments"
26    type_collection_name = "judgment"
27    _default_reparse_document_type = "judgment"
28
29    def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
30        super().__init__(self.document_noun, uri, *args, **kwargs)
31
32    @cached_property
33    def neutral_citation(self) -> Optional[NeutralCitationString]:
34        value_in_xml = self.body.get_xpath_match_string(
35            "/akn:akomaNtoso/akn:*/akn:meta/akn:proprietary/uk:cite/text()",
36            {
37                "uk": "https://caselaw.nationalarchives.gov.uk/akn",
38                "akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",
39            },
40        )
41        if value_in_xml:
42            return NeutralCitationString(value_in_xml)
43        return None
44
45    @cached_property
46    def linked_document(self) -> Optional["PressSummary"]:
47        """
48        Attempt to fetch a linked press summary, and return it, if it exists
49        """
50        try:
51            uri = DocumentURIString(self.uri + "/press-summary/1")
52            if not TYPE_CHECKING:  # This isn't nice, but will be cleaned up when we refactor how related documents work
53                PressSummary = importlib.import_module("caselawclient.models.press_summaries").PressSummary
54            return PressSummary(uri, self.api_client)
55        except DocumentNotFoundError:
56            return None
57
58    @cached_property
59    def linked_press_summaries(self, only_published: bool = True) -> "IdentifierResolutions":
60        return self.linked_document_resolutions(["uksummaryofncn"], only_published)
20class Judgment(NeutralCitationMixin, Document):
21    """
22    Represents a judgment document.
23    """
24
25    document_noun = "judgment"
26    document_noun_plural = "judgments"
27    type_collection_name = "judgment"
28    _default_reparse_document_type = "judgment"
29
30    def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
31        super().__init__(self.document_noun, uri, *args, **kwargs)
32
33    @cached_property
34    def neutral_citation(self) -> Optional[NeutralCitationString]:
35        value_in_xml = self.body.get_xpath_match_string(
36            "/akn:akomaNtoso/akn:*/akn:meta/akn:proprietary/uk:cite/text()",
37            {
38                "uk": "https://caselaw.nationalarchives.gov.uk/akn",
39                "akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",
40            },
41        )
42        if value_in_xml:
43            return NeutralCitationString(value_in_xml)
44        return None
45
46    @cached_property
47    def linked_document(self) -> Optional["PressSummary"]:
48        """
49        Attempt to fetch a linked press summary, and return it, if it exists
50        """
51        try:
52            uri = DocumentURIString(self.uri + "/press-summary/1")
53            if not TYPE_CHECKING:  # This isn't nice, but will be cleaned up when we refactor how related documents work
54                PressSummary = importlib.import_module("caselawclient.models.press_summaries").PressSummary
55            return PressSummary(uri, self.api_client)
56        except DocumentNotFoundError:
57            return None
58
59    @cached_property
60    def linked_press_summaries(self, only_published: bool = True) -> "IdentifierResolutions":
61        return self.linked_document_resolutions(["uksummaryofncn"], only_published)

Represents a judgment document.

Judgment( uri: caselawclient.types.DocumentURIString, *args: Any, **kwargs: Any)
30    def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
31        super().__init__(self.document_noun, uri, *args, **kwargs)
Parameters
  • uri: The URI of the document to retrieve from MarkLogic.
  • api_client: An instance of the API client object to handle communication with the MarkLogic server.
  • search_query: Optionally, a search string which should be highlighted if it appears in the document body.
Raises
  • DocumentNotFoundError: The document does not exist within MarkLogic
document_noun = 'judgment'

The noun for a single instance of this document type.

document_noun_plural = 'judgments'

The noun for a plural of this document type.

type_collection_name = 'judgment'
neutral_citation: Optional[ds_caselaw_utils.types.NeutralCitationString]
33    @cached_property
34    def neutral_citation(self) -> Optional[NeutralCitationString]:
35        value_in_xml = self.body.get_xpath_match_string(
36            "/akn:akomaNtoso/akn:*/akn:meta/akn:proprietary/uk:cite/text()",
37            {
38                "uk": "https://caselaw.nationalarchives.gov.uk/akn",
39                "akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",
40            },
41        )
42        if value_in_xml:
43            return NeutralCitationString(value_in_xml)
44        return None
linked_document: Optional[caselawclient.models.press_summaries.PressSummary]
46    @cached_property
47    def linked_document(self) -> Optional["PressSummary"]:
48        """
49        Attempt to fetch a linked press summary, and return it, if it exists
50        """
51        try:
52            uri = DocumentURIString(self.uri + "/press-summary/1")
53            if not TYPE_CHECKING:  # This isn't nice, but will be cleaned up when we refactor how related documents work
54                PressSummary = importlib.import_module("caselawclient.models.press_summaries").PressSummary
55            return PressSummary(uri, self.api_client)
56        except DocumentNotFoundError:
57            return None

Attempt to fetch a linked press summary, and return it, if it exists

linked_press_summaries: caselawclient.identifier_resolution.IdentifierResolutions
59    @cached_property
60    def linked_press_summaries(self, only_published: bool = True) -> "IdentifierResolutions":
61        return self.linked_document_resolutions(["uksummaryofncn"], only_published)