caselawclient.models.identifiers.fclid

 1import re
 2from typing import TYPE_CHECKING
 3
 4from sqids import Sqids
 5
 6from caselawclient.types import DocumentIdentifierSlug
 7
 8from . import Identifier, IdentifierSchema
 9
10if TYPE_CHECKING:
11    from caselawclient.Client import MarklogicApiClient
12
13
14VALID_FCLID_PATTERN = re.compile(r"^[bcdfghjkmnpqrstvwxyz23456789]{4,}$")
15
16FCLID_MINIMUM_LENGTH = 8
17FCLID_ALPHABET = "bcdfghjkmnpqrstvwxyz23456789"
18
19sqids = Sqids(
20    min_length=FCLID_MINIMUM_LENGTH,
21    alphabet=FCLID_ALPHABET,
22)
23
24
25class FindCaseLawIdentifierSchema(IdentifierSchema):
26    """
27    Identifier schema describing a Find Case Law Identifier.
28    """
29
30    name = "Find Case Law Identifier"
31    namespace = "fclid"
32    human_readable = False
33    base_score_multiplier = 0.6
34
35    allow_editing = False
36    require_globally_unique = True
37
38    @classmethod
39    def validate_identifier_value(cls, value: str) -> bool:
40        return bool(VALID_FCLID_PATTERN.match(value))
41
42    @classmethod
43    def compile_identifier_url_slug(cls, value: str) -> DocumentIdentifierSlug:
44        return DocumentIdentifierSlug("tna." + value)
45
46    @classmethod
47    def mint(cls, api_client: "MarklogicApiClient") -> "FindCaseLawIdentifier":
48        """Generate a totally new Find Case Law identifier."""
49        next_sequence_number = api_client.get_next_document_sequence_number()
50        new_identifier = sqids.encode([next_sequence_number])
51        return FindCaseLawIdentifier(value=new_identifier)
52
53
54class FindCaseLawIdentifier(Identifier):
55    schema = FindCaseLawIdentifierSchema
VALID_FCLID_PATTERN = re.compile('^[bcdfghjkmnpqrstvwxyz23456789]{4,}$')
FCLID_MINIMUM_LENGTH = 8
FCLID_ALPHABET = 'bcdfghjkmnpqrstvwxyz23456789'
sqids = <sqids.sqids.Sqids object>
class FindCaseLawIdentifierSchema(caselawclient.models.identifiers.IdentifierSchema):
26class FindCaseLawIdentifierSchema(IdentifierSchema):
27    """
28    Identifier schema describing a Find Case Law Identifier.
29    """
30
31    name = "Find Case Law Identifier"
32    namespace = "fclid"
33    human_readable = False
34    base_score_multiplier = 0.6
35
36    allow_editing = False
37    require_globally_unique = True
38
39    @classmethod
40    def validate_identifier_value(cls, value: str) -> bool:
41        return bool(VALID_FCLID_PATTERN.match(value))
42
43    @classmethod
44    def compile_identifier_url_slug(cls, value: str) -> DocumentIdentifierSlug:
45        return DocumentIdentifierSlug("tna." + value)
46
47    @classmethod
48    def mint(cls, api_client: "MarklogicApiClient") -> "FindCaseLawIdentifier":
49        """Generate a totally new Find Case Law identifier."""
50        next_sequence_number = api_client.get_next_document_sequence_number()
51        new_identifier = sqids.encode([next_sequence_number])
52        return FindCaseLawIdentifier(value=new_identifier)

Identifier schema describing a Find Case Law Identifier.

name = 'Find Case Law Identifier'
namespace = 'fclid'
human_readable = False

Should this identifier type be considered for display as a 'human readable' identifier?

base_score_multiplier = 0.6

A multiplier used to adjust the relative ranking of this identifier when calculating preferred identifiers.

allow_editing = False

Should editors be allowed to manually manipulate identifiers under this schema?

require_globally_unique = True

Must this identifier be globally unique? (appear on no other documents)

@classmethod
def validate_identifier_value(cls, value: str) -> bool:
39    @classmethod
40    def validate_identifier_value(cls, value: str) -> bool:
41        return bool(VALID_FCLID_PATTERN.match(value))

Check that any given identifier value is valid for this schema.

@classmethod
def compile_identifier_url_slug(cls, value: str) -> caselawclient.types.DocumentIdentifierSlug:
43    @classmethod
44    def compile_identifier_url_slug(cls, value: str) -> DocumentIdentifierSlug:
45        return DocumentIdentifierSlug("tna." + value)

Convert an identifier into a precompiled URL slug.

@classmethod
def mint( cls, api_client: caselawclient.Client.MarklogicApiClient) -> FindCaseLawIdentifier:
47    @classmethod
48    def mint(cls, api_client: "MarklogicApiClient") -> "FindCaseLawIdentifier":
49        """Generate a totally new Find Case Law identifier."""
50        next_sequence_number = api_client.get_next_document_sequence_number()
51        new_identifier = sqids.encode([next_sequence_number])
52        return FindCaseLawIdentifier(value=new_identifier)

Generate a totally new Find Case Law identifier.

class FindCaseLawIdentifier(caselawclient.models.identifiers.Identifier):
55class FindCaseLawIdentifier(Identifier):
56    schema = FindCaseLawIdentifierSchema

A base class for subclasses representing a concrete identifier.

schema = <class 'FindCaseLawIdentifierSchema'>