-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve identifier URIs to MarkLogic URIs
- Loading branch information
1 parent
abad449
commit 54b7536
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
from typing import NamedTuple | ||
|
||
from caselawclient.models.documents import DocumentURIString | ||
from caselawclient.xquery_type_dicts import MarkLogicDocumentURIString | ||
|
||
|
||
class IdentifierResolution(NamedTuple): | ||
identifier_uuid: str | ||
document_uri: MarkLogicDocumentURIString | ||
identifier_slug: DocumentURIString | ||
document_published: bool | ||
|
||
@staticmethod | ||
def from_marklogic_output(raw_row: str) -> "IdentifierResolution": | ||
row = json.loads(raw_row) | ||
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", | ||
) | ||
|
||
|
||
class IdentifierResolutions(list[IdentifierResolution]): | ||
@staticmethod | ||
def from_marklogic_output(table: list[str]) -> "IdentifierResolutions": | ||
return IdentifierResolutions(list(IdentifierResolution.from_marklogic_output(row) for row in table)) | ||
|
||
def published(self) -> "IdentifierResolutions": | ||
return IdentifierResolutions(list(x for x in self if x.document_published)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
xquery version "1.0-ml"; | ||
|
||
declare namespace xdmp="http://marklogic.com/xdmp"; | ||
declare variable $uri as xs:string external; | ||
declare variable $identifier_uri as xs:string external; | ||
|
||
xdmp:sql( | ||
"SELECT * from compiled_url_slugs WHERE documents.compiled_url_slugs.identifier_slug = @uri", | ||
"array", | ||
"map", | ||
map:new(( | ||
map:entry("uri", $uri) | ||
map:entry("uri", $identifier_uri) | ||
)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters