""" Ranking / Drag-and-Drop Layout Generates a draggable list of items that annotators can reorder. Uses a hidden input to store the rank order. Research basis: - Kiritchenko & Mohammad (2017) "Best-Worst Scaling More Reliable than Rating Scales" ACL - Thurstone (1927) "A Law of Comparative Judgment" """ import logging from potato.ai.ai_help_wrapper import get_ai_wrapper from .identifier_utils import ( safe_generate_layout, generate_element_identifier, generate_validation_attribute, escape_html_content, generate_layout_attributes, generate_tooltip_html, ) logger = logging.getLogger(__name__) def generate_ranking_layout(annotation_scheme): """ Generate HTML for a ranking / drag-and-drop annotation interface. Args: annotation_scheme (dict): Configuration including: - name: Schema identifier - description: Display description - labels: List of items to rank - allow_ties: Whether ties are allowed (default false) Returns: tuple: (html_string, key_bindings) """ return safe_generate_layout(annotation_scheme, _generate_ranking_layout_internal) def _generate_ranking_layout_internal(annotation_scheme): schema_name = annotation_scheme["name"] safe_schema = escape_html_content(schema_name) description = annotation_scheme["description"] labels = annotation_scheme.get("labels", []) allow_ties = annotation_scheme.get("allow_ties", False) layout_attrs = generate_layout_attributes(annotation_scheme) validation = generate_validation_attribute(annotation_scheme) if not labels: raise ValueError(f"ranking schema '{schema_name}' requires 'labels'") # Normalize labels label_names = [] for lbl in labels: if isinstance(lbl, str): label_names.append(lbl) elif isinstance(lbl, dict) and "name" in lbl: label_names.append(lbl["name"]) else: raise ValueError(f"Invalid label format: {lbl}") identifiers = generate_element_identifier(schema_name, "rank_order", "hidden") initial_order = ",".join(label_names) html = f"""
""" key_bindings = [] logger.info(f"Generated ranking layout for {schema_name} with {len(label_names)} items") return html, key_bindings