ds-caselaw-marklogic-api-client 20.0.0__py3-none-any.whl → 21.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
@@ -446,6 +446,24 @@ class MarklogicApiClient:
446
446
 
447
447
  return self._send_to_eval(vars, "set_metadata_court.xqy")
448
448
 
449
+ def set_document_jurisdiction(
450
+ self, document_uri: DocumentURIString, content: str
451
+ ) -> requests.Response:
452
+ uri = self._format_uri_for_marklogic(document_uri)
453
+ vars: query_dicts.SetMetadataJurisdictionDict = {"uri": uri, "content": content}
454
+ return self._send_to_eval(vars, "set_metadata_jurisdiction.xqy")
455
+
456
+ def set_document_court_and_jurisdiction(
457
+ self, document_uri: DocumentURIString, content: str
458
+ ) -> requests.Response:
459
+ if "/" in content:
460
+ court, jurisdiction = re.split("\\s*/\\s*", content)
461
+ self.set_document_court(document_uri, court)
462
+ return self.set_document_jurisdiction(document_uri, jurisdiction)
463
+ else:
464
+ self.set_document_court(document_uri, content)
465
+ return self.set_document_jurisdiction(document_uri, "")
466
+
449
467
  def set_judgment_this_uri(
450
468
  self, judgment_uri: DocumentURIString
451
469
  ) -> requests.Response:
@@ -968,12 +986,16 @@ class MarklogicApiClient:
968
986
  return (int(table[1][1]), int(table[1][2]))
969
987
 
970
988
  def get_pending_enrichment_for_version(
971
- self, target_version: tuple[int, int]
989
+ self,
990
+ target_enrichment_version: tuple[int, int],
991
+ target_parser_version: tuple[int, int],
972
992
  ) -> list[list[Any]]:
973
993
  """Retrieve documents which are not yet enriched with a given version."""
974
994
  vars: query_dicts.GetPendingEnrichmentForVersionDict = {
975
- "target_major_version": target_version[0],
976
- "target_minor_version": target_version[1],
995
+ "target_enrichment_major_version": target_enrichment_version[0],
996
+ "target_enrichment_minor_version": target_enrichment_version[1],
997
+ "target_parser_major_version": target_parser_version[0],
998
+ "target_parser_minor_version": target_parser_version[1],
977
999
  }
978
1000
  results: list[list[Any]] = json.loads(
979
1001
  get_single_string_from_marklogic_response(
@@ -198,6 +198,20 @@ class Document:
198
198
  },
199
199
  )
200
200
 
201
+ @cached_property
202
+ def jurisdiction(self) -> str:
203
+ return self.xml.get_xpath_match_string(
204
+ "/akn:akomaNtoso/akn:*/akn:meta/akn:proprietary/uk:jurisdiction/text()",
205
+ {
206
+ "uk": "https://caselaw.nationalarchives.gov.uk/akn",
207
+ "akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",
208
+ },
209
+ )
210
+
211
+ @property
212
+ def court_and_jurisdiction(self) -> str:
213
+ return "/".join((self.court, self.jurisdiction))
214
+
201
215
  @cached_property
202
216
  def document_date_as_string(self) -> str:
203
217
  return self.xml.get_xpath_match_string(
@@ -464,9 +478,9 @@ class Document:
464
478
  """
465
479
  Request enrichment of the document
466
480
  """
467
-
481
+ now = datetime.datetime.now(datetime.timezone.utc)
468
482
  self.api_client.set_property(
469
- self.uri, "last_sent_to_enrichment", datetime.datetime.now().isoformat()
483
+ self.uri, "last_sent_to_enrichment", now.isoformat()
470
484
  )
471
485
 
472
486
  announce_document_event(
@@ -536,6 +550,9 @@ class Document:
536
550
  def reparse(self) -> None:
537
551
  "Send an SNS notification that triggers reparsing, also sending all editor-modifiable metadata and URI"
538
552
 
553
+ now = datetime.datetime.now(datetime.timezone.utc)
554
+ self.api_client.set_property(self.uri, "last_sent_to_parser", now.isoformat())
555
+
539
556
  parser_type_noun = {"judgment": "judgment", "press summary": "pressSummary"}[
540
557
  self.document_noun
541
558
  ]
@@ -550,13 +567,14 @@ class Document:
550
567
  # values are "" from the API, we should pass None instead in this case.
551
568
 
552
569
  parser_instructions: ParserInstructionsDict = {
553
- "name": self.name or None,
554
- "cite": self.best_human_identifier or None,
555
- "court": self.court or None,
556
- "date": checked_date,
557
- "uri": self.uri,
558
570
  "documentType": parser_type_noun,
559
- "published": self.is_published,
571
+ "metadata": {
572
+ "name": self.name or None,
573
+ "cite": self.best_human_identifier or None,
574
+ "court": self.court or None,
575
+ "date": checked_date,
576
+ "uri": self.uri,
577
+ },
560
578
  }
561
579
 
562
580
  request_parse(
@@ -19,20 +19,21 @@ class NeutralCitationMixin:
19
19
  """
20
20
 
21
21
  def __init__(self, document_noun: str, *args: Any, **kwargs: Any) -> None:
22
- self.attributes_to_validate: list[
23
- tuple[str, bool, str]
24
- ] = self.attributes_to_validate + [
25
- (
26
- "has_ncn",
27
- True,
28
- f"This {document_noun} has no neutral citation number",
29
- ),
30
- (
31
- "has_valid_ncn",
32
- True,
33
- f"The neutral citation number of this {document_noun} is not valid",
34
- ),
35
- ]
22
+ self.attributes_to_validate: list[tuple[str, bool, str]] = (
23
+ self.attributes_to_validate
24
+ + [
25
+ (
26
+ "has_ncn",
27
+ True,
28
+ f"This {document_noun} has no neutral citation number",
29
+ ),
30
+ (
31
+ "has_valid_ncn",
32
+ True,
33
+ f"The neutral citation number of this {document_noun} is not valid",
34
+ ),
35
+ ]
36
+ )
36
37
 
37
38
  super(NeutralCitationMixin, self).__init__(*args, **kwargs)
38
39
 
@@ -16,24 +16,25 @@ from typing_extensions import NotRequired
16
16
  env = environ.Env()
17
17
 
18
18
 
19
+ class ParserInstructionsMetadataDict(TypedDict):
20
+ name: Optional[str]
21
+ cite: Optional[str]
22
+ court: Optional[str]
23
+ date: Optional[str]
24
+ uri: Optional[str]
25
+
26
+
19
27
  class ParserInstructionsDict(TypedDict):
20
- name: NotRequired[Optional[str]]
21
- cite: NotRequired[Optional[str]]
22
- court: NotRequired[Optional[str]]
23
- date: NotRequired[Optional[str]]
24
- uri: NotRequired[Optional[str]]
25
28
  documentType: NotRequired[Optional[str]]
26
- published: NotRequired[bool]
29
+ metadata: NotRequired[ParserInstructionsMetadataDict]
27
30
 
28
31
 
29
32
  @overload
30
- def create_aws_client(service: Literal["s3"]) -> S3Client:
31
- ...
33
+ def create_aws_client(service: Literal["s3"]) -> S3Client: ...
32
34
 
33
35
 
34
36
  @overload
35
- def create_aws_client(service: Literal["sns"]) -> SNSClient:
36
- ...
37
+ def create_aws_client(service: Literal["sns"]) -> SNSClient: ...
37
38
 
38
39
 
39
40
  def create_aws_client(service: Union[Literal["s3"], Literal["sns"]]) -> Any:
@@ -1,7 +1,9 @@
1
1
  xquery version "1.0-ml";
2
2
 
3
- declare variable $target_major_version as xs:int external;
4
- declare variable $target_minor_version as xs:int external;
3
+ declare variable $target_enrichment_major_version as xs:int external;
4
+ declare variable $target_enrichment_minor_version as xs:int external;
5
+ declare variable $target_parser_major_version as xs:int external;
6
+ declare variable $target_parser_minor_version as xs:int external;
5
7
 
6
8
  xdmp:to-json(xdmp:sql(
7
9
  "SELECT process_data.uri, enrich_version_string, minutes_since_enrichment_request
@@ -9,20 +11,25 @@ xdmp:to-json(xdmp:sql(
9
11
  SELECT
10
12
  process_data.uri,
11
13
  enrich_version_string, enrich_major_version, enrich_minor_version,
14
+ parser_major_version, parser_minor_version,
12
15
  DATEDIFF('minute', last_sent_to_enrichment, CURRENT_TIMESTAMP) AS minutes_since_enrichment_request
13
16
  FROM documents.process_data
14
17
  JOIN documents.process_property_data ON process_data.uri = process_property_data.uri
15
18
  )
16
19
  WHERE (
17
20
  (enrich_version_string IS NULL) OR
18
- (enrich_major_version <= @target_major_version AND enrich_minor_version < @target_minor_version)
21
+ (enrich_major_version <= @target_enrichment_major_version AND enrich_minor_version < @target_enrichment_minor_version)
22
+ ) AND (
23
+ (parser_major_version = @target_parser_major_version AND parser_minor_version = @target_parser_minor_version)
19
24
  )
20
25
  AND (minutes_since_enrichment_request > 43200 OR minutes_since_enrichment_request IS NULL)
21
26
  ORDER BY enrich_major_version ASC NULLS FIRST, enrich_minor_version ASC",
22
27
  "array",
23
28
  map:new((
24
- map:entry("target_major_version", $target_major_version),
25
- map:entry("target_minor_version", $target_minor_version)
29
+ map:entry("target_enrichment_major_version", $target_enrichment_major_version),
30
+ map:entry("target_enrichment_minor_version", $target_enrichment_minor_version),
31
+ map:entry("target_parser_major_version", $target_parser_major_version),
32
+ map:entry("target_parser_minor_version", $target_parser_minor_version)
26
33
  ))
27
34
  ))
28
35
 
@@ -0,0 +1,37 @@
1
+ xquery version "1.0-ml";
2
+
3
+ declare namespace akn = "http://docs.oasis-open.org/legaldocml/ns/akn/3.0";
4
+ declare namespace uk = "https://caselaw.nationalarchives.gov.uk/akn";
5
+
6
+ declare variable $uri as xs:string external;
7
+ declare variable $content as xs:string external;
8
+ declare variable $proprietary-node := document($uri)/akn:akomaNtoso/akn:*/akn:meta/akn:proprietary;
9
+ declare variable $jurisdiction-node := $proprietary-node/uk:jurisdiction;
10
+
11
+ declare function local:delete($uri)
12
+ {
13
+ xdmp:node-delete($jurisdiction-node)
14
+ };
15
+
16
+ declare function local:edit($uri, $content)
17
+ {
18
+ xdmp:node-replace(
19
+ $jurisdiction-node,
20
+ <uk:jurisdiction>{$content}</uk:jurisdiction>
21
+ )
22
+ };
23
+
24
+ declare function local:add($uri, $content)
25
+ {
26
+ xdmp:node-insert-child(
27
+ $proprietary-node,
28
+ <uk:jurisdiction>{$content}</uk:jurisdiction>
29
+ )
30
+ };
31
+
32
+ if (fn:boolean(
33
+ cts:search(doc($uri),
34
+ cts:element-query(xs:QName('uk:jurisdiction'),cts:and-query(()))))) then
35
+ if ($content = "") then local:delete($uri) else local:edit($uri, $content)
36
+ else
37
+ local:add($uri, $content)
@@ -80,8 +80,10 @@ class GetLastModifiedDict(MarkLogicAPIDict):
80
80
 
81
81
  # get_pending_enrichment_for_version.xqy
82
82
  class GetPendingEnrichmentForVersionDict(MarkLogicAPIDict):
83
- target_major_version: int
84
- target_minor_version: int
83
+ target_enrichment_major_version: int
84
+ target_enrichment_minor_version: int
85
+ target_parser_major_version: int
86
+ target_parser_minor_version: int
85
87
 
86
88
 
87
89
  # get_pending_parse_for_version.xqy
@@ -142,6 +144,12 @@ class SetMetadataCourtDict(MarkLogicAPIDict):
142
144
  uri: MarkLogicDocumentURIString
143
145
 
144
146
 
147
+ # set_metadata_jurisdiction.xqy
148
+ class SetMetadataJurisdictionDict(MarkLogicAPIDict):
149
+ content: str
150
+ uri: MarkLogicDocumentURIString
151
+
152
+
145
153
  # set_metadata_name.xqy
146
154
  class SetMetadataNameDict(MarkLogicAPIDict):
147
155
  content: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ds-caselaw-marklogic-api-client
3
- Version: 20.0.0
3
+ Version: 21.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
@@ -1,16 +1,16 @@
1
- caselawclient/Client.py,sha256=PKyGcRi9rNMHF17Gbj5_LWAo6HTQ8JbmNOPLp8bd7KI,37002
1
+ caselawclient/Client.py,sha256=JmDrsC678sj2REAasJZCA_ujeUsGYI0X6C5tA9iaijI,38099
2
2
  caselawclient/__init__.py,sha256=DY-caubLDQWWingSdsBWgovDNXh8KcnkI6kwz08eIFk,612
3
3
  caselawclient/client_helpers/__init__.py,sha256=6vUjIwi777iaNDBUYwWmpzgAXeFHeXnmmMBniVmjUP8,3830
4
4
  caselawclient/client_helpers/search_helpers.py,sha256=DYgUltPq8fFI2KkLRqH1-8zpbb8_swBFyBvvgBbinig,1514
5
5
  caselawclient/content_hash.py,sha256=DF7ujrQPNf1bTSbK0mIIaC5qx6CmF5I0xlQ7uIG0zYI,2236
6
6
  caselawclient/errors.py,sha256=3rsbOQ11hIhm7-UABcHNMcs9XgcrIzytAP0koyZBLWM,3195
7
7
  caselawclient/models/__init__.py,sha256=kd23EUpvaC7aLHdgk8farqKAQEx3lf7RvNT2jEatvlg,68
8
- caselawclient/models/documents.py,sha256=WTZc5FrbTeL3fhSoTRJVaHpRiYFP7bSySu1nEgWsqFk,19673
8
+ caselawclient/models/documents.py,sha256=6w_U3Lwuve0ffJLJW78Lt5uojIbzD6I3PKWGWWLYFUU,20365
9
9
  caselawclient/models/judgments.py,sha256=TcAsn27K--QQAfaaUZ8biybB9OeVS__91FRlwaG16HY,1020
10
- caselawclient/models/neutral_citation_mixin.py,sha256=qqB1K4IHVy0XvdY40sfVywZ6VGaZ9ojHcVOQRyi0Vhc,1752
10
+ caselawclient/models/neutral_citation_mixin.py,sha256=G9QS5XZ0tf_VXTxt4Uryy_gZ4eBDsmChqEClLAntIwI,1810
11
11
  caselawclient/models/press_summaries.py,sha256=5c1jpVhVtmIMN8AeHMywGXvz4H55kKAIUaaaVims6Tw,994
12
12
  caselawclient/models/utilities/__init__.py,sha256=aL1a2nDacPxninETeaVZKwOxZemgvm73IcpWgMNXoGc,1100
13
- caselawclient/models/utilities/aws.py,sha256=HxmcoDXPpkDfxDH-tm3HtxnMCfOC2qIuy6PZs46OveY,7645
13
+ caselawclient/models/utilities/aws.py,sha256=6J6dOhyNzSHkIpAFseJDDNBQTXkTs63qS1W-oXZaqG8,7648
14
14
  caselawclient/models/utilities/move.py,sha256=_SKzO1UVXHFIVvWfT4nuCwdov7acp8tYzzEg-vVfUyg,5372
15
15
  caselawclient/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  caselawclient/responses/__init__.py,sha256=2-5NJn_PXPTje_W4dHeHYaNRN6vXK4UcB9eLLNUAKa4,67
@@ -34,7 +34,7 @@ caselawclient/xquery/get_judgment.xqy,sha256=xg66A1xslgwds670gu_9DFcOmxYGoo8sA2E
34
34
  caselawclient/xquery/get_judgment_checkout_status.xqy,sha256=mdY9UXLyzQdB7byEERPqentlr0YDLbXRVqH0h4UuZTQ,193
35
35
  caselawclient/xquery/get_judgment_version.xqy,sha256=wF9k9-CBrqo8VbxxyTrD-AGzR3-3jMm25tRVCjxPLrU,292
36
36
  caselawclient/xquery/get_last_modified.xqy,sha256=8fCm_7o_kkytCEmEeSTLWzLP7iOjuPV01IfHDgf6HaQ,172
37
- caselawclient/xquery/get_pending_enrichment_for_version.xqy,sha256=8B9prPDQXj5-gd8XY7UedOyIX6jsRy0ZWOSLjz6UE0I,1077
37
+ caselawclient/xquery/get_pending_enrichment_for_version.xqy,sha256=jYc2OPnAIU4kfRsyhCam9RtrxOB2KhKX40CALFc2Rwo,1623
38
38
  caselawclient/xquery/get_pending_parse_for_version.xqy,sha256=1HRQ3Mwljgp1QbVTiesJrV5HuuMCyKPDMzBOzrT_oQM,1054
39
39
  caselawclient/xquery/get_properties_for_search_results.xqy,sha256=Tlv3EKwVV_q-JyQyhjWVHIleicPDpucxP4ScuQjpgSw,625
40
40
  caselawclient/xquery/get_property.xqy,sha256=RHlOTrK0aH-S7s_ykYzGmUeKOJxXlI4vE5sKRt556NY,209
@@ -45,6 +45,7 @@ caselawclient/xquery/list_judgment_versions.xqy,sha256=WShga8igeD21hSLfVSvCOiDMP
45
45
  caselawclient/xquery/set_boolean_property.xqy,sha256=8Vg3yDWqeDynUJQHw2OF4daDIKTnp8ARol1_OCqY0Dk,355
46
46
  caselawclient/xquery/set_metadata_citation.xqy,sha256=ImwijXowvOCiH_br_LepnKsEpys9tg4Cf3uz6MoC5-c,659
47
47
  caselawclient/xquery/set_metadata_court.xqy,sha256=xQGR3e4pdJuDPMlzdAdzrBDSeQbEFiLVIm2z_KQI_Ds,996
48
+ caselawclient/xquery/set_metadata_jurisdiction.xqy,sha256=7iG1uFZOme0_d1hkzLJ870ot_ioFnSwDROfA-_yGtN8,1059
48
49
  caselawclient/xquery/set_metadata_name.xqy,sha256=7UeCo13ePNPxXcz9v7o1Pw7MoL6b5voOS6STmy-ROf4,752
49
50
  caselawclient/xquery/set_metadata_this_uri.xqy,sha256=lBHk2EJxcRcxu1JqNdBlSzUZmFvVaSs0vu2cVrt84c8,1762
50
51
  caselawclient/xquery/set_metadata_work_expression_date.xqy,sha256=eN4VvRA5FqP3aKrlvnqwa7e9mcuuNXqLH5_yHWvrjrU,1017
@@ -56,8 +57,8 @@ caselawclient/xquery/user_has_role.xqy,sha256=52YuFZnXqaDDJs-j_UanpqcLNEiw_m9xb0
56
57
  caselawclient/xquery/validate_all_documents.xqy,sha256=z_0YEXmRcZ-FaJM0ouKiTjdI4tLKQ4FTssRihR07qFk,156
57
58
  caselawclient/xquery/xslt.xqy,sha256=w57wNijH3dkwHkpKeAxqjlghVflQwo8cq6jS_sm-erM,199
58
59
  caselawclient/xquery/xslt_transform.xqy,sha256=smyFFxqmtkuOzBd2l7uw6K2oAsYctudrP8omdv_XNAM,2463
59
- caselawclient/xquery_type_dicts.py,sha256=LpD5p7D-9kclSE15zGcCLqVl090xklqAR6n99onidrg,5042
60
- ds_caselaw_marklogic_api_client-20.0.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
61
- ds_caselaw_marklogic_api_client-20.0.0.dist-info/METADATA,sha256=b5cVU1HXx6AkLkyRKXw2U3qjGOZm9dgVE9aUCG7bG64,4006
62
- ds_caselaw_marklogic_api_client-20.0.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
63
- ds_caselaw_marklogic_api_client-20.0.0.dist-info/RECORD,,
60
+ caselawclient/xquery_type_dicts.py,sha256=A7yNusrb3lMKg6tmMrTOPZcjuJEijWHiBk4hk6eKCMM,5278
61
+ ds_caselaw_marklogic_api_client-21.0.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
62
+ ds_caselaw_marklogic_api_client-21.0.0.dist-info/METADATA,sha256=OTHWjjgvwMlUUY-YxoHCgoSBclZSlwjYs6FfXf-xrgc,4006
63
+ ds_caselaw_marklogic_api_client-21.0.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
64
+ ds_caselaw_marklogic_api_client-21.0.0.dist-info/RECORD,,