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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import Any, Literal

from ..sections.utils import validate_section
from .model import ChordAnalysisResult, ChordLabel, SectionChordSummary

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,15 +49,7 @@ def analyze(
summaries: list[SectionChordSummary] = []

for i, section in enumerate(sections):
if not isinstance(section, dict):
logger.warning(
"Invalid section format at index %d; expected dict, got %s",
i,
type(section).__name__,
)
section_id = f"section-{i}"
else:
section_id = section.get("id", f"section-{i}")
section_id = validate_section(section, i, logger)

chords: list[ChordLabel] = []
key_center = _DEFAULT_KEY_CENTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import Any, Literal

from ..sections.utils import validate_section
from .model import (
RangeAnalysisResult,
RangeInfo,
Expand Down Expand Up @@ -182,15 +183,7 @@ def analyze(
summaries: list[SectionRangeSummary] = []

for i, section in enumerate(sections):
if not isinstance(section, dict):
logger.warning(
"Invalid section format at index %d; expected dict, got %s",
i,
type(section).__name__,
)
section_id = f"section-{i}"
else:
section_id = section.get("id", f"section-{i}")
section_id = validate_section(section, i, logger)

section_roles = (roles_by_section or {}).get(section_id, [])
ranges: list[RangeInfo] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import Any

from ..sections.utils import validate_section
from .model import (
CueAnchorKind,
PartGraphNode,
Expand Down Expand Up @@ -53,15 +54,7 @@ def extract(

# Simple mock implementation for testing/demonstration purposes
for i, section in enumerate(sections):
if not isinstance(section, dict):
logger.warning(
"Invalid section format at index %d; expected dict, got %s",
i,
type(section).__name__,
)
section_id = f"section-{i}"
else:
section_id = section.get("id", f"section-{i}")
section_id = validate_section(section, i, logger)

topology = self._build_topology(section_id, i == 0, roles)
topologies.append(topology)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SectionExtractionResult,
SectionLabel,
)
from .utils import validate_section

__all__ = [
"CueAnchor",
Expand All @@ -25,4 +26,5 @@
"count_based_anchor",
"lyric_phrase_anchor",
"extract_sections",
"validate_section",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Utility functions for section processing."""

from __future__ import annotations

import logging
from typing import Any


def validate_section(section: Any, index: int, logger: logging.Logger) -> str:
"""Return a stable section id, warning when section data is malformed."""
if not isinstance(section, dict):
logger.warning(
"Invalid section format at index %d; expected dict, got %s",
index,
type(section).__name__,
)
return f"section-{index}"
return str(section.get("id", f"section-{index}"))
Loading