Skip to content

Commit

Permalink
Add identifier namespace and type to IdentifierResolution
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Jan 17, 2025
1 parent 31cb78f commit a884aaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/caselawclient/identifier_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import NamedTuple

from caselawclient.models.documents import DocumentURIString
from caselawclient.models.identifiers import Identifier
from caselawclient.models.identifiers.unpacker import IDENTIFIER_NAMESPACE_MAP
from caselawclient.xquery_type_dicts import MarkLogicDocumentURIString


Expand Down Expand Up @@ -33,15 +35,18 @@ class IdentifierResolution(NamedTuple):
document_published: bool
identifier_value: str
identifier_namespace: str
identifier_type: type[Identifier]

@staticmethod
def from_marklogic_output(raw_row: str) -> "IdentifierResolution":
row = json.loads(raw_row)
identifier_namespace = row["documents.compiled_url_slugs.identifier_namespace"]
return IdentifierResolution(
identifier_uuid=row["documents.compiled_url_slugs.identifier_uuid"],
document_uri=MarkLogicDocumentURIString(row["documents.compiled_url_slugs.document_uri"]),
identifier_slug=DocumentURIString(row["documents.compiled_url_slugs.identifier_slug"]),
document_published=row["documents.compiled_url_slugs.document_published"] == "true",
identifier_value=row["documents.compiled_url_slugs.identifier_value"],
identifier_namespace=row["documents.compiled_url_slugs.identifier_namespace"],
identifier_namespace=identifier_namespace,
identifier_type=IDENTIFIER_NAMESPACE_MAP[identifier_namespace],
)
14 changes: 12 additions & 2 deletions tests/client/test_identifier_resolution.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
from caselawclient.identifier_resolution import IdentifierResolutions
from caselawclient.models.identifiers.neutral_citation import NeutralCitationNumber

raw_marklogic_resolutions = [
"""
{"documents.compiled_url_slugs.identifier_uuid":"24b9a384-8bcf-4f20-996a-5c318f8dc657",
"documents.compiled_url_slugs.document_uri":"/ewca/civ/2003/547.xml",
"documents.compiled_url_slugs.identifier_slug":"ewca/civ/2003/54721",
"documents.compiled_url_slugs.document_published":"false"}
"documents.compiled_url_slugs.document_published":"false",
"documents.compiled_url_slugs.identifier_namespace":"ukncn",
"documents.compiled_url_slugs.identifier_value":"[2003] EWCA 54721 (Civ)"
}
""",
"""
{"documents.compiled_url_slugs.identifier_uuid":"x",
"documents.compiled_url_slugs.document_uri":"x",
"documents.compiled_url_slugs.identifier_slug":"x",
"documents.compiled_url_slugs.document_published":"true"}
"documents.compiled_url_slugs.document_published":"true",
"documents.compiled_url_slugs.identifier_namespace":"ukncn",
"documents.compiled_url_slugs.identifier_value":"X"
}
""",
]

Expand All @@ -22,6 +29,9 @@ def test_decoded_identifier():
assert res.identifier_uuid == "24b9a384-8bcf-4f20-996a-5c318f8dc657"
assert res.document_uri == "/ewca/civ/2003/547.xml"
assert res.identifier_slug == "ewca/civ/2003/54721"
assert res.identifier_namespace == "ukncn"
assert res.identifier_type == NeutralCitationNumber
assert res.identifier_value == "[2003] EWCA 54721 (Civ)"
assert res.document_published == False # noqa: E712


Expand Down

0 comments on commit a884aaf

Please sign in to comment.