ds-caselaw-marklogic-api-client 32.0.0__py3-none-any.whl → 34.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
caselawclient/Client.py CHANGED
@@ -572,6 +572,7 @@ class MarklogicApiClient:
572
572
  self,
573
573
  document_uri: DocumentURIString,
574
574
  document_xml: Element,
575
+ document_type: type[Document],
575
576
  annotation: VersionAnnotation,
576
577
  ) -> requests.Response:
577
578
  """
@@ -579,6 +580,7 @@ class MarklogicApiClient:
579
580
 
580
581
  :param document_uri: The URI to insert the document at
581
582
  :param document_xml: The XML of the document to insert
583
+ :param document_type: The type class of the document
582
584
  :param annotation: Annotations to record alongside this version
583
585
 
584
586
  :return: The response object from MarkLogic
@@ -592,6 +594,7 @@ class MarklogicApiClient:
592
594
 
593
595
  vars: query_dicts.InsertDocumentDict = {
594
596
  "uri": uri,
597
+ "type_collection": document_type.type_collection_name,
595
598
  "document": xml.decode("utf-8"),
596
599
  "annotation": annotation.as_json,
597
600
  }
@@ -1068,14 +1071,14 @@ class MarklogicApiClient:
1068
1071
  response = self._send_to_eval(vars, "get_properties_for_search_results.xqy")
1069
1072
  return get_single_string_from_marklogic_response(response)
1070
1073
 
1071
- def search_and_decode_response(self, search_parameters: SearchParameters) -> str:
1074
+ def search_and_decode_response(self, search_parameters: SearchParameters) -> bytes:
1072
1075
  response = self.advanced_search(search_parameters)
1073
- return get_single_string_from_marklogic_response(response)
1076
+ return get_single_bytestring_from_marklogic_response(response)
1074
1077
 
1075
1078
  def search_judgments_and_decode_response(
1076
1079
  self,
1077
1080
  search_parameters: SearchParameters,
1078
- ) -> str:
1081
+ ) -> bytes:
1079
1082
  search_parameters.collections = [DOCUMENT_COLLECTION_URI_JUDGMENT]
1080
1083
  return self.search_and_decode_response(search_parameters)
1081
1084
 
@@ -2,8 +2,17 @@ import json
2
2
  from enum import Enum
3
3
  from typing import Any, Optional, TypedDict
4
4
 
5
+ from lxml import etree
5
6
  from typing_extensions import NotRequired
6
7
 
8
+ from ..models.documents import Document
9
+ from ..models.judgments import Judgment
10
+ from ..models.press_summaries import PressSummary
11
+
12
+
13
+ class CannotDetermineDocumentType(Exception):
14
+ pass
15
+
7
16
 
8
17
  class AnnotationDataDict(TypedDict):
9
18
  type: str
@@ -112,3 +121,22 @@ class VersionAnnotation:
112
121
 
113
122
  def __str__(self) -> str:
114
123
  return self.as_json
124
+
125
+
126
+ def get_document_type_class(xml: bytes) -> type[Document]:
127
+ """Attempt to get the type of the document based on the XML root node."""
128
+
129
+ node = etree.fromstring(xml)
130
+
131
+ # If the document's root element is `judgment` it's a `Judgment`, regardless of the presence of a `name`.
132
+ if node.tag == "judgment":
133
+ return Judgment
134
+
135
+ # If the document's root element has a `name` attribute with a value of `pressSummary` we can assume it's a `PressSummary`
136
+ if node.tag == "doc" and node.attrib.get("name") == "pressSummary":
137
+ return PressSummary
138
+
139
+ # Otherwise, we don't know for sure. Fail out.
140
+ raise CannotDetermineDocumentType(
141
+ "Unable to accurately determine the type of document based on the root XML node.",
142
+ )
@@ -61,6 +61,8 @@ class Document:
61
61
  document_noun_plural = "documents"
62
62
  """ The noun for a plural of this document type. """
63
63
 
64
+ type_collection_name: str
65
+
64
66
  attributes_to_validate: list[tuple[str, bool, str]] = [
65
67
  (
66
68
  "is_failure",
@@ -23,6 +23,7 @@ class Judgment(NeutralCitationMixin, Document):
23
23
 
24
24
  document_noun = "judgment"
25
25
  document_noun_plural = "judgments"
26
+ type_collection_name = "judgment"
26
27
 
27
28
  def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
28
29
  super().__init__(self.document_noun, uri, *args, **kwargs)
@@ -24,6 +24,7 @@ class PressSummary(NeutralCitationMixin, Document):
24
24
 
25
25
  document_noun = "press summary"
26
26
  document_noun_plural = "press summaries"
27
+ type_collection_name = "press-summary"
27
28
 
28
29
  def __init__(self, uri: DocumentURIString, *args: Any, **kwargs: Any) -> None:
29
30
  super().__init__(self.document_noun, uri, *args, **kwargs)
@@ -3,7 +3,7 @@ import os
3
3
  from datetime import datetime
4
4
  from enum import Enum
5
5
  from functools import cached_property
6
- from typing import Dict, Optional
6
+ from typing import Any, Dict, Optional
7
7
 
8
8
  from dateutil import parser as dateparser
9
9
  from dateutil.parser import ParserError
@@ -12,6 +12,8 @@ from ds_caselaw_utils.types import CourtCode, JurisdictionCode
12
12
  from lxml import etree
13
13
 
14
14
  from caselawclient.Client import MarklogicApiClient
15
+ from caselawclient.models.identifiers import Identifiers
16
+ from caselawclient.models.identifiers.unpacker import unpack_all_identifiers_from_etree
15
17
  from caselawclient.types import DocumentURIString
16
18
  from caselawclient.xml_helpers import get_xpath_match_string
17
19
 
@@ -169,6 +171,21 @@ class SearchResult:
169
171
  self._get_xpath_match_string("@uri").lstrip("/").split(".xml")[0],
170
172
  )
171
173
 
174
+ @property
175
+ def identifiers(self) -> Identifiers:
176
+ identifiers_etrees = self._get_xpath("//identifiers")
177
+ if count := len(identifiers_etrees) != 1:
178
+ logging.warning(f"{count} //identifiers nodes found in search result, expected 1.")
179
+ identifiers_etree = None if not identifiers_etrees else identifiers_etrees[0]
180
+ return unpack_all_identifiers_from_etree(identifiers_etree)
181
+
182
+ @cached_property
183
+ def slug(self) -> str:
184
+ preferred = self.identifiers.preferred()
185
+ if not preferred:
186
+ raise RuntimeError("No preferred identifier for search result")
187
+ return str(preferred.url_slug)
188
+
172
189
  @property
173
190
  def neutral_citation(self) -> str:
174
191
  """
@@ -278,3 +295,6 @@ class SearchResult:
278
295
 
279
296
  def _get_xpath_match_string(self, path: str) -> str:
280
297
  return get_xpath_match_string(self.node, path, namespaces=self.NAMESPACES)
298
+
299
+ def _get_xpath(self, path: str) -> Any:
300
+ return self.node.xpath(path, namespaces=self.NAMESPACES)
@@ -4,20 +4,16 @@ import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls
4
4
 
5
5
  declare variable $uri as xs:string external;
6
6
  declare variable $document as xs:string external;
7
+ declare variable $type_collection as xs:string external;
7
8
  declare variable $annotation as xs:string external;
8
9
 
9
10
  let $document_xml := xdmp:unquote($document)
10
11
 
11
- let $collections :=
12
- if (fn:contains($uri, 'press-summary'))
13
- then ("press-summary")
14
- else ("judgment")
15
-
16
12
  return dls:document-insert-and-manage(
17
13
  $uri,
18
14
  fn:true(),
19
15
  $document_xml,
20
16
  $annotation,
21
17
  (),
22
- $collections
18
+ ($type_collection)
23
19
  )
@@ -8,8 +8,7 @@ declare variable $judgment as xs:string external;
8
8
  declare variable $annotation as xs:string external;
9
9
 
10
10
  let $judgment_xml := xdmp:unquote($judgment)
11
- (: alternative: check output of let $output := xdmp:validate($judgment_xml) :)
12
- let $crash_if_invalid := validate strict {$judgment_xml}
11
+
13
12
  return dls:document-update(
14
13
  $uri,
15
14
  $judgment_xml,
@@ -133,6 +133,7 @@ class GetVersionCreatedDict(MarkLogicAPIDict):
133
133
  class InsertDocumentDict(MarkLogicAPIDict):
134
134
  annotation: str
135
135
  document: str
136
+ type_collection: str
136
137
  uri: MarkLogicDocumentURIString
137
138
 
138
139
 
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ds-caselaw-marklogic-api-client
3
- Version: 32.0.0
3
+ Version: 34.0.0
4
4
  Summary: An API client for interacting with the underlying data in Find Caselaw.
5
5
  Home-page: https://github.com/nationalarchives/ds-caselaw-custom-api-client
6
6
  Keywords: national archives,caselaw
7
7
  Author: The National Archives
8
- Requires-Python: >=3.9,<4.0
8
+ Requires-Python: >=3.10.0,<4.0.0
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: Programming Language :: Python :: 3.9
11
10
  Classifier: Programming Language :: Python :: 3.10
12
11
  Classifier: Programming Language :: Python :: 3.11
13
12
  Requires-Dist: boto3 (>=1.26.112,<2.0.0)
@@ -1,13 +1,13 @@
1
- caselawclient/Client.py,sha256=Vy8DRniIxWQxc0hMlnhD-e6_O3WM9eVLX7PBaP1fPLg,44756
1
+ caselawclient/Client.py,sha256=v8Zb7vZmoF3COJWtIzoJxTy8d3DLo-mlNH3MhfDL4hs,44931
2
2
  caselawclient/__init__.py,sha256=DY-caubLDQWWingSdsBWgovDNXh8KcnkI6kwz08eIFk,612
3
- caselawclient/client_helpers/__init__.py,sha256=fyDNKCdrTb2N0Ks23YDhmvlXKfLTHnYQCXhnZb-QQbg,3832
3
+ caselawclient/client_helpers/__init__.py,sha256=mmPVwIxnR-KeelNIIMGjsTMzruK6j0X1YR_0H_RHnew,4798
4
4
  caselawclient/client_helpers/search_helpers.py,sha256=R99HyRLeYHgsw2L3DOidEqlKLLvs6Tga5rKTuWQViig,1525
5
5
  caselawclient/content_hash.py,sha256=0cPC4OoABq0SC2wYFX9-24DodNigeOqksDxgxQH_hUA,2221
6
6
  caselawclient/errors.py,sha256=JC16fEGq_MRJX-_KFzfINCV2Cqx8o6OWOt3C16rQd84,3142
7
7
  caselawclient/factories.py,sha256=BzxG7rBprmszxS1U1jsyBKaMSSm22RFmFK1nQSOZJlw,6812
8
8
  caselawclient/identifier_resolution.py,sha256=BKj7k8ca6b8ZpeoOk2uHYqprOOp9aN5qEB7PWvfJmSw,2439
9
9
  caselawclient/models/__init__.py,sha256=kd23EUpvaC7aLHdgk8farqKAQEx3lf7RvNT2jEatvlg,68
10
- caselawclient/models/documents/__init__.py,sha256=J5lUpL7XiBYA3mRiDsjc8McUzkhxcdSVS3nlrIUWpAI,19012
10
+ caselawclient/models/documents/__init__.py,sha256=7U5oN2b8JZV9sFSYglBg2K7fKKQgDjTVU5FT22URx7U,19043
11
11
  caselawclient/models/documents/body.py,sha256=mhPOV1cOF3RJr69UzNPlo1KrzePaj7KDPYi1exP06L0,5880
12
12
  caselawclient/models/documents/exceptions.py,sha256=Mz1P8uNqf5w6uLnRwJt6xK7efsVqtd5VA-WXUUH7QLk,285
13
13
  caselawclient/models/documents/statuses.py,sha256=Cp4dTQmJOtsU41EJcxy5dV1841pGD2PNWH0VrkDEv4Q,579
@@ -18,9 +18,9 @@ caselawclient/models/identifiers/fclid.py,sha256=FBqarEcnr-1AYmFvjTu1WoPNSBY785h
18
18
  caselawclient/models/identifiers/neutral_citation.py,sha256=O3zLw8lnhh5Mb0COjwhhDfTyvcSt48Td5pfT6yaCCJk,1947
19
19
  caselawclient/models/identifiers/press_summary_ncn.py,sha256=0SU6WQqj337VOio8pzSHn2AgFTF1_B3bKDnrpTMPTZY,751
20
20
  caselawclient/models/identifiers/unpacker.py,sha256=xvp480QESbN36NEc6qeo-orqOBq6WchnLI7thY7A1qs,2156
21
- caselawclient/models/judgments.py,sha256=H_-t4mCa3LdYu1cLOhQB5n045RdJghWpqS5hgPPDE4U,2170
21
+ caselawclient/models/judgments.py,sha256=r40irgdEID-NeSNLm3OUdUBznMpRSwjD2SJrGlBgP8o,2208
22
22
  caselawclient/models/neutral_citation_mixin.py,sha256=jAac3PPuWyPdj9N-n-U_JfwkbgbSIXaqFVQahfu95do,2086
23
- caselawclient/models/press_summaries.py,sha256=a50KdX_v41G_eI5h6_HuA2hvrhOA2EDvoTYBi5va1e8,2101
23
+ caselawclient/models/press_summaries.py,sha256=PIq9RceZ7n7Z079tESfxhQbfxCmtTc2V2OeFtcn594s,2144
24
24
  caselawclient/models/utilities/__init__.py,sha256=u3yIhbTjFQ1JJyAm5wsMEBswWl4t6Z7UMORF5FqC2xQ,1257
25
25
  caselawclient/models/utilities/aws.py,sha256=E4nFcNC2xxPUv0Xkfi2XTO3FyIH6jaAy9pgsvR48Eg8,8759
26
26
  caselawclient/models/utilities/dates.py,sha256=WwORxVjUHM1ZFcBF6Qtwo3Cj0sATsnSECkUZ6ls1N1Q,492
@@ -28,7 +28,7 @@ caselawclient/models/utilities/move.py,sha256=MXdUqkSiyqRb8YKs_66B6ICWn8EWM6DiJV
28
28
  caselawclient/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  caselawclient/responses/__init__.py,sha256=2-5NJn_PXPTje_W4dHeHYaNRN6vXK4UcB9eLLNUAKa4,67
30
30
  caselawclient/responses/search_response.py,sha256=Z76Zj4VvM-EV_vdiehv2-Jfkr9HZD3SvCTlRrUB_cyE,1951
31
- caselawclient/responses/search_result.py,sha256=hotJHJ9wQusjb4PjZm1DDZv2HEsXWTtZU5TOTj2T0rw,8205
31
+ caselawclient/responses/search_result.py,sha256=l6wSruVJDLCT1JquDrUVk9TZ0Ic6w4Wlayhu8vL_0sg,9123
32
32
  caselawclient/responses/xsl/search_match.xsl,sha256=4Sv--MrwBd7J48E9aI7jlFSXGlNi4dBqgzJ3bdMJ_ZU,1018
33
33
  caselawclient/search_parameters.py,sha256=nR-UC1aWZbdXzXBrVDaHECU4Ro8Zi4JZATtgrpAVsKY,3342
34
34
  caselawclient/types.py,sha256=0PsEsQzJOInpuwZ-Ydw0UpGns6jbHzlJhc-Ms28sqCU,2064
@@ -58,7 +58,7 @@ caselawclient/xquery/get_recently_enriched.xqy,sha256=qSA9EYlKaAyYwewBRj494aC_Jn
58
58
  caselawclient/xquery/get_recently_parsed.xqy,sha256=k8NP72O11FyDZ3MeKAJWlcrzPsynhPTddYIeS0pRaII,594
59
59
  caselawclient/xquery/get_version_annotation.xqy,sha256=pFDMGA9SxI59iUPaoAeUsq23kUp4Op7cUg-PFNFqxcI,262
60
60
  caselawclient/xquery/get_version_created.xqy,sha256=bRweaXFtwMBNzL16SlOdiOxHkbqNUwpwDHLxpZYVCh0,250
61
- caselawclient/xquery/insert_document.xqy,sha256=iP2xTaLGa-u6X9KfS1yJ6yPCKQUWQFYdEW1S4YcMY7w,531
61
+ caselawclient/xquery/insert_document.xqy,sha256=aRauDny7OwqWr19L4BGLky48OBqiHtsV4Qf6xd2zBUc,486
62
62
  caselawclient/xquery/list_judgment_versions.xqy,sha256=WShga8igeD21hSLfVSvCOiDMPDhNH6KGf1OW6G0SAkY,190
63
63
  caselawclient/xquery/resolve_from_identifier_slug.xqy,sha256=jMaOugdG1XVQIk9AR5NOth8D2RS8VEUJuBwjO9j4MFM,485
64
64
  caselawclient/xquery/resolve_from_identifier_value.xqy,sha256=7uP3DnRi67qSp0aUhW6Cv_GA8BQGw6GuvtAghjrT7Z4,493
@@ -72,15 +72,15 @@ caselawclient/xquery/set_metadata_work_expression_date.xqy,sha256=eN4VvRA5FqP3aK
72
72
  caselawclient/xquery/set_property.xqy,sha256=wUDCMLrUUgTMqn_-_T48DXsdDLtFncrVjidVuCwtpS4,343
73
73
  caselawclient/xquery/set_property_as_node.xqy,sha256=85ywMo5VPGXBnHepIajDOPYEy_ZmeU_9glgDcJ_CwEI,362
74
74
  caselawclient/xquery/update_document.xqy,sha256=-kbv3Ig2nuBviCyn0R_H6GPE1kpDP4UOhWsYk5oBgtU,420
75
- caselawclient/xquery/update_locked_judgment.xqy,sha256=wFDEtKh7MxvPmEHrzOHTJIRlY01ATneESl-n_lIQ7cU,556
75
+ caselawclient/xquery/update_locked_judgment.xqy,sha256=1njfQ4dPLhnIM_j4VupXBEHJ47ZBX85VS8Py46rYh8E,421
76
76
  caselawclient/xquery/user_has_privilege.xqy,sha256=TfqPjhdpXt-4Fo7E2kEYRhfqQm6uES-IuLbAlCxylbg,371
77
77
  caselawclient/xquery/user_has_role.xqy,sha256=52YuFZnXqaDDJs-j_UanpqcLNEiw_m9xb07HvZVUoXY,246
78
78
  caselawclient/xquery/validate_all_documents.xqy,sha256=z_0YEXmRcZ-FaJM0ouKiTjdI4tLKQ4FTssRihR07qFk,156
79
79
  caselawclient/xquery/validate_document.xqy,sha256=PgaDcnqCRJPIVqfmWsNlXmCLNKd21qkJrvY1RtNP7eA,140
80
80
  caselawclient/xquery/xslt.xqy,sha256=w57wNijH3dkwHkpKeAxqjlghVflQwo8cq6jS_sm-erM,199
81
81
  caselawclient/xquery/xslt_transform.xqy,sha256=cccaFiGkCcvSfDv007UriZ3I4ak2nTLP1trRZdbOoS8,2462
82
- caselawclient/xquery_type_dicts.py,sha256=mkpvJcqgKhDi7xkW9RLGIoXIzrpcmLSkg_B1zP8CWWk,6358
83
- ds_caselaw_marklogic_api_client-32.0.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
84
- ds_caselaw_marklogic_api_client-32.0.0.dist-info/METADATA,sha256=HeIQpEv7f-NciSntkOJER1_Br9gpaaevWbHDnr9fG7k,4251
85
- ds_caselaw_marklogic_api_client-32.0.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
86
- ds_caselaw_marklogic_api_client-32.0.0.dist-info/RECORD,,
82
+ caselawclient/xquery_type_dicts.py,sha256=21V6PJ0a8lPZuwzQCWeHNo914hdCbCJtOvnqdHcTpKk,6383
83
+ ds_caselaw_marklogic_api_client-34.0.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
84
+ ds_caselaw_marklogic_api_client-34.0.0.dist-info/METADATA,sha256=1Y9daSrmdkheziHwxatUrnUuGlx4whYIcdURLgxibKU,4206
85
+ ds_caselaw_marklogic_api_client-34.0.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
86
+ ds_caselaw_marklogic_api_client-34.0.0.dist-info/RECORD,,