""" Extractive QA / Answer Span Layout Display a question and a passage; annotator highlights the answer span in the passage. A streamlined SQuAD-style workflow that combines question display with directed span selection. Research: Rajpurkar et al. (2016) "SQuAD"; Kwiatkowski et al. (2019) "Natural Questions". """ import logging from .identifier_utils import ( safe_generate_layout, generate_element_identifier, generate_validation_attribute, escape_html_content, generate_layout_attributes ) logger = logging.getLogger(__name__) DEFAULT_HIGHLIGHT_COLOR = "#FFEB3B" DEFAULT_ALLOW_UNANSWERABLE = True def generate_extractive_qa_layout(annotation_scheme): """ Generate HTML for an Extractive QA interface. Args: annotation_scheme (dict): Configuration including: - name: Schema identifier - description: Display description - question_field: Field in data containing the question - passage_field: Field in data containing the passage - allow_unanswerable: Whether to show "Unanswerable" button - highlight_color: Color for answer highlight Returns: tuple: (html_string, key_bindings) """ return safe_generate_layout(annotation_scheme, _generate_extractive_qa_layout_internal) def _generate_extractive_qa_layout_internal(annotation_scheme): schema_name = annotation_scheme['name'] description = annotation_scheme['description'] question_field = annotation_scheme.get('question_field', 'question') passage_field = annotation_scheme.get('passage_field', '') allow_unanswerable = annotation_scheme.get('allow_unanswerable', DEFAULT_ALLOW_UNANSWERABLE) highlight_color = annotation_scheme.get('highlight_color', DEFAULT_HIGHLIGHT_COLOR) layout_attrs = generate_layout_attributes(annotation_scheme) validation = generate_validation_attribute(annotation_scheme) identifiers = generate_element_identifier(schema_name, schema_name, "hidden") unanswerable_btn = "" if allow_unanswerable: unanswerable_btn = f""" """ html = f"""
""" logger.info(f"Generated extractive QA layout for {schema_name}") return html, []