Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion exporters/html/html_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ def convert_to_html(data: Dict[str, Any], apply_amendments: bool = False, up_to_
organisation_data = data.get('organisation', {})
organisation = organisation_data.get('namn', '') if organisation_data else ''

# Determine doctype (grundlag, lag, or förordning)
from util.doctype_utils import determine_doctype
forfattningstyp_namn = data.get('forfattningstypNamn')
doctype = determine_doctype(beteckning, forfattningstyp_namn)

# Generate PDF URL
pdf_url = generate_pdf_url(beteckning, utfardad_datum, check_exists=False)

Expand Down Expand Up @@ -264,11 +269,16 @@ def convert_to_html(data: Dict[str, Any], apply_amendments: bool = False, up_to_
column1_items.append(f"""
<dt>Beteckning:</dt>
<dd property="eli:id_local" datatype="xsd:string">{html.escape(beteckning)}</dd>""")

if organisation:
column1_items.append(f"""
<dt>Departement:</dt>
<dd property="eli:passed_by" datatype="xsd:string">{html.escape(organisation)}</dd>""")

if doctype:
column1_items.append(f"""
<dt>Normtyp:</dt>
<dd property="eli:type_document" datatype="xsd:string">{html.escape(doctype)}</dd>""")

if pdf_url:
column1_items.append(f"""
Expand Down
3 changes: 2 additions & 1 deletion formatters/sort_frontmatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def sort_frontmatter_properties(frontmatter_content: str) -> str:
# Definiera den önskade ordningen för properties
PROPERTY_ORDER = [
'beteckning',
'rubrik',
'rubrik',
'normtyp',
'departement',
'utfardad_datum',
'ikraft_datum',
Expand Down
6 changes: 6 additions & 0 deletions sfs_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from util.yaml_utils import format_yaml_value
from util.datetime_utils import format_datetime
from util.file_utils import filter_json_files, save_to_disk
from util.doctype_utils import determine_doctype
from formatters.predocs_parser import parse_predocs_string


Expand Down Expand Up @@ -311,6 +312,10 @@ def convert_to_markdown(data: Dict[str, Any], fetch_predocs_from_api: bool = Fal
organisation_data = data.get('organisation', {})
organisation = organisation_data.get('namn', '') if organisation_data else ''

# Determine doctype (grundlag, lag, or förordning)
forfattningstyp_namn = data.get('forfattningstypNamn')
doctype = determine_doctype(beteckning, forfattningstyp_namn)

# Extract the main text content from nested structure
innehall_text = fulltext_data.get('forfattningstext')

Expand Down Expand Up @@ -348,6 +353,7 @@ def convert_to_markdown(data: Dict[str, Any], fetch_predocs_from_api: bool = Fal
beteckning: {format_yaml_value(beteckning)}
rubrik: {format_yaml_value(rubrik)}
departement: {format_yaml_value(organisation)}
normtyp: {format_yaml_value(doctype)}
"""

# Add dates if they exist (ikraft_datum will be added separately if needed)
Expand Down
70 changes: 70 additions & 0 deletions util/doctype_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Utility functions for determining doctype (legal document type) for SFS documents.

This module provides functions to classify Swedish legal documents into their
appropriate categories: grundlag (fundamental law), lag (law), or förordning (regulation).
"""

# Sveriges fyra grundlagar med deras SFS-beteckningar
GRUNDLAGAR = {
'1974:152', # Regeringsformen (RF)
'1810:0926', # Successionsordningen (SO)
'1949:105', # Tryckfrihetsförordningen (TF)
'1991:1469', # Yttrandefrihetsgrundlagen (YGL)
}


def determine_doctype(beteckning: str, forfattningstyp_namn: str = None) -> str:
"""
Determine the doctype (legal document type) for an SFS document.

The function classifies documents into three categories:
- 'Grundlag': One of Sweden's four fundamental laws
- 'Lag': Regular laws (förordningar excluded)
- 'Förordning': Regulations

Args:
beteckning: The SFS designation (e.g., "1974:152", "2024:1274")
forfattningstyp_namn: Optional type name from source data (e.g., "Lag", "Förordning")

Returns:
str: One of "Grundlag", "Lag", or "Förordning" (with capital first letter)

Examples:
>>> determine_doctype("1974:152", "Lag")
'Grundlag'
>>> determine_doctype("2024:1274", "Förordning")
'Förordning'
>>> determine_doctype("2010:800", "Lag")
'Lag'
"""
# First check if it's one of the fundamental laws
if beteckning in GRUNDLAGAR:
return 'Grundlag'

# If we have explicit type information, use it
if forfattningstyp_namn:
# Normalize the type name (case-insensitive matching)
normalized_type = forfattningstyp_namn.lower()

if 'förordning' in normalized_type:
return 'Förordning'
elif 'lag' in normalized_type:
return 'Lag'

# Default fallback: assume it's a law if we can't determine otherwise
# This is a safe default as most SFS documents are laws
return 'Lag'


def is_grundlag(beteckning: str) -> bool:
"""
Check if a document is one of Sweden's four fundamental laws.

Args:
beteckning: The SFS designation (e.g., "1974:152")

Returns:
bool: True if the document is a grundlag, False otherwise
"""
return beteckning in GRUNDLAGAR