Id Regulation Constants
Shared constants for Indonesian regulation document processing.
Centralises all regex patterns, lookup tables, and enum types used by both the IDRegulationParser and the IDRegulationChunker so neither stage needs to import from the other. IDRegulationParser annotates each parsed element with structure metadata; IDRegulationChunker groups those pre-tagged elements into per-article output chunks.
TODO: this module mixes constants with parsing helper functions (e.g. parse_indonesian_part_number, parse_roman_numeral). Split into a constants.py and a utils.py for id_regulation in a separate PR.
AmendmentGroupLevel
Bases: StrEnum
Structural level of a Bagian/BAB/Paragraf group quoted as amendment payload.
Distinguishes a quoted group's own hierarchy level (see IDRegulationParser's regulation_amendment_group_level metadata field) from the article-level AmendmentOperation -- a single INSERT item can introduce a whole new chapter/part/paragraph, and this is the vocabulary for which level it is.
AmendmentOperation
Bases: StrEnum
Amendment operation types for Indonesian regulations.
CitationType
Bases: StrEnum
Citation types for regulation cross-references.
NodeLabel
Bases: StrEnum
Neo4j node labels for the Indonesian regulation graph. See ONTOLOGY.md.
RegulationStructure
Bases: StrEnum
Structural element types within an Indonesian regulation document.
Used to tag each parsed element with its role in the document hierarchy, from front matter through chapters, parts, paragraphs, articles, body text, amendment directives, explanations, and the enactment tail.
RelationType
Bases: StrEnum
Neo4j relationship (edge) types for the Indonesian regulation graph. See ONTOLOGY.md.
VersionType
Bases: StrEnum
Article version types for Indonesian regulation graph nodes.
is_known_regulation_structure(regulation_structure)
Return whether a structure tag marks document content rather than page furniture.
IDRegulationParser keeps page boilerplate (the repeated masthead, standalone page numbers) in its output so nothing is silently dropped, but tags it UNKNOWN with an empty hierarchy. Those elements carry no legal meaning: IDRegulationChunker discards them, and structural assertions must skip them rather than read them as content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regulation_structure
|
Any
|
An element's |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True unless the tag is |
is_meaningful_title(text)
Return whether a section-title string carries real content.
Headings sometimes capture punctuation- or whitespace-only noise (e.g. OCR dot-leader artifacts like ". ."), which should be discarded rather than stored as a chapter/part/paragraph title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The candidate title text. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the text contains at least one alphanumeric character. |
match_ordinal_header_re(pattern, group_name, text)
Match an ordinal-header regex, requiring ALL CAPS when the colon glue is unspaced.
Regex lookbehind can't check a variable-length word's casing, so this does it in Python instead of duplicating the check across DECISION_CLAUSE_HEADER_RE and INSTRUCTION_HEADER_RE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
Pattern[str]
|
DECISION_CLAUSE_HEADER_RE or INSTRUCTION_HEADER_RE. |
required |
group_name
|
str
|
The pattern's ordinal-word capture group name. |
required |
text
|
str
|
Stripped element text. |
required |
Returns:
| Type | Description |
|---|---|
Match[str] | None
|
re.Match[str] | None: The match, or None if rejected for an unspaced glue on a not-fully-uppercase word. |
parse_indonesian_part_number(text)
Convert an Indonesian ordinal number-word phrase into its integer value.
Handles the irregular "Pertama", the optional ordinal prefix ke, and
additive/multiplicative number words, e.g.:
1. "Pertama" -> 1
2. "Kesatu" -> 1
3. "Kesebelas" -> 11
4. "Kedua Puluh" -> 20
5. "Ketiga Puluh Lima" -> 35
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The ordinal number-word phrase to parse, such as "Kesatu". |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The parsed integer value, or None if no number word is recognised. |
parse_roman_numeral(text)
Convert a Roman numeral into its integer value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Roman numeral to parse, such as "IX". Case-insensitive. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The parsed integer value, or None if the text is not a valid Roman numeral. |
resolve_inline_title(inline)
Return the stripped title if it is meaningful, None otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inline
|
str | None
|
Candidate inline title captured alongside a section header. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The stripped title when it carries real content, otherwise None. |