caselawclient.models.press_summaries

 1from __future__ import annotations
 2
 3import importlib
 4from functools import cached_property
 5from typing import TYPE_CHECKING, Any, Optional
 6
 7from ds_caselaw_utils.types import NeutralCitationString
 8
 9from caselawclient.errors import DocumentNotFoundError
10from caselawclient.identifier_resolution import IdentifierResolutions
11from caselawclient.models.neutral_citation_mixin import NeutralCitationMixin
12from caselawclient.types import DocumentURIString
13
14from .documents import Document
15
16if TYPE_CHECKING:
17    from caselawclient.models.judgments import Judgment
18
19
20class PressSummary(NeutralCitationMixin, Document):
21    """
22    Represents a press summary document.
23    """
24
25    document_noun = "press summary"
26    document_noun_plural = "press summaries"
27    type_collection_name = "press-summary"
28    _default_reparse_document_type = "pressSummary"
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:doc/akn:preface/akn:p/akn:neutralCitation/text()",
37            {
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[Judgment]:
47        """
48        Attempt to fetch a linked judgement, and return it, if it exists
49        """
50        try:
51            uri = DocumentURIString(self.uri.removesuffix("/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                Judgment = importlib.import_module("caselawclient.models.judgments").Judgment
54            return Judgment(uri, self.api_client)
55        except DocumentNotFoundError:
56            return None
57
58    def linked_judgments(self, only_published: bool = True) -> "IdentifierResolutions":
59        return self.linked_document_resolutions(["ukncn"], only_published)
21class PressSummary(NeutralCitationMixin, Document):
22    """
23    Represents a press summary document.
24    """
25
26    document_noun = "press summary"
27    document_noun_plural = "press summaries"
28    type_collection_name = "press-summary"
29    _default_reparse_document_type = "pressSummary"
30
31    def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
32        super().__init__(self.document_noun, uri, *args, **kwargs)
33
34    @cached_property
35    def neutral_citation(self) -> Optional[NeutralCitationString]:
36        value_in_xml = self.body.get_xpath_match_string(
37            "/akn:akomaNtoso/akn:doc/akn:preface/akn:p/akn:neutralCitation/text()",
38            {
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[Judgment]:
48        """
49        Attempt to fetch a linked judgement, and return it, if it exists
50        """
51        try:
52            uri = DocumentURIString(self.uri.removesuffix("/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                Judgment = importlib.import_module("caselawclient.models.judgments").Judgment
55            return Judgment(uri, self.api_client)
56        except DocumentNotFoundError:
57            return None
58
59    def linked_judgments(self, only_published: bool = True) -> "IdentifierResolutions":
60        return self.linked_document_resolutions(["ukncn"], only_published)

Represents a press summary document.

PressSummary( uri: caselawclient.types.DocumentURIString, *args: Any, **kwargs: Any)
31    def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
32        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 = 'press summary'

The noun for a single instance of this document type.

document_noun_plural = 'press summaries'

The noun for a plural of this document type.

type_collection_name = 'press-summary'
neutral_citation: Optional[ds_caselaw_utils.types.NeutralCitationString]
34    @cached_property
35    def neutral_citation(self) -> Optional[NeutralCitationString]:
36        value_in_xml = self.body.get_xpath_match_string(
37            "/akn:akomaNtoso/akn:doc/akn:preface/akn:p/akn:neutralCitation/text()",
38            {
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.judgments.Judgment]
46    @cached_property
47    def linked_document(self) -> Optional[Judgment]:
48        """
49        Attempt to fetch a linked judgement, and return it, if it exists
50        """
51        try:
52            uri = DocumentURIString(self.uri.removesuffix("/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                Judgment = importlib.import_module("caselawclient.models.judgments").Judgment
55            return Judgment(uri, self.api_client)
56        except DocumentNotFoundError:
57            return None

Attempt to fetch a linked judgement, and return it, if it exists

def linked_judgments( self, only_published: bool = True) -> caselawclient.identifier_resolution.IdentifierResolutions:
59    def linked_judgments(self, only_published: bool = True) -> "IdentifierResolutions":
60        return self.linked_document_resolutions(["ukncn"], only_published)