ds-caselaw-marklogic-api-client 27.1.0__py3-none-any.whl → 27.3.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
@@ -217,10 +217,10 @@ class MarklogicApiClient:
217
217
  def get_document_by_uri(
218
218
  self,
219
219
  uri: DocumentURIString,
220
- query: Optional[str] = None,
220
+ search_query: Optional[str] = None,
221
221
  ) -> Document:
222
222
  document_type_class = self.get_document_type_from_uri(uri)
223
- return document_type_class(uri, self)
223
+ return document_type_class(uri, self, search_query=search_query)
224
224
 
225
225
  def get_document_type_from_uri(self, uri: DocumentURIString) -> Type[Document]:
226
226
  vars: query_dicts.DocumentCollectionsDict = {
@@ -403,6 +403,7 @@ class MarklogicApiClient:
403
403
  judgment_uri: DocumentURIString,
404
404
  version_uri: Optional[DocumentURIString] = None,
405
405
  show_unpublished: bool = False,
406
+ search_query: Optional[str] = None,
406
407
  ) -> bytes:
407
408
  marklogic_document_uri = self._format_uri_for_marklogic(judgment_uri)
408
409
  marklogic_document_version_uri = (
@@ -418,6 +419,7 @@ class MarklogicApiClient:
418
419
  "uri": marklogic_document_uri,
419
420
  "version_uri": marklogic_document_version_uri,
420
421
  "show_unpublished": show_unpublished,
422
+ "search_query": search_query,
421
423
  }
422
424
 
423
425
  response = self._eval_as_bytes(vars, "get_judgment.xqy")
@@ -433,11 +435,13 @@ class MarklogicApiClient:
433
435
  judgment_uri: DocumentURIString,
434
436
  version_uri: Optional[DocumentURIString] = None,
435
437
  show_unpublished: bool = False,
438
+ search_query: Optional[str] = None,
436
439
  ) -> str:
437
440
  return self.get_judgment_xml_bytestring(
438
441
  judgment_uri,
439
442
  version_uri,
440
443
  show_unpublished,
444
+ search_query=search_query,
441
445
  ).decode(encoding="utf-8")
442
446
 
443
447
  def set_document_name(
@@ -1076,6 +1080,7 @@ class MarklogicApiClient:
1076
1080
  self,
1077
1081
  target_enrichment_version: tuple[int, int],
1078
1082
  target_parser_version: tuple[int, int],
1083
+ maximum_records: int = 1000,
1079
1084
  ) -> list[list[Any]]:
1080
1085
  """Retrieve documents which are not yet enriched with a given version."""
1081
1086
  vars: query_dicts.GetPendingEnrichmentForVersionDict = {
@@ -1083,6 +1088,7 @@ class MarklogicApiClient:
1083
1088
  "target_enrichment_minor_version": target_enrichment_version[1],
1084
1089
  "target_parser_major_version": target_parser_version[0],
1085
1090
  "target_parser_minor_version": target_parser_version[1],
1091
+ "maximum_records": maximum_records,
1086
1092
  }
1087
1093
  results: list[list[Any]] = json.loads(
1088
1094
  get_single_string_from_marklogic_response(
@@ -1111,11 +1117,13 @@ class MarklogicApiClient:
1111
1117
  def get_pending_parse_for_version(
1112
1118
  self,
1113
1119
  target_version: tuple[int, int],
1120
+ maximum_records: int = 1000,
1114
1121
  ) -> list[list[Any]]:
1115
1122
  """Retrieve documents which are not yet parsed with a given version."""
1116
1123
  vars: query_dicts.GetPendingParseForVersionDict = {
1117
1124
  "target_major_version": target_version[0],
1118
1125
  "target_minor_version": target_version[1],
1126
+ "maximum_records": maximum_records,
1119
1127
  }
1120
1128
  results: list[list[Any]] = json.loads(
1121
1129
  get_single_string_from_marklogic_response(
@@ -105,7 +105,7 @@ class Document:
105
105
  Individual document classes should extend this list where necessary to validate document type-specific attributes.
106
106
  """
107
107
 
108
- def __init__(self, uri: str, api_client: "MarklogicApiClient"):
108
+ def __init__(self, uri: str, api_client: "MarklogicApiClient", search_query: Optional[str] = None):
109
109
  """
110
110
  :param uri: For historical reasons this accepts a pseudo-URI which may include leading or trailing slashes.
111
111
 
@@ -117,7 +117,11 @@ class Document:
117
117
  raise DocumentNotFoundError(f"Document {self.uri} does not exist")
118
118
 
119
119
  self.body: DocumentBody = DocumentBody(
120
- xml_bytestring=self.api_client.get_judgment_xml_bytestring(self.uri, show_unpublished=True),
120
+ xml_bytestring=self.api_client.get_judgment_xml_bytestring(
121
+ self.uri,
122
+ show_unpublished=True,
123
+ search_query=search_query,
124
+ ),
121
125
  )
122
126
  """ `Document.body` represents the XML of the document itself, without any information such as version tracking or properties. """
123
127
 
@@ -973,6 +973,14 @@
973
973
  </xsl:element>
974
974
  </xsl:template>
975
975
 
976
+ <!-- search query numbering -->
977
+
978
+ <xsl:template match="uk:mark">
979
+ <xsl:element name="{ local-name(.) }">
980
+ <xsl:copy-of select="@*"/>
981
+ <xsl:apply-templates />
982
+ </xsl:element>
983
+ </xsl:template>
976
984
 
977
985
  <!-- text -->
978
986
 
@@ -1,8 +1,38 @@
1
1
  xquery version "1.0-ml";
2
2
 
3
+ declare namespace xdmp = "http://marklogic.com/xdmp";
4
+ declare namespace cts = "http://marklogic.com/cts";
5
+ declare namespace uk = "https://caselaw.nationalarchives.gov.uk/akn";
6
+ import module namespace helper = "https://caselaw.nationalarchives.gov.uk/helper" at "/judgments/search/helper.xqy";
7
+
3
8
  declare variable $show_unpublished as xs:boolean? external;
4
9
  declare variable $uri as xs:string external;
5
10
  declare variable $version_uri as xs:string? external;
11
+ declare variable $search_query as xs:string? external;
12
+
13
+ (: Note that `xsl:output method` is changed from `html` to `xml` and we've namespaced the tag :)
14
+ let $number_marks_xslt := (
15
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16
+ xmlns:uk="https://caselaw.nationalarchives.gov.uk/akn"
17
+ version="2.0">
18
+ <xsl:output method="xml" />
19
+ <xsl:template match="@*|node()">
20
+ <xsl:copy>
21
+ <xsl:apply-templates select="@*|node()"/>
22
+ </xsl:copy>
23
+ </xsl:template>
24
+ <xsl:template match="uk:mark">
25
+ <xsl:copy>
26
+ <xsl:copy-of select="@*" />
27
+ <xsl:attribute name="id">
28
+ <xsl:text>mark_</xsl:text>
29
+ <xsl:value-of select="count(preceding::uk:mark)"/>
30
+ </xsl:attribute>
31
+ <xsl:apply-templates />
32
+ </xsl:copy>
33
+ </xsl:template>
34
+ </xsl:stylesheet>
35
+ )
6
36
 
7
37
  let $judgment := fn:document($uri)
8
38
  let $version := if ($version_uri) then fn:document($version_uri) else ()
@@ -11,11 +41,26 @@ let $is_published := $judgment_published_property/text()
11
41
 
12
42
  let $document_to_return := if ($version_uri) then $version else $judgment
13
43
 
14
- let $return_value := if ($show_unpublished) then
44
+
45
+ let $raw_xml := if ($show_unpublished) then
15
46
  $document_to_return
16
47
  else if (xs:boolean($is_published)) then
17
48
  $document_to_return
18
49
  else
19
50
  ()
20
51
 
21
- return $return_value
52
+ (: If a search query string is present, highlight instances :)
53
+ let $transformed := if($search_query) then
54
+ xdmp:xslt-eval(
55
+ $number_marks_xslt,
56
+ cts:highlight(
57
+ $raw_xml,
58
+ helper:make-q-query($search_query),
59
+ <uk:mark>{$cts:text}</uk:mark>
60
+ )
61
+ )
62
+ else
63
+ $raw_xml
64
+
65
+
66
+ return $transformed
@@ -1,9 +1,11 @@
1
1
  xquery version "1.0-ml";
2
2
 
3
+ declare namespace xdmp="http://marklogic.com/xdmp";
3
4
  declare variable $target_enrichment_major_version as xs:int external;
4
5
  declare variable $target_enrichment_minor_version as xs:int external;
5
6
  declare variable $target_parser_major_version as xs:int external;
6
7
  declare variable $target_parser_minor_version as xs:int external;
8
+ declare variable $maximum_records as xs:int? external := 1000;
7
9
 
8
10
  xdmp:to-json(xdmp:sql(
9
11
  "SELECT process_data.uri, enrich_version_string, minutes_since_enrichment_request
@@ -23,13 +25,16 @@ xdmp:to-json(xdmp:sql(
23
25
  (parser_major_version = @target_parser_major_version AND parser_minor_version = @target_parser_minor_version)
24
26
  )
25
27
  AND (minutes_since_enrichment_request > 43200 OR minutes_since_enrichment_request IS NULL)
26
- ORDER BY enrich_major_version ASC NULLS FIRST, enrich_minor_version ASC",
28
+ ORDER BY enrich_major_version ASC NULLS FIRST, enrich_minor_version ASC
29
+ LIMIT @maximum_records",
27
30
  "array",
28
31
  map:new((
29
32
  map:entry("target_enrichment_major_version", $target_enrichment_major_version),
30
33
  map:entry("target_enrichment_minor_version", $target_enrichment_minor_version),
31
34
  map:entry("target_parser_major_version", $target_parser_major_version),
32
- map:entry("target_parser_minor_version", $target_parser_minor_version)
35
+ map:entry("target_parser_minor_version", $target_parser_minor_version),
36
+ map:entry("maximum_records", $maximum_records)
37
+
33
38
  ))
34
39
  ))
35
40
 
@@ -2,6 +2,7 @@ xquery version "1.0-ml";
2
2
 
3
3
  declare variable $target_major_version as xs:int external;
4
4
  declare variable $target_minor_version as xs:int external;
5
+ declare variable $maximum_records as xs:int? external := 1000;
5
6
 
6
7
  xdmp:to-json(xdmp:sql(
7
8
  "SELECT process_data.uri, parser_version_string, minutes_since_parse_request
@@ -18,11 +19,13 @@ xdmp:to-json(xdmp:sql(
18
19
  (parser_major_version <= @target_major_version AND parser_minor_version < @target_minor_version)
19
20
  )
20
21
  AND (minutes_since_parse_request > 43200 OR minutes_since_parse_request IS NULL)
21
- ORDER BY parser_major_version ASC NULLS FIRST, parser_minor_version ASC",
22
+ ORDER BY parser_major_version ASC NULLS FIRST, parser_minor_version ASC
23
+ LIMIT @maximum_records",
22
24
  "array",
23
25
  map:new((
24
26
  map:entry("target_major_version", $target_major_version),
25
- map:entry("target_minor_version", $target_minor_version)
27
+ map:entry("target_minor_version", $target_minor_version),
28
+ map:entry("maximum_records", $maximum_records)
29
+
26
30
  ))
27
- ))
28
-
31
+ ))
@@ -64,6 +64,7 @@ class GetComponentsForDocumentDict(MarkLogicAPIDict):
64
64
 
65
65
  # get_judgment.xqy
66
66
  class GetJudgmentDict(MarkLogicAPIDict):
67
+ search_query: Optional[str]
67
68
  show_unpublished: Optional[bool]
68
69
  uri: MarkLogicDocumentURIString
69
70
  version_uri: Optional[MarkLogicDocumentVersionURIString]
@@ -87,6 +88,7 @@ class GetLastModifiedDict(MarkLogicAPIDict):
87
88
 
88
89
  # get_pending_enrichment_for_version.xqy
89
90
  class GetPendingEnrichmentForVersionDict(MarkLogicAPIDict):
91
+ maximum_records: Optional[int]
90
92
  target_enrichment_major_version: int
91
93
  target_enrichment_minor_version: int
92
94
  target_parser_major_version: int
@@ -95,6 +97,7 @@ class GetPendingEnrichmentForVersionDict(MarkLogicAPIDict):
95
97
 
96
98
  # get_pending_parse_for_version.xqy
97
99
  class GetPendingParseForVersionDict(MarkLogicAPIDict):
100
+ maximum_records: Optional[int]
98
101
  target_major_version: int
99
102
  target_minor_version: int
100
103
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ds-caselaw-marklogic-api-client
3
- Version: 27.1.0
3
+ Version: 27.3.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
@@ -1,4 +1,4 @@
1
- caselawclient/Client.py,sha256=CP7wx_Z_RKK6Wg4Ib3JypEXbncL1jNsLmo66MyXxcF0,40295
1
+ caselawclient/Client.py,sha256=oMWfL0FwKdWyMtk_0qf6uxWJvsHLSps8vxDsAC9GxeI,40668
2
2
  caselawclient/__init__.py,sha256=DY-caubLDQWWingSdsBWgovDNXh8KcnkI6kwz08eIFk,612
3
3
  caselawclient/client_helpers/__init__.py,sha256=fyDNKCdrTb2N0Ks23YDhmvlXKfLTHnYQCXhnZb-QQbg,3832
4
4
  caselawclient/client_helpers/search_helpers.py,sha256=R99HyRLeYHgsw2L3DOidEqlKLLvs6Tga5rKTuWQViig,1525
@@ -6,11 +6,11 @@ caselawclient/content_hash.py,sha256=0cPC4OoABq0SC2wYFX9-24DodNigeOqksDxgxQH_hUA
6
6
  caselawclient/errors.py,sha256=tV0vs3wYSd331BzmfuRiZV6GAdsd91rtN65ymRaSx3s,3164
7
7
  caselawclient/factories.py,sha256=wTGGP8VyUME2gwbnuYE2uC5PdCdJ2PXF9gEET3U9CZg,4356
8
8
  caselawclient/models/__init__.py,sha256=kd23EUpvaC7aLHdgk8farqKAQEx3lf7RvNT2jEatvlg,68
9
- caselawclient/models/documents/__init__.py,sha256=LnAURUtxoY4UdDUk-dFgnyJ-Gn9eB0VfdC4gjNoYacM,16974
9
+ caselawclient/models/documents/__init__.py,sha256=uNjmmNKAthBmB6RSNlmJPir3E2MGrYkcP17iEY-xtkk,17100
10
10
  caselawclient/models/documents/body.py,sha256=mtdjmG1WU2qSpyRLS8-PWcSoXpDa2Qz6xlcTbxZgxvA,5603
11
11
  caselawclient/models/documents/exceptions.py,sha256=Mz1P8uNqf5w6uLnRwJt6xK7efsVqtd5VA-WXUUH7QLk,285
12
12
  caselawclient/models/documents/statuses.py,sha256=Cp4dTQmJOtsU41EJcxy5dV1841pGD2PNWH0VrkDEv4Q,579
13
- caselawclient/models/documents/transforms/html.xsl,sha256=BTo3dsjJywmw28rnPB-AwRXZk8hY8Bi7KqEkg8tsOuQ,38131
13
+ caselawclient/models/documents/transforms/html.xsl,sha256=oSSO-IBX4qLiSWexQYmWJfGNevF09aCBx4D1NYqXxpo,38322
14
14
  caselawclient/models/documents/xml.py,sha256=afEsgcnTThqW_gKYq-VGtFr4ovOoT2J7h2gXX7F8BbE,1267
15
15
  caselawclient/models/judgments.py,sha256=SuCNtOD4LElp37df4dvhaD0umTowioWH0sZNmBgFsoE,1739
16
16
  caselawclient/models/neutral_citation_mixin.py,sha256=5ktKCPIDidVRwxVTzx5e242O1BxOdP--1dnatZyTbYI,1773
@@ -37,12 +37,12 @@ caselawclient/xquery/get_combined_stats_table.xqy,sha256=cclNqSzIB6sX6A_hgVOFZon
37
37
  caselawclient/xquery/get_components_for_document.xqy,sha256=qh_F56XEDyVKMIaN4J1fskcjYK3Mc6JR8ARGwS2b0lw,768
38
38
  caselawclient/xquery/get_highest_enrichment_version.xqy,sha256=a0dwVmEZuIMyRjIlvenSmbOaaN0WvgaCZvMtVWoLulQ,247
39
39
  caselawclient/xquery/get_highest_parser_version.xqy,sha256=LW3iSg4eWArbfBaCVWWOpr4MoUcDBz514nV48ElOsAM,247
40
- caselawclient/xquery/get_judgment.xqy,sha256=xg66A1xslgwds670gu_9DFcOmxYGoo8sA2EDoKbz0Co,715
40
+ caselawclient/xquery/get_judgment.xqy,sha256=8V-sEFKmtpf2LIZD9QKVRfpblEsmDpP4BA6QztSCyHA,2216
41
41
  caselawclient/xquery/get_judgment_checkout_status.xqy,sha256=mdY9UXLyzQdB7byEERPqentlr0YDLbXRVqH0h4UuZTQ,193
42
42
  caselawclient/xquery/get_judgment_version.xqy,sha256=wF9k9-CBrqo8VbxxyTrD-AGzR3-3jMm25tRVCjxPLrU,292
43
43
  caselawclient/xquery/get_last_modified.xqy,sha256=8fCm_7o_kkytCEmEeSTLWzLP7iOjuPV01IfHDgf6HaQ,172
44
- caselawclient/xquery/get_pending_enrichment_for_version.xqy,sha256=jYc2OPnAIU4kfRsyhCam9RtrxOB2KhKX40CALFc2Rwo,1623
45
- caselawclient/xquery/get_pending_parse_for_version.xqy,sha256=1HRQ3Mwljgp1QbVTiesJrV5HuuMCyKPDMzBOzrT_oQM,1054
44
+ caselawclient/xquery/get_pending_enrichment_for_version.xqy,sha256=S5r5h1iyn_wDQXLEh2MzK8qQ1Jiq-1lRsKgDa8L16yY,1821
45
+ caselawclient/xquery/get_pending_parse_for_version.xqy,sha256=9cjVZtHeBBjm-a7RMsn1PVJt_Ug78YFlmp5CN8VJ1jQ,1197
46
46
  caselawclient/xquery/get_properties_for_search_results.xqy,sha256=Tlv3EKwVV_q-JyQyhjWVHIleicPDpucxP4ScuQjpgSw,625
47
47
  caselawclient/xquery/get_property.xqy,sha256=RHlOTrK0aH-S7s_ykYzGmUeKOJxXlI4vE5sKRt556NY,209
48
48
  caselawclient/xquery/get_version_annotation.xqy,sha256=pFDMGA9SxI59iUPaoAeUsq23kUp4Op7cUg-PFNFqxcI,262
@@ -65,8 +65,8 @@ caselawclient/xquery/validate_all_documents.xqy,sha256=z_0YEXmRcZ-FaJM0ouKiTjdI4
65
65
  caselawclient/xquery/validate_document.xqy,sha256=PgaDcnqCRJPIVqfmWsNlXmCLNKd21qkJrvY1RtNP7eA,140
66
66
  caselawclient/xquery/xslt.xqy,sha256=w57wNijH3dkwHkpKeAxqjlghVflQwo8cq6jS_sm-erM,199
67
67
  caselawclient/xquery/xslt_transform.xqy,sha256=smyFFxqmtkuOzBd2l7uw6K2oAsYctudrP8omdv_XNAM,2463
68
- caselawclient/xquery_type_dicts.py,sha256=YOrXbEYJU84S-YwergCI12OL5Wrn_wpqMcqWpsQrKek,5590
69
- ds_caselaw_marklogic_api_client-27.1.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
70
- ds_caselaw_marklogic_api_client-27.1.0.dist-info/METADATA,sha256=gYAgOwD-FrETnEArRn9NSyZ2Yl2EvBOFPse-fWZNI7w,4232
71
- ds_caselaw_marklogic_api_client-27.1.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
72
- ds_caselaw_marklogic_api_client-27.1.0.dist-info/RECORD,,
68
+ caselawclient/xquery_type_dicts.py,sha256=AUEmycChASKl8sbqVQWe6WA0s-lIfEqh9mA-GdnUCQ8,5692
69
+ ds_caselaw_marklogic_api_client-27.3.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
70
+ ds_caselaw_marklogic_api_client-27.3.0.dist-info/METADATA,sha256=GltSiGOxA1e5fTsNbAdFhCjVwxQe7XAWS__-eZ165AM,4232
71
+ ds_caselaw_marklogic_api_client-27.3.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
72
+ ds_caselaw_marklogic_api_client-27.3.0.dist-info/RECORD,,