infinity-context 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- infinity_context-0.1.0.dist-info/METADATA +239 -0
- infinity_context-0.1.0.dist-info/RECORD +1053 -0
- infinity_context-0.1.0.dist-info/WHEEL +5 -0
- infinity_context-0.1.0.dist-info/entry_points.txt +9 -0
- infinity_context-0.1.0.dist-info/licenses/LICENSE +201 -0
- infinity_context-0.1.0.dist-info/top_level.txt +8 -0
- infinity_context_adapters/__init__.py +1 -0
- infinity_context_adapters/cognee/__init__.py +5 -0
- infinity_context_adapters/cognee/adapter.py +364 -0
- infinity_context_adapters/embeddings/__init__.py +6 -0
- infinity_context_adapters/embeddings/noop_adapter.py +5 -0
- infinity_context_adapters/embeddings/openai_adapter.py +104 -0
- infinity_context_adapters/extraction/__init__.py +41 -0
- infinity_context_adapters/extraction/content.py +828 -0
- infinity_context_adapters/extraction/docling_engine.py +255 -0
- infinity_context_adapters/extraction/document_normalization.py +434 -0
- infinity_context_adapters/extraction/factory.py +69 -0
- infinity_context_adapters/extraction/fallback_context.py +137 -0
- infinity_context_adapters/extraction/file_detection.py +378 -0
- infinity_context_adapters/extraction/image_evidence.py +319 -0
- infinity_context_adapters/extraction/media_tools.py +579 -0
- infinity_context_adapters/extraction/openai_json.py +356 -0
- infinity_context_adapters/extraction/openai_vision.py +722 -0
- infinity_context_adapters/extraction/prompts/__init__.py +1 -0
- infinity_context_adapters/extraction/prompts/semantic_memory_v1.md +20 -0
- infinity_context_adapters/extraction/schemas/__init__.py +1 -0
- infinity_context_adapters/extraction/schemas/semantic_memory_v1.json +62 -0
- infinity_context_adapters/extraction/transcription/__init__.py +11 -0
- infinity_context_adapters/extraction/transcription/openai_adapter.py +400 -0
- infinity_context_adapters/extraction/transcription_engine.py +544 -0
- infinity_context_adapters/extraction/video_evidence.py +129 -0
- infinity_context_adapters/extraction/whisper_engine.py +386 -0
- infinity_context_adapters/features/__init__.py +7 -0
- infinity_context_adapters/features/context_building/__init__.py +53 -0
- infinity_context_adapters/features/context_building/candidate_provider_chain.py +68 -0
- infinity_context_adapters/features/context_building/graphiti_candidate_provider.py +44 -0
- infinity_context_adapters/features/context_building/in_memory_candidate_provider.py +62 -0
- infinity_context_adapters/features/context_building/postgres_candidate_provider.py +44 -0
- infinity_context_adapters/features/context_building/qdrant_candidate_provider.py +44 -0
- infinity_context_adapters/features/context_building/query_request.py +99 -0
- infinity_context_adapters/features/context_building/records.py +113 -0
- infinity_context_adapters/features/document_ingestion/__init__.py +74 -0
- infinity_context_adapters/features/document_ingestion/composition.py +69 -0
- infinity_context_adapters/features/document_ingestion/extraction_adapter.py +114 -0
- infinity_context_adapters/features/document_ingestion/in_memory_chunk_index.py +67 -0
- infinity_context_adapters/features/document_ingestion/in_memory_document_store.py +176 -0
- infinity_context_adapters/features/document_ingestion/postgres_document_store.py +110 -0
- infinity_context_adapters/features/document_ingestion/qdrant_chunk_index.py +49 -0
- infinity_context_adapters/features/document_ingestion/records.py +88 -0
- infinity_context_adapters/features/memory_facts/__init__.py +53 -0
- infinity_context_adapters/features/memory_facts/graphiti_fact_projection.py +111 -0
- infinity_context_adapters/features/memory_facts/in_memory_fact_store.py +200 -0
- infinity_context_adapters/features/memory_facts/postgres_fact_store.py +126 -0
- infinity_context_adapters/features/memory_facts/qdrant_fact_projection.py +100 -0
- infinity_context_adapters/features/memory_scopes/__init__.py +44 -0
- infinity_context_adapters/features/memory_scopes/in_memory_scope_store.py +189 -0
- infinity_context_adapters/features/memory_scopes/postgres_scope_store.py +121 -0
- infinity_context_adapters/features/memory_scopes/records.py +86 -0
- infinity_context_adapters/graphiti/__init__.py +5 -0
- infinity_context_adapters/graphiti/adapter.py +613 -0
- infinity_context_adapters/graphiti/identity_evidence.py +711 -0
- infinity_context_adapters/graphiti/scope_identity.py +31 -0
- infinity_context_adapters/local_blob.py +101 -0
- infinity_context_adapters/noop/__init__.py +16 -0
- infinity_context_adapters/noop/adapters.py +156 -0
- infinity_context_adapters/noop/runtime.py +21 -0
- infinity_context_adapters/postgres/__init__.py +19 -0
- infinity_context_adapters/postgres/asset_mappers.py +348 -0
- infinity_context_adapters/postgres/asset_repositories.py +865 -0
- infinity_context_adapters/postgres/benchmark_projection_schema.py +241 -0
- infinity_context_adapters/postgres/benchmark_run_completion.py +645 -0
- infinity_context_adapters/postgres/benchmark_run_repositories.py +908 -0
- infinity_context_adapters/postgres/benchmark_writer_fence.py +139 -0
- infinity_context_adapters/postgres/canonical_keyword_trigram.py +31 -0
- infinity_context_adapters/postgres/canonical_retrieval_batching.py +388 -0
- infinity_context_adapters/postgres/fact_repositories.py +766 -0
- infinity_context_adapters/postgres/mappers.py +745 -0
- infinity_context_adapters/postgres/migrations/0001_core_facts.sql +95 -0
- infinity_context_adapters/postgres/migrations/0002_threads_documents_chunks.sql +97 -0
- infinity_context_adapters/postgres/migrations/0003_suggestions.sql +24 -0
- infinity_context_adapters/postgres/migrations/0004_service_tokens.sql +16 -0
- infinity_context_adapters/postgres/migrations/0005_data_classification_lite.sql +8 -0
- infinity_context_adapters/postgres/migrations/0006_service_token_usage_metadata.sql +5 -0
- infinity_context_adapters/postgres/migrations/0007_service_token_permissions.sql +2 -0
- infinity_context_adapters/postgres/migrations/0008_service_token_memory_scope.sql +2 -0
- infinity_context_adapters/postgres/migrations/0009_outbox_lifecycle_hardening.sql +15 -0
- infinity_context_adapters/postgres/migrations/0010_fact_taxonomy.sql +14 -0
- infinity_context_adapters/postgres/migrations/0011_asset_extractions.sql +66 -0
- infinity_context_adapters/postgres/migrations/0012_asset_extraction_execution_hardening.sql +20 -0
- infinity_context_adapters/postgres/migrations/0012_usage_governance.sql +33 -0
- infinity_context_adapters/postgres/migrations/0013_context_link_suggestions.sql +44 -0
- infinity_context_adapters/postgres/migrations/0014_memory_anchors.sql +26 -0
- infinity_context_adapters/postgres/migrations/0015_users_acl.sql +36 -0
- infinity_context_adapters/postgres/migrations/0016_managed_benchmark_runs.sql +27 -0
- infinity_context_adapters/postgres/migrations/0017_managed_benchmark_writer_fence.sql +104 -0
- infinity_context_adapters/postgres/migrations/0018_benchmark_projection_manifest.sql +51 -0
- infinity_context_adapters/postgres/migrations/0019_managed_benchmark_sealed_fence.sql +131 -0
- infinity_context_adapters/postgres/migrations/0020_benchmark_cleanup_completion.sql +219 -0
- infinity_context_adapters/postgres/migrations/0021_benchmark_unsealed_abort.sql +64 -0
- infinity_context_adapters/postgres/migrations/0022_canonical_keyword_trigram.sql +5 -0
- infinity_context_adapters/postgres/models.py +878 -0
- infinity_context_adapters/postgres/projection_fence.py +80 -0
- infinity_context_adapters/postgres/repositories.py +906 -0
- infinity_context_adapters/postgres/repository_helpers.py +115 -0
- infinity_context_adapters/postgres/scope_repositories.py +540 -0
- infinity_context_adapters/postgres/unit_of_work.py +785 -0
- infinity_context_adapters/postgres/usage_repositories.py +128 -0
- infinity_context_adapters/postgres/user_repositories.py +164 -0
- infinity_context_adapters/provider_errors.py +73 -0
- infinity_context_adapters/qdrant/__init__.py +5 -0
- infinity_context_adapters/qdrant/identity_evidence.py +504 -0
- infinity_context_adapters/qdrant/vector_adapter.py +718 -0
- infinity_context_adapters/s3_blob.py +242 -0
- infinity_context_cli/__init__.py +5 -0
- infinity_context_cli/__main__.py +6 -0
- infinity_context_cli/cli.py +964 -0
- infinity_context_cli/config.py +184 -0
- infinity_context_cli/doctor.py +397 -0
- infinity_context_cli/local_experience.py +250 -0
- infinity_context_cli/mcp_config.py +124 -0
- infinity_context_cli/onboarding.py +542 -0
- infinity_context_cli/runtime.py +179 -0
- infinity_context_contracts/__init__.py +16 -0
- infinity_context_contracts/_json.py +32 -0
- infinity_context_contracts/capabilities.py +67 -0
- infinity_context_contracts/common.py +54 -0
- infinity_context_contracts/features/__init__.py +12 -0
- infinity_context_contracts/features/context_building.py +248 -0
- infinity_context_contracts/features/document_ingestion.py +277 -0
- infinity_context_contracts/features/memory_facts.py +236 -0
- infinity_context_contracts/features/memory_scopes.py +329 -0
- infinity_context_contracts/health.py +23 -0
- infinity_context_core/__init__.py +76 -0
- infinity_context_core/agent_behavior_contract.py +72 -0
- infinity_context_core/application/__init__.py +580 -0
- infinity_context_core/application/anchor_creative_work_filters.py +148 -0
- infinity_context_core/application/anchor_event_extraction.py +1571 -0
- infinity_context_core/application/anchor_extraction.py +1144 -0
- infinity_context_core/application/anchor_identity_normalization.py +90 -0
- infinity_context_core/application/anchor_relation_projection.py +203 -0
- infinity_context_core/application/anchor_temporal_window.py +172 -0
- infinity_context_core/application/asset_extraction_mapping.py +236 -0
- infinity_context_core/application/asset_upload_policy.py +952 -0
- infinity_context_core/application/auto_apply.py +72 -0
- infinity_context_core/application/auto_memory.py +527 -0
- infinity_context_core/application/capture_policy.py +61 -0
- infinity_context_core/application/chunker.py +93 -0
- infinity_context_core/application/context_action_role_evidence.py +890 -0
- infinity_context_core/application/context_action_role_labels.py +176 -0
- infinity_context_core/application/context_action_roles.py +2365 -0
- infinity_context_core/application/context_action_subject_policy.py +71 -0
- infinity_context_core/application/context_activity_companion.py +120 -0
- infinity_context_core/application/context_activity_duration_rerank.py +118 -0
- infinity_context_core/application/context_activity_participant_grounding.py +87 -0
- infinity_context_core/application/context_aggregation_answer_slots.py +586 -0
- infinity_context_core/application/context_aggregation_evidence_text.py +409 -0
- infinity_context_core/application/context_aggregation_rerank.py +145 -0
- infinity_context_core/application/context_aggregation_subject.py +137 -0
- infinity_context_core/application/context_allergy_condition_inference.py +146 -0
- infinity_context_core/application/context_anchor_identity.py +157 -0
- infinity_context_core/application/context_anchor_intent_ranking.py +84 -0
- infinity_context_core/application/context_anchor_relations.py +67 -0
- infinity_context_core/application/context_anchors.py +393 -0
- infinity_context_core/application/context_answer_evidence_types.py +14 -0
- infinity_context_core/application/context_answer_unit_shapes.py +207 -0
- infinity_context_core/application/context_artifact_evidence.py +893 -0
- infinity_context_core/application/context_attribution_lexicon.py +254 -0
- infinity_context_core/application/context_awareness_cause_rerank.py +109 -0
- infinity_context_core/application/context_baby_birth_evidence.py +91 -0
- infinity_context_core/application/context_birdwatching_schedule_rerank.py +130 -0
- infinity_context_core/application/context_bm25_ranking.py +450 -0
- infinity_context_core/application/context_book_author_preference_exact_turns.py +110 -0
- infinity_context_core/application/context_building_legacy_candidate_adapter.py +530 -0
- infinity_context_core/application/context_canonical_fact_retrieval.py +409 -0
- infinity_context_core/application/context_causal_reason_rerank.py +145 -0
- infinity_context_core/application/context_choice_reason_rerank.py +109 -0
- infinity_context_core/application/context_collectors.py +931 -0
- infinity_context_core/application/context_commonality_rerank.py +428 -0
- infinity_context_core/application/context_community_membership_inference.py +139 -0
- infinity_context_core/application/context_competition_count_exact_turns.py +383 -0
- infinity_context_core/application/context_conflicting_evidence_rerank.py +282 -0
- infinity_context_core/application/context_conversation_counterparty.py +260 -0
- infinity_context_core/application/context_count_cardinality.py +164 -0
- infinity_context_core/application/context_creative_work_count_exact_turns.py +517 -0
- infinity_context_core/application/context_diagnostics.py +55 -0
- infinity_context_core/application/context_diagnostics_bundle_keys.py +433 -0
- infinity_context_core/application/context_diagnostics_bundle_projection.py +711 -0
- infinity_context_core/application/context_diagnostics_item_projection.py +410 -0
- infinity_context_core/application/context_diagnostics_primitives.py +131 -0
- infinity_context_core/application/context_diagnostics_ranking.py +143 -0
- infinity_context_core/application/context_diagnostics_signals.py +209 -0
- infinity_context_core/application/context_diagnostics_sources.py +82 -0
- infinity_context_core/application/context_dialogue_authority.py +382 -0
- infinity_context_core/application/context_distinct_set_evidence.py +994 -0
- infinity_context_core/application/context_distinct_set_selection.py +335 -0
- infinity_context_core/application/context_domain_rerank_apply.py +310 -0
- infinity_context_core/application/context_domain_rerank_signals.py +2391 -0
- infinity_context_core/application/context_domain_rerank_types.py +14 -0
- infinity_context_core/application/context_english_activity_displacement_answer_support.py +128 -0
- infinity_context_core/application/context_english_lifestyle_inference.py +122 -0
- infinity_context_core/application/context_english_lifestyle_inference_answer_support.py +291 -0
- infinity_context_core/application/context_english_temporal_dates.py +53 -0
- infinity_context_core/application/context_evidence_priority.py +262 -0
- infinity_context_core/application/context_evidence_reservation_safety.py +208 -0
- infinity_context_core/application/context_exercise_performance_rerank.py +71 -0
- infinity_context_core/application/context_food_inventory_exact_turns.py +583 -0
- infinity_context_core/application/context_frequency_rerank.py +109 -0
- infinity_context_core/application/context_future_plan_timing_rerank.py +110 -0
- infinity_context_core/application/context_generic_behavior_inference.py +348 -0
- infinity_context_core/application/context_geo_residence_aliases.py +149 -0
- infinity_context_core/application/context_hydration.py +329 -0
- infinity_context_core/application/context_identity_fact_rerank.py +362 -0
- infinity_context_core/application/context_identity_rerank.py +76 -0
- infinity_context_core/application/context_identity_terms.py +15 -0
- infinity_context_core/application/context_inference_evidence.py +484 -0
- infinity_context_core/application/context_inference_evidence_terms.py +744 -0
- infinity_context_core/application/context_internal_diagnostics.py +61 -0
- infinity_context_core/application/context_item_evidence.py +108 -0
- infinity_context_core/application/context_item_purchase_evidence.py +49 -0
- infinity_context_core/application/context_keyword_aggregation_prefilter.py +63 -0
- infinity_context_core/application/context_keyword_ranking.py +178 -0
- infinity_context_core/application/context_lexical.py +750 -0
- infinity_context_core/application/context_lifecycle_rerank.py +502 -0
- infinity_context_core/application/context_link_candidate_policy.py +864 -0
- infinity_context_core/application/context_link_expansion.py +727 -0
- infinity_context_core/application/context_link_expansion_items.py +441 -0
- infinity_context_core/application/context_link_policy.py +451 -0
- infinity_context_core/application/context_link_source_enrichment.py +120 -0
- infinity_context_core/application/context_media_time.py +368 -0
- infinity_context_core/application/context_museum_visit_policy.py +66 -0
- infinity_context_core/application/context_named_person_preference.py +313 -0
- infinity_context_core/application/context_national_park_inference.py +93 -0
- infinity_context_core/application/context_object_attribute_rerank.py +416 -0
- infinity_context_core/application/context_object_mismatch.py +63 -0
- infinity_context_core/application/context_occupational_role_identity.py +961 -0
- infinity_context_core/application/context_ordinal_sequence.py +134 -0
- infinity_context_core/application/context_owner_grounding.py +408 -0
- infinity_context_core/application/context_packer.py +858 -0
- infinity_context_core/application/context_packer_answer_slots.py +733 -0
- infinity_context_core/application/context_packer_answer_support.py +3101 -0
- infinity_context_core/application/context_packer_answer_support_patterns.py +1267 -0
- infinity_context_core/application/context_packer_answer_support_slots.py +1209 -0
- infinity_context_core/application/context_packer_answer_support_utils.py +473 -0
- infinity_context_core/application/context_packer_diagnostics.py +48 -0
- infinity_context_core/application/context_packer_exact_literal_turns.py +697 -0
- infinity_context_core/application/context_packer_exact_prepasses.py +758 -0
- infinity_context_core/application/context_packer_exact_turn_utils.py +133 -0
- infinity_context_core/application/context_packer_identity_policy.py +155 -0
- infinity_context_core/application/context_packer_inference_reservation.py +113 -0
- infinity_context_core/application/context_packer_inventory_prepasses.py +359 -0
- infinity_context_core/application/context_packer_inventory_slots.py +771 -0
- infinity_context_core/application/context_packer_marker_coverage.py +409 -0
- infinity_context_core/application/context_packer_rendering.py +338 -0
- infinity_context_core/application/context_packer_selection.py +487 -0
- infinity_context_core/application/context_packer_source_policy.py +123 -0
- infinity_context_core/application/context_paired_evidence_requirements.py +78 -0
- infinity_context_core/application/context_paired_evidence_roles.py +64 -0
- infinity_context_core/application/context_person_activity_exact_turns.py +375 -0
- infinity_context_core/application/context_person_aliases.py +49 -0
- infinity_context_core/application/context_person_kinship.py +296 -0
- infinity_context_core/application/context_person_occupation.py +240 -0
- infinity_context_core/application/context_person_relation_inventory.py +755 -0
- infinity_context_core/application/context_person_residence.py +398 -0
- infinity_context_core/application/context_person_team_membership.py +305 -0
- infinity_context_core/application/context_pet_ownership.py +223 -0
- infinity_context_core/application/context_polarity_rerank.py +338 -0
- infinity_context_core/application/context_policy.py +107 -0
- infinity_context_core/application/context_political_inference.py +128 -0
- infinity_context_core/application/context_possession_source.py +161 -0
- infinity_context_core/application/context_precise_temporal_evidence.py +156 -0
- infinity_context_core/application/context_preference_goal_rerank.py +428 -0
- infinity_context_core/application/context_preference_inference.py +335 -0
- infinity_context_core/application/context_property_interaction_evidence.py +659 -0
- infinity_context_core/application/context_provider_retrieval_terms.py +95 -0
- infinity_context_core/application/context_quality.py +488 -0
- infinity_context_core/application/context_quantity_evidence_patterns.py +254 -0
- infinity_context_core/application/context_quantity_evidence_slots.py +750 -0
- infinity_context_core/application/context_quantity_pending_clothing.py +200 -0
- infinity_context_core/application/context_query_artifact_inventory_expansions.py +76 -0
- infinity_context_core/application/context_query_decomposition.py +879 -0
- infinity_context_core/application/context_query_decomposition_answer_policy.py +707 -0
- infinity_context_core/application/context_query_decomposition_contracts.py +28 -0
- infinity_context_core/application/context_query_decomposition_event_policy.py +535 -0
- infinity_context_core/application/context_query_decomposition_inventory_policy.py +767 -0
- infinity_context_core/application/context_query_decomposition_shared.py +300 -0
- infinity_context_core/application/context_query_duration.py +171 -0
- infinity_context_core/application/context_query_entity_relation_expansions.py +212 -0
- infinity_context_core/application/context_query_event_summary_expansions.py +80 -0
- infinity_context_core/application/context_query_expansion.py +200 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part1.py +1279 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part2.py +770 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part3.py +982 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part4.py +1334 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part5.py +517 -0
- infinity_context_core/application/context_query_expansion_rule_terms.py +269 -0
- infinity_context_core/application/context_query_expansion_rules.py +66 -0
- infinity_context_core/application/context_query_expansion_selection.py +892 -0
- infinity_context_core/application/context_query_financial_resources_inference.py +92 -0
- infinity_context_core/application/context_query_food_expansions.py +89 -0
- infinity_context_core/application/context_query_frequency.py +194 -0
- infinity_context_core/application/context_query_game_expansions.py +141 -0
- infinity_context_core/application/context_query_health_lifestyle_expansions.py +178 -0
- infinity_context_core/application/context_query_identity_terms.py +81 -0
- infinity_context_core/application/context_query_intent.py +33 -0
- infinity_context_core/application/context_query_intent_common.py +29 -0
- infinity_context_core/application/context_query_intent_contracts.py +92 -0
- infinity_context_core/application/context_query_intent_extraction.py +614 -0
- infinity_context_core/application/context_query_intent_keys.py +499 -0
- infinity_context_core/application/context_query_intent_matching.py +407 -0
- infinity_context_core/application/context_query_organization_summary_expansions.py +75 -0
- infinity_context_core/application/context_query_personal_fact_expansions.py +314 -0
- infinity_context_core/application/context_query_pet_activity_expansions.py +329 -0
- infinity_context_core/application/context_query_preference_expansions.py +97 -0
- infinity_context_core/application/context_query_project_summary_expansions.py +60 -0
- infinity_context_core/application/context_query_relevance_ranking.py +76 -0
- infinity_context_core/application/context_query_sports_expansions.py +48 -0
- infinity_context_core/application/context_query_state_transition.py +53 -0
- infinity_context_core/application/context_query_support_role.py +165 -0
- infinity_context_core/application/context_query_temporal_expansions.py +18 -0
- infinity_context_core/application/context_query_travel_expansions.py +134 -0
- infinity_context_core/application/context_query_vehicle_expansions.py +79 -0
- infinity_context_core/application/context_query_workflow_expansions.py +233 -0
- infinity_context_core/application/context_query_workflow_intent.py +65 -0
- infinity_context_core/application/context_quote_scanner.py +342 -0
- infinity_context_core/application/context_rank_dedupe.py +171 -0
- infinity_context_core/application/context_rank_fusion.py +191 -0
- infinity_context_core/application/context_ranked_activity_reservation.py +586 -0
- infinity_context_core/application/context_ranked_evidence_coverage_reservation.py +427 -0
- infinity_context_core/application/context_ranked_evidence_priority_reservation.py +37 -0
- infinity_context_core/application/context_ranked_evidence_selection.py +260 -0
- infinity_context_core/application/context_ranking.py +3681 -0
- infinity_context_core/application/context_ranking_reason_policy.py +31 -0
- infinity_context_core/application/context_ranking_reason_priorities.py +859 -0
- infinity_context_core/application/context_ranking_reason_scores.py +519 -0
- infinity_context_core/application/context_recommendation_answer_support.py +358 -0
- infinity_context_core/application/context_recommendation_exact_turns.py +360 -0
- infinity_context_core/application/context_relation_requirement.py +498 -0
- infinity_context_core/application/context_relationship_status_evidence.py +83 -0
- infinity_context_core/application/context_relative_duration_evidence.py +61 -0
- infinity_context_core/application/context_relevance.py +430 -0
- infinity_context_core/application/context_reported_obligation_attribution.py +416 -0
- infinity_context_core/application/context_reporting_frames.py +338 -0
- infinity_context_core/application/context_requirement_coverage.py +767 -0
- infinity_context_core/application/context_requirement_guard.py +503 -0
- infinity_context_core/application/context_requirement_patterns.py +943 -0
- infinity_context_core/application/context_requirement_ranking.py +181 -0
- infinity_context_core/application/context_requirement_signals.py +101 -0
- infinity_context_core/application/context_rerank_domain_heuristics.py +433 -0
- infinity_context_core/application/context_rerank_evidence_signals.py +400 -0
- infinity_context_core/application/context_rerank_relevance.py +131 -0
- infinity_context_core/application/context_retrieval_performance.py +153 -0
- infinity_context_core/application/context_review_items.py +338 -0
- infinity_context_core/application/context_score_signal_rerank.py +21 -0
- infinity_context_core/application/context_short_story_progress_evidence.py +119 -0
- infinity_context_core/application/context_snippets.py +545 -0
- infinity_context_core/application/context_social_education_inference.py +265 -0
- infinity_context_core/application/context_social_inventory_rerank.py +329 -0
- infinity_context_core/application/context_source_family.py +100 -0
- infinity_context_core/application/context_source_grounding.py +277 -0
- infinity_context_core/application/context_source_sibling_answer_evidence_repair.py +1983 -0
- infinity_context_core/application/context_source_sibling_contracts.py +35 -0
- infinity_context_core/application/context_source_sibling_evidence.py +405 -0
- infinity_context_core/application/context_source_sibling_evidence_rules.py +798 -0
- infinity_context_core/application/context_source_sibling_evidence_shared.py +449 -0
- infinity_context_core/application/context_source_sibling_identity.py +114 -0
- infinity_context_core/application/context_source_sibling_inventory_evidence.py +28 -0
- infinity_context_core/application/context_source_sibling_patterns.py +946 -0
- infinity_context_core/application/context_source_sibling_place_evidence.py +561 -0
- infinity_context_core/application/context_source_sibling_policy.py +988 -0
- infinity_context_core/application/context_source_sibling_scoring.py +721 -0
- infinity_context_core/application/context_source_siblings.py +363 -0
- infinity_context_core/application/context_speaker_attribution.py +574 -0
- infinity_context_core/application/context_speaker_disambiguation.py +108 -0
- infinity_context_core/application/context_stage_diagnostics.py +111 -0
- infinity_context_core/application/context_state_evidence.py +196 -0
- infinity_context_core/application/context_state_residence_inference.py +163 -0
- infinity_context_core/application/context_state_transition_pairing.py +401 -0
- infinity_context_core/application/context_temporal_answer_grounding.py +187 -0
- infinity_context_core/application/context_temporal_hints.py +485 -0
- infinity_context_core/application/context_temporal_intent_policy.py +146 -0
- infinity_context_core/application/context_temporal_interval_requirements.py +107 -0
- infinity_context_core/application/context_temporal_metadata.py +29 -0
- infinity_context_core/application/context_temporal_query.py +1358 -0
- infinity_context_core/application/context_temporal_ranges.py +471 -0
- infinity_context_core/application/context_temporal_session_order.py +439 -0
- infinity_context_core/application/context_temporal_source_identity.py +426 -0
- infinity_context_core/application/context_temporal_source_turn.py +1290 -0
- infinity_context_core/application/context_temporal_source_turn_labels.py +265 -0
- infinity_context_core/application/context_temporal_source_turn_patterns.py +186 -0
- infinity_context_core/application/context_temporal_source_turn_types.py +62 -0
- infinity_context_core/application/context_travel_hobby_writing_evidence.py +176 -0
- infinity_context_core/application/context_travel_place_evidence.py +23 -0
- infinity_context_core/application/document_fragments.py +206 -0
- infinity_context_core/application/document_text.py +203 -0
- infinity_context_core/application/dto.py +311 -0
- infinity_context_core/application/dto_anchors.py +143 -0
- infinity_context_core/application/dto_assets.py +234 -0
- infinity_context_core/application/dto_benchmark_runs.py +114 -0
- infinity_context_core/application/dto_context.py +176 -0
- infinity_context_core/application/dto_context_links.py +170 -0
- infinity_context_core/application/dto_facts.py +275 -0
- infinity_context_core/application/dto_suggestions_capture.py +199 -0
- infinity_context_core/application/dto_workspace.py +101 -0
- infinity_context_core/application/extraction_coordinates.py +56 -0
- infinity_context_core/application/extraction_resource_policy.py +796 -0
- infinity_context_core/application/extractor.py +147 -0
- infinity_context_core/application/memory_digest_renderer.py +215 -0
- infinity_context_core/application/multimodal_manifest.py +418 -0
- infinity_context_core/application/normalize.py +29 -0
- infinity_context_core/application/observed_anchor_resolution.py +243 -0
- infinity_context_core/application/related_facts.py +144 -0
- infinity_context_core/application/review_payloads.py +104 -0
- infinity_context_core/application/safe_payload.py +86 -0
- infinity_context_core/application/semantic_dedupe.py +943 -0
- infinity_context_core/application/sensitive_text.py +39 -0
- infinity_context_core/application/source_refs.py +263 -0
- infinity_context_core/application/storage_key_safety.py +13 -0
- infinity_context_core/application/temporal_validity.py +31 -0
- infinity_context_core/application/use_cases/__init__.py +1 -0
- infinity_context_core/application/use_cases/anchors.py +1165 -0
- infinity_context_core/application/use_cases/asset_extraction_support.py +273 -0
- infinity_context_core/application/use_cases/asset_extractions.py +1454 -0
- infinity_context_core/application/use_cases/assets.py +463 -0
- infinity_context_core/application/use_cases/benchmark_runs.py +877 -0
- infinity_context_core/application/use_cases/benchmark_unsealed_abort.py +147 -0
- infinity_context_core/application/use_cases/blob_storage_cleanup.py +289 -0
- infinity_context_core/application/use_cases/blob_storage_integrity.py +351 -0
- infinity_context_core/application/use_cases/build_context.py +995 -0
- infinity_context_core/application/use_cases/build_context_final_packing.py +59 -0
- infinity_context_core/application/use_cases/build_context_item_projection.py +839 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation.py +908 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation_seeds.py +132 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation_selection.py +280 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation_support.py +161 -0
- infinity_context_core/application/use_cases/build_context_requirement_guard.py +156 -0
- infinity_context_core/application/use_cases/build_context_source_selection.py +935 -0
- infinity_context_core/application/use_cases/build_memory_digest.py +203 -0
- infinity_context_core/application/use_cases/build_memory_insights.py +979 -0
- infinity_context_core/application/use_cases/consolidate_capture.py +806 -0
- infinity_context_core/application/use_cases/context_link_crud.py +196 -0
- infinity_context_core/application/use_cases/context_link_reviews.py +441 -0
- infinity_context_core/application/use_cases/context_link_suggestions.py +1060 -0
- infinity_context_core/application/use_cases/context_link_visibility.py +106 -0
- infinity_context_core/application/use_cases/context_links.py +33 -0
- infinity_context_core/application/use_cases/delete_document.py +71 -0
- infinity_context_core/application/use_cases/delete_thread_memory.py +55 -0
- infinity_context_core/application/use_cases/duplicate_merge_resolution.py +307 -0
- infinity_context_core/application/use_cases/ensure_scope.py +29 -0
- infinity_context_core/application/use_cases/expire_suggestions.py +36 -0
- infinity_context_core/application/use_cases/export_graph.py +684 -0
- infinity_context_core/application/use_cases/fact_relations.py +204 -0
- infinity_context_core/application/use_cases/forget_fact.py +43 -0
- infinity_context_core/application/use_cases/get_capabilities.py +213 -0
- infinity_context_core/application/use_cases/get_capture.py +16 -0
- infinity_context_core/application/use_cases/get_session_status.py +23 -0
- infinity_context_core/application/use_cases/ingest_document.py +376 -0
- infinity_context_core/application/use_cases/ingest_episode.py +263 -0
- infinity_context_core/application/use_cases/list_captures.py +25 -0
- infinity_context_core/application/use_cases/memory_browser.py +414 -0
- infinity_context_core/application/use_cases/operations_console.py +293 -0
- infinity_context_core/application/use_cases/process_document.py +83 -0
- infinity_context_core/application/use_cases/purge_capture.py +34 -0
- infinity_context_core/application/use_cases/query_documents.py +42 -0
- infinity_context_core/application/use_cases/query_facts.py +57 -0
- infinity_context_core/application/use_cases/receive_capture.py +238 -0
- infinity_context_core/application/use_cases/related_facts.py +47 -0
- infinity_context_core/application/use_cases/remember_fact.py +145 -0
- infinity_context_core/application/use_cases/spaces_memory_scopes.py +134 -0
- infinity_context_core/application/use_cases/suggestions.py +804 -0
- infinity_context_core/application/use_cases/update_fact.py +43 -0
- infinity_context_core/application/use_cases/usage.py +49 -0
- infinity_context_core/application/use_cases/users.py +138 -0
- infinity_context_core/domain/__init__.py +1 -0
- infinity_context_core/domain/aggregation_admission.py +200 -0
- infinity_context_core/domain/anchor_entities.py +316 -0
- infinity_context_core/domain/assets.py +654 -0
- infinity_context_core/domain/capture.py +321 -0
- infinity_context_core/domain/distinct_set_membership.py +69 -0
- infinity_context_core/domain/entities.py +103 -0
- infinity_context_core/domain/entity_policies.py +119 -0
- infinity_context_core/domain/entity_types.py +150 -0
- infinity_context_core/domain/errors.py +53 -0
- infinity_context_core/domain/events.py +14 -0
- infinity_context_core/domain/extraction.py +529 -0
- infinity_context_core/domain/idempotency.py +12 -0
- infinity_context_core/domain/memory_item_entities.py +426 -0
- infinity_context_core/domain/source_refs.py +91 -0
- infinity_context_core/domain/suggestion_entities.py +236 -0
- infinity_context_core/domain/taxonomy.py +121 -0
- infinity_context_core/domain/usage.py +221 -0
- infinity_context_core/domain/workspace_entities.py +269 -0
- infinity_context_core/features/__init__.py +7 -0
- infinity_context_core/features/context_building/__init__.py +3 -0
- infinity_context_core/features/context_building/application/__init__.py +92 -0
- infinity_context_core/features/context_building/application/candidate_fusion.py +136 -0
- infinity_context_core/features/context_building/application/coverage_reservation_selector.py +212 -0
- infinity_context_core/features/context_building/application/handlers.py +155 -0
- infinity_context_core/features/context_building/application/inference_evidence_reservation.py +592 -0
- infinity_context_core/features/context_building/application/provider_pipeline.py +61 -0
- infinity_context_core/features/context_building/application/queries.py +107 -0
- infinity_context_core/features/context_building/application/use_cases.py +78 -0
- infinity_context_core/features/context_building/domain/__init__.py +95 -0
- infinity_context_core/features/context_building/domain/budget.py +97 -0
- infinity_context_core/features/context_building/domain/context.py +157 -0
- infinity_context_core/features/context_building/domain/evidence_obligations.py +60 -0
- infinity_context_core/features/context_building/domain/feature.py +15 -0
- infinity_context_core/features/context_building/domain/prompt_sections.py +150 -0
- infinity_context_core/features/context_building/domain/query_pipeline.py +276 -0
- infinity_context_core/features/context_building/domain/rendering.py +102 -0
- infinity_context_core/features/context_building/ports/__init__.py +8 -0
- infinity_context_core/features/context_building/ports/candidates.py +36 -0
- infinity_context_core/features/context_building/public.py +165 -0
- infinity_context_core/features/context_building/tests/test_application_ports_public_skeleton.py +575 -0
- infinity_context_core/features/context_building/tests/test_domain_context_building_skeleton.py +402 -0
- infinity_context_core/features/document_ingestion/__init__.py +3 -0
- infinity_context_core/features/document_ingestion/application/__init__.py +31 -0
- infinity_context_core/features/document_ingestion/application/commands.py +62 -0
- infinity_context_core/features/document_ingestion/application/use_cases.py +273 -0
- infinity_context_core/features/document_ingestion/domain/__init__.py +61 -0
- infinity_context_core/features/document_ingestion/domain/chunking.py +297 -0
- infinity_context_core/features/document_ingestion/domain/errors.py +22 -0
- infinity_context_core/features/document_ingestion/domain/feature.py +18 -0
- infinity_context_core/features/document_ingestion/domain/source_document.py +228 -0
- infinity_context_core/features/document_ingestion/ports/__init__.py +21 -0
- infinity_context_core/features/document_ingestion/ports/indexing.py +51 -0
- infinity_context_core/features/document_ingestion/ports/repositories.py +56 -0
- infinity_context_core/features/document_ingestion/public.py +95 -0
- infinity_context_core/features/document_ingestion/tests/test_application_handlers.py +226 -0
- infinity_context_core/features/document_ingestion/tests/test_application_ports_public_skeleton.py +334 -0
- infinity_context_core/features/document_ingestion/tests/test_domain_chunking_skeleton.py +79 -0
- infinity_context_core/features/document_ingestion/tests/test_domain_source_document_skeleton.py +101 -0
- infinity_context_core/features/memory_facts/__init__.py +3 -0
- infinity_context_core/features/memory_facts/application/__init__.py +37 -0
- infinity_context_core/features/memory_facts/application/commands.py +89 -0
- infinity_context_core/features/memory_facts/application/handlers.py +241 -0
- infinity_context_core/features/memory_facts/application/use_cases.py +47 -0
- infinity_context_core/features/memory_facts/domain/__init__.py +35 -0
- infinity_context_core/features/memory_facts/domain/fact.py +98 -0
- infinity_context_core/features/memory_facts/domain/feature.py +15 -0
- infinity_context_core/features/memory_facts/ports/__init__.py +31 -0
- infinity_context_core/features/memory_facts/ports/clock.py +14 -0
- infinity_context_core/features/memory_facts/ports/ids.py +19 -0
- infinity_context_core/features/memory_facts/ports/outbox.py +26 -0
- infinity_context_core/features/memory_facts/ports/repositories.py +30 -0
- infinity_context_core/features/memory_facts/ports/unit_of_work.py +43 -0
- infinity_context_core/features/memory_facts/public.py +79 -0
- infinity_context_core/features/memory_facts/tests/test_application_handlers.py +332 -0
- infinity_context_core/features/memory_facts/tests/test_application_ports_public_skeleton.py +318 -0
- infinity_context_core/features/memory_facts/tests/test_domain_fact_skeleton.py +222 -0
- infinity_context_core/features/memory_scopes/__init__.py +3 -0
- infinity_context_core/features/memory_scopes/application/__init__.py +55 -0
- infinity_context_core/features/memory_scopes/application/commands.py +102 -0
- infinity_context_core/features/memory_scopes/application/errors.py +27 -0
- infinity_context_core/features/memory_scopes/application/handlers.py +226 -0
- infinity_context_core/features/memory_scopes/application/use_cases.py +68 -0
- infinity_context_core/features/memory_scopes/domain/__init__.py +59 -0
- infinity_context_core/features/memory_scopes/domain/errors.py +22 -0
- infinity_context_core/features/memory_scopes/domain/feature.py +18 -0
- infinity_context_core/features/memory_scopes/domain/policies.py +197 -0
- infinity_context_core/features/memory_scopes/domain/scope.py +178 -0
- infinity_context_core/features/memory_scopes/ports/__init__.py +25 -0
- infinity_context_core/features/memory_scopes/ports/clock.py +14 -0
- infinity_context_core/features/memory_scopes/ports/ids.py +13 -0
- infinity_context_core/features/memory_scopes/ports/repositories.py +40 -0
- infinity_context_core/features/memory_scopes/ports/unit_of_work.py +39 -0
- infinity_context_core/features/memory_scopes/public.py +111 -0
- infinity_context_core/features/memory_scopes/tests/test_application_ports_public_skeleton.py +824 -0
- infinity_context_core/features/memory_scopes/tests/test_domain_scope_skeleton.py +428 -0
- infinity_context_core/memory_scope_snapshot_preview.py +863 -0
- infinity_context_core/memory_scope_snapshots.py +206 -0
- infinity_context_core/ports/__init__.py +164 -0
- infinity_context_core/ports/adapters.py +217 -0
- infinity_context_core/ports/assets.py +270 -0
- infinity_context_core/ports/auth.py +68 -0
- infinity_context_core/ports/auto_memory.py +71 -0
- infinity_context_core/ports/benchmark_runs.py +205 -0
- infinity_context_core/ports/capabilities.py +324 -0
- infinity_context_core/ports/captures.py +53 -0
- infinity_context_core/ports/clock.py +11 -0
- infinity_context_core/ports/derived_projection_policy.py +72 -0
- infinity_context_core/ports/extraction.py +201 -0
- infinity_context_core/ports/graph_evidence.py +170 -0
- infinity_context_core/ports/ids.py +11 -0
- infinity_context_core/ports/projection_fence.py +27 -0
- infinity_context_core/ports/repositories.py +563 -0
- infinity_context_core/ports/transcription.py +63 -0
- infinity_context_core/ports/unit_of_work.py +77 -0
- infinity_context_core/ports/usage.py +36 -0
- infinity_context_core/ports/vector_projection_evidence.py +230 -0
- infinity_context_core/ports/vision.py +36 -0
- infinity_context_core/processes/__init__.py +3 -0
- infinity_context_core/processes/document_memory_pipeline/__init__.py +3 -0
- infinity_context_core/processes/document_memory_pipeline/contracts.py +44 -0
- infinity_context_core/processes/document_memory_pipeline/process.py +72 -0
- infinity_context_core/processes/document_memory_pipeline/public.py +21 -0
- infinity_context_core/reporting.py +105 -0
- infinity_context_mcp/__init__.py +5 -0
- infinity_context_mcp/__main__.py +6 -0
- infinity_context_mcp/adapters/__init__.py +1 -0
- infinity_context_mcp/adapters/http_gateway.py +940 -0
- infinity_context_mcp/agent_behavior_bench.py +1731 -0
- infinity_context_mcp/agent_behavior_bench_metrics.py +419 -0
- infinity_context_mcp/agent_behavior_bench_redaction.py +149 -0
- infinity_context_mcp/agent_behavior_bench_types.py +127 -0
- infinity_context_mcp/agent_behavior_scenarios.py +35 -0
- infinity_context_mcp/agent_behavior_scenarios_core.py +484 -0
- infinity_context_mcp/agent_behavior_scenarios_realistic.py +473 -0
- infinity_context_mcp/agent_behavior_scenarios_transcript.py +196 -0
- infinity_context_mcp/agent_behavior_transcripts.py +231 -0
- infinity_context_mcp/agent_behavior_types.py +66 -0
- infinity_context_mcp/agent_behavior_utils.py +29 -0
- infinity_context_mcp/application/__init__.py +1 -0
- infinity_context_mcp/application/context_link_review.py +109 -0
- infinity_context_mcp/application/local_runtime.py +473 -0
- infinity_context_mcp/application/normalization.py +36 -0
- infinity_context_mcp/application/obsidian.py +568 -0
- infinity_context_mcp/application/policy.py +160 -0
- infinity_context_mcp/application/ports.py +324 -0
- infinity_context_mcp/application/prepare.py +254 -0
- infinity_context_mcp/application/readiness.py +71 -0
- infinity_context_mcp/application/review_batch.py +62 -0
- infinity_context_mcp/application/service.py +701 -0
- infinity_context_mcp/application/service_base.py +29 -0
- infinity_context_mcp/application/service_constants.py +89 -0
- infinity_context_mcp/application/service_context_links.py +224 -0
- infinity_context_mcp/application/service_duplicates.py +62 -0
- infinity_context_mcp/application/service_facts.py +461 -0
- infinity_context_mcp/application/service_helpers.py +179 -0
- infinity_context_mcp/application/service_lifecycle.py +348 -0
- infinity_context_mcp/application/service_policy.py +74 -0
- infinity_context_mcp/application/service_query.py +384 -0
- infinity_context_mcp/application/service_resources.py +192 -0
- infinity_context_mcp/application/service_response.py +95 -0
- infinity_context_mcp/application/service_scope.py +132 -0
- infinity_context_mcp/application/service_suggestions.py +820 -0
- infinity_context_mcp/application/suggest_batch.py +71 -0
- infinity_context_mcp/application/usage_guide.py +74 -0
- infinity_context_mcp/bench.py +279 -0
- infinity_context_mcp/config.py +213 -0
- infinity_context_mcp/domain/__init__.py +1 -0
- infinity_context_mcp/domain/context_links.py +117 -0
- infinity_context_mcp/domain/local_runtime_models.py +56 -0
- infinity_context_mcp/domain/memory_browser.py +35 -0
- infinity_context_mcp/domain/models.py +1036 -0
- infinity_context_mcp/domain/obsidian_models.py +67 -0
- infinity_context_mcp/domain/policy.py +112 -0
- infinity_context_mcp/domain/prepare_models.py +24 -0
- infinity_context_mcp/plugin_hook.py +873 -0
- infinity_context_mcp/plugin_hook_settings.py +253 -0
- infinity_context_mcp/server.py +133 -0
- infinity_context_mcp/server_context_tools.py +404 -0
- infinity_context_mcp/server_fact_tools.py +928 -0
- infinity_context_mcp/server_hardening.py +54 -0
- infinity_context_mcp/server_local_runtime_tools.py +164 -0
- infinity_context_mcp/server_obsidian_tools.py +380 -0
- infinity_context_mcp/server_query_tools.py +626 -0
- infinity_context_mcp/server_request_mapping.py +73 -0
- infinity_context_mcp/server_resources.py +187 -0
- infinity_context_mcp/server_response.py +26 -0
- infinity_context_obsidian/__init__.py +5 -0
- infinity_context_obsidian/cli.py +594 -0
- infinity_context_obsidian/conflicts.py +110 -0
- infinity_context_obsidian/doctor.py +319 -0
- infinity_context_obsidian/domain.py +92 -0
- infinity_context_obsidian/frontmatter.py +68 -0
- infinity_context_obsidian/gateway.py +66 -0
- infinity_context_obsidian/layout.py +179 -0
- infinity_context_obsidian/note_format.py +159 -0
- infinity_context_obsidian/plugin_bundle/__init__.py +1 -0
- infinity_context_obsidian/plugin_bundle/main.js +5 -0
- infinity_context_obsidian/plugin_bundle/manifest.json +10 -0
- infinity_context_obsidian/plugin_bundle/styles.css +123 -0
- infinity_context_obsidian/plugin_install.py +139 -0
- infinity_context_obsidian/ports.py +72 -0
- infinity_context_obsidian/setup.py +202 -0
- infinity_context_obsidian/state.py +85 -0
- infinity_context_obsidian/sync.py +741 -0
- infinity_context_obsidian/vault.py +61 -0
- infinity_context_sdk/__init__.py +1049 -0
- infinity_context_sdk/_payloads.py +401 -0
- infinity_context_sdk/_redaction.py +31 -0
- infinity_context_sdk/anchors.py +249 -0
- infinity_context_sdk/assets.py +554 -0
- infinity_context_sdk/capabilities.py +199 -0
- infinity_context_sdk/context.py +540 -0
- infinity_context_sdk/context_bundle_diagnostics.py +905 -0
- infinity_context_sdk/context_payload_utils.py +219 -0
- infinity_context_sdk/export.py +123 -0
- infinity_context_sdk/scopes.py +74 -0
- infinity_context_sdk/thread_memory.py +55 -0
- infinity_context_server/__init__.py +5 -0
- infinity_context_server/__main__.py +19 -0
- infinity_context_server/admin.py +832 -0
- infinity_context_server/admin_invariants.py +388 -0
- infinity_context_server/admin_outbox.py +130 -0
- infinity_context_server/admin_projection_repair.py +374 -0
- infinity_context_server/api/__init__.py +1 -0
- infinity_context_server/api/auth.py +432 -0
- infinity_context_server/api/dependencies.py +9 -0
- infinity_context_server/api/errors.py +94 -0
- infinity_context_server/api/legacy_client.py +356 -0
- infinity_context_server/api/policy.py +35 -0
- infinity_context_server/api/public_payload.py +27 -0
- infinity_context_server/api/v1/__init__.py +54 -0
- infinity_context_server/api/v1/anchors.py +469 -0
- infinity_context_server/api/v1/assets.py +409 -0
- infinity_context_server/api/v1/capabilities.py +144 -0
- infinity_context_server/api/v1/captures.py +329 -0
- infinity_context_server/api/v1/context.py +362 -0
- infinity_context_server/api/v1/context_links.py +611 -0
- infinity_context_server/api/v1/diagnostics.py +333 -0
- infinity_context_server/api/v1/digest.py +107 -0
- infinity_context_server/api/v1/documents.py +164 -0
- infinity_context_server/api/v1/episodes.py +146 -0
- infinity_context_server/api/v1/export.py +184 -0
- infinity_context_server/api/v1/facts.py +265 -0
- infinity_context_server/api/v1/health.py +24 -0
- infinity_context_server/api/v1/insights.py +100 -0
- infinity_context_server/api/v1/internal_memory_comparison_runs.py +406 -0
- infinity_context_server/api/v1/memory_browser.py +183 -0
- infinity_context_server/api/v1/operations.py +81 -0
- infinity_context_server/api/v1/scope_resolution.py +389 -0
- infinity_context_server/api/v1/source_refs.py +111 -0
- infinity_context_server/api/v1/spaces_memory_scopes.py +141 -0
- infinity_context_server/api/v1/suggestions.py +237 -0
- infinity_context_server/api/v1/thread_memory.py +74 -0
- infinity_context_server/api/v1/usage.py +75 -0
- infinity_context_server/api/v1/users.py +164 -0
- infinity_context_server/auth_scope.py +492 -0
- infinity_context_server/auth_tokens.py +283 -0
- infinity_context_server/backpressure.py +47 -0
- infinity_context_server/benchmark_projection_absence.py +155 -0
- infinity_context_server/benchmark_projection_delete_outbox.py +162 -0
- infinity_context_server/composition.py +897 -0
- infinity_context_server/config.py +223 -0
- infinity_context_server/db.py +39 -0
- infinity_context_server/deployment_readiness.py +205 -0
- infinity_context_server/derived_identity_evidence.py +987 -0
- infinity_context_server/derived_identity_target.py +39 -0
- infinity_context_server/derived_projection_policy.py +85 -0
- infinity_context_server/diagnostics.py +536 -0
- infinity_context_server/doctor.py +71 -0
- infinity_context_server/eval.py +3066 -0
- infinity_context_server/eval_auto_memory.py +1735 -0
- infinity_context_server/eval_auto_memory_metrics.py +224 -0
- infinity_context_server/eval_auto_memory_types.py +75 -0
- infinity_context_server/eval_case_catalog.py +1590 -0
- infinity_context_server/eval_case_runner.py +1100 -0
- infinity_context_server/eval_common.py +336 -0
- infinity_context_server/eval_constants.py +310 -0
- infinity_context_server/eval_fixtures.py +150 -0
- infinity_context_server/eval_graph.py +92 -0
- infinity_context_server/eval_hybrid.py +99 -0
- infinity_context_server/eval_multimodal_offline.py +697 -0
- infinity_context_server/eval_prompt_contract.py +402 -0
- infinity_context_server/eval_scorecard.py +2627 -0
- infinity_context_server/eval_semantic_linking.py +1526 -0
- infinity_context_server/eval_semantic_retrieval_api_canary.py +405 -0
- infinity_context_server/eval_semantic_retrieval_canary.py +359 -0
- infinity_context_server/eval_types.py +88 -0
- infinity_context_server/evidence_bundle.py +523 -0
- infinity_context_server/extraction_capabilities.py +1234 -0
- infinity_context_server/features/__init__.py +3 -0
- infinity_context_server/features/context_building/__init__.py +5 -0
- infinity_context_server/features/context_building/benchmark_budget.py +29 -0
- infinity_context_server/features/context_building/composition.py +49 -0
- infinity_context_server/features/context_building/context_requests.py +151 -0
- infinity_context_server/features/context_building/contracts.py +96 -0
- infinity_context_server/features/context_building/digest_api_responses.py +225 -0
- infinity_context_server/features/context_building/digest_requests.py +65 -0
- infinity_context_server/features/context_building/insights_api_responses.py +132 -0
- infinity_context_server/features/context_building/legacy_api_responses.py +875 -0
- infinity_context_server/features/context_building/mappers.py +205 -0
- infinity_context_server/features/context_building/public.py +66 -0
- infinity_context_server/features/context_building/routes.py +44 -0
- infinity_context_server/features/document_ingestion/__init__.py +5 -0
- infinity_context_server/features/document_ingestion/asset_requests.py +45 -0
- infinity_context_server/features/document_ingestion/asset_responses.py +365 -0
- infinity_context_server/features/document_ingestion/composition.py +49 -0
- infinity_context_server/features/document_ingestion/contracts.py +104 -0
- infinity_context_server/features/document_ingestion/mappers.py +386 -0
- infinity_context_server/features/document_ingestion/public.py +58 -0
- infinity_context_server/features/document_ingestion/routes.py +44 -0
- infinity_context_server/features/memory_facts/__init__.py +7 -0
- infinity_context_server/features/memory_facts/compatibility.py +204 -0
- infinity_context_server/features/memory_facts/composition.py +72 -0
- infinity_context_server/features/memory_facts/contracts.py +187 -0
- infinity_context_server/features/memory_facts/mappers.py +620 -0
- infinity_context_server/features/memory_facts/public.py +168 -0
- infinity_context_server/features/memory_facts/routes.py +118 -0
- infinity_context_server/features/memory_facts/suggestion_requests.py +283 -0
- infinity_context_server/features/memory_facts/suggestion_responses.py +382 -0
- infinity_context_server/features/memory_scopes/__init__.py +5 -0
- infinity_context_server/features/memory_scopes/compatibility.py +231 -0
- infinity_context_server/features/memory_scopes/composition.py +49 -0
- infinity_context_server/features/memory_scopes/contracts.py +103 -0
- infinity_context_server/features/memory_scopes/graph_export_responses.py +93 -0
- infinity_context_server/features/memory_scopes/mappers.py +290 -0
- infinity_context_server/features/memory_scopes/public.py +136 -0
- infinity_context_server/features/memory_scopes/routes.py +185 -0
- infinity_context_server/features/memory_scopes/snapshot_compatibility.py +146 -0
- infinity_context_server/features/memory_scopes/thread_memory_requests.py +127 -0
- infinity_context_server/llm_provider_readiness.py +267 -0
- infinity_context_server/longmemeval_session_identity.py +167 -0
- infinity_context_server/main.py +68 -0
- infinity_context_server/mem0_benchmark_auth_challenge.py +160 -0
- infinity_context_server/memora_comparison.py +658 -0
- infinity_context_server/memory_comparison_answer_context.py +2442 -0
- infinity_context_server/memory_comparison_answer_context_backfill.py +1027 -0
- infinity_context_server/memory_comparison_answer_context_diagnostics.py +694 -0
- infinity_context_server/memory_comparison_answer_context_inspection.py +103 -0
- infinity_context_server/memory_comparison_answer_context_retrieval_slice.py +175 -0
- infinity_context_server/memory_comparison_answer_context_risks.py +223 -0
- infinity_context_server/memory_comparison_backend_target.py +41 -0
- infinity_context_server/memory_comparison_benchmark.py +651 -0
- infinity_context_server/memory_comparison_benchmark_compact.py +387 -0
- infinity_context_server/memory_comparison_benchmark_compact_fast_gate.py +387 -0
- infinity_context_server/memory_comparison_benchmark_compact_samples.py +931 -0
- infinity_context_server/memory_comparison_benchmark_config.py +105 -0
- infinity_context_server/memory_comparison_benchmark_control.py +215 -0
- infinity_context_server/memory_comparison_benchmark_execution.py +238 -0
- infinity_context_server/memory_comparison_benchmark_identity.py +65 -0
- infinity_context_server/memory_comparison_benchmark_metrics.py +686 -0
- infinity_context_server/memory_comparison_benchmark_replay.py +400 -0
- infinity_context_server/memory_comparison_benchmark_shared.py +284 -0
- infinity_context_server/memory_comparison_bounded_provider.py +295 -0
- infinity_context_server/memory_comparison_bundle_partial_support.py +107 -0
- infinity_context_server/memory_comparison_bundle_planner.py +3521 -0
- infinity_context_server/memory_comparison_bundle_source_windows.py +247 -0
- infinity_context_server/memory_comparison_candidate_features.py +2014 -0
- infinity_context_server/memory_comparison_candidate_fusion.py +893 -0
- infinity_context_server/memory_comparison_candidate_risks.py +124 -0
- infinity_context_server/memory_comparison_canonical_source_hash.py +109 -0
- infinity_context_server/memory_comparison_case_identity.py +100 -0
- infinity_context_server/memory_comparison_case_loader.py +123 -0
- infinity_context_server/memory_comparison_chat_completions.py +402 -0
- infinity_context_server/memory_comparison_clean_state.py +607 -0
- infinity_context_server/memory_comparison_clean_state_http.py +120 -0
- infinity_context_server/memory_comparison_clean_state_runner.py +103 -0
- infinity_context_server/memory_comparison_cli.py +295 -0
- infinity_context_server/memory_comparison_codex_canary.py +315 -0
- infinity_context_server/memory_comparison_codex_llm.py +345 -0
- infinity_context_server/memory_comparison_compact_gap_report.py +289 -0
- infinity_context_server/memory_comparison_comparative_preference.py +71 -0
- infinity_context_server/memory_comparison_conversation_ingestion.py +198 -0
- infinity_context_server/memory_comparison_evidence.py +877 -0
- infinity_context_server/memory_comparison_evidence_commitment.py +20 -0
- infinity_context_server/memory_comparison_failure_diagnostics.py +809 -0
- infinity_context_server/memory_comparison_full_canonical_evidence.py +746 -0
- infinity_context_server/memory_comparison_full_canonical_source_evidence_trust.py +450 -0
- infinity_context_server/memory_comparison_full_delete_evidence.py +670 -0
- infinity_context_server/memory_comparison_full_delete_evidence_trust.py +441 -0
- infinity_context_server/memory_comparison_full_delete_evidence_witnesses.py +308 -0
- infinity_context_server/memory_comparison_full_execution_validation.py +697 -0
- infinity_context_server/memory_comparison_full_execution_validation_slots.py +655 -0
- infinity_context_server/memory_comparison_full_methodology.py +556 -0
- infinity_context_server/memory_comparison_full_policy_component_validation.py +899 -0
- infinity_context_server/memory_comparison_full_profiles.py +398 -0
- infinity_context_server/memory_comparison_full_run_component_sets.py +304 -0
- infinity_context_server/memory_comparison_full_run_components.py +787 -0
- infinity_context_server/memory_comparison_full_run_evidence.py +759 -0
- infinity_context_server/memory_comparison_full_scope.py +244 -0
- infinity_context_server/memory_comparison_full_source_evidence.py +866 -0
- infinity_context_server/memory_comparison_full_verdict.py +252 -0
- infinity_context_server/memory_comparison_gold_blind.py +654 -0
- infinity_context_server/memory_comparison_gold_blind_answer_contract.py +492 -0
- infinity_context_server/memory_comparison_gold_blind_contract.py +760 -0
- infinity_context_server/memory_comparison_gold_blind_dispatch_models.py +34 -0
- infinity_context_server/memory_comparison_gold_blind_execution_validation.py +170 -0
- infinity_context_server/memory_comparison_gold_blind_judge_binding.py +167 -0
- infinity_context_server/memory_comparison_gold_blind_judge_capability.py +387 -0
- infinity_context_server/memory_comparison_gold_blind_retrieval_contract.py +413 -0
- infinity_context_server/memory_comparison_gold_blind_run_proof.py +880 -0
- infinity_context_server/memory_comparison_gold_blind_run_validation.py +109 -0
- infinity_context_server/memory_comparison_gold_blind_validation.py +319 -0
- infinity_context_server/memory_comparison_http.py +921 -0
- infinity_context_server/memory_comparison_http_ingest_observation.py +710 -0
- infinity_context_server/memory_comparison_http_ingest_request.py +204 -0
- infinity_context_server/memory_comparison_intent.py +2925 -0
- infinity_context_server/memory_comparison_latency.py +455 -0
- infinity_context_server/memory_comparison_llm.py +473 -0
- infinity_context_server/memory_comparison_location_roles.py +169 -0
- infinity_context_server/memory_comparison_locomo_cases.py +328 -0
- infinity_context_server/memory_comparison_locomo_expected_turn.py +297 -0
- infinity_context_server/memory_comparison_locomo_transport.py +873 -0
- infinity_context_server/memory_comparison_longmemeval_cases.py +339 -0
- infinity_context_server/memory_comparison_managed_attestation.py +771 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_abort_http.py +120 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_contracts.py +715 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_http.py +855 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_recovery_http.py +164 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_wire.py +890 -0
- infinity_context_server/memory_comparison_managed_composite_assembler.py +524 -0
- infinity_context_server/memory_comparison_managed_corpus_projection.py +653 -0
- infinity_context_server/memory_comparison_managed_execution_receipts.py +991 -0
- infinity_context_server/memory_comparison_managed_http_derived_evidence.py +724 -0
- infinity_context_server/memory_comparison_managed_http_exact_cleanup.py +476 -0
- infinity_context_server/memory_comparison_managed_http_execution.py +673 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle.py +905 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle_credentials.py +83 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle_evidence.py +366 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle_registration.py +106 -0
- infinity_context_server/memory_comparison_managed_http_policy_lifecycle.py +894 -0
- infinity_context_server/memory_comparison_managed_http_policy_material_projection.py +315 -0
- infinity_context_server/memory_comparison_managed_http_policy_receipts.py +219 -0
- infinity_context_server/memory_comparison_managed_http_policy_registry_evidence.py +177 -0
- infinity_context_server/memory_comparison_managed_http_policy_requirements.py +824 -0
- infinity_context_server/memory_comparison_managed_http_policy_support.py +108 -0
- infinity_context_server/memory_comparison_managed_http_policy_validation.py +762 -0
- infinity_context_server/memory_comparison_managed_ingest_manifest.py +449 -0
- infinity_context_server/memory_comparison_managed_live_admission.py +886 -0
- infinity_context_server/memory_comparison_managed_live_cli.py +536 -0
- infinity_context_server/memory_comparison_managed_live_composition.py +636 -0
- infinity_context_server/memory_comparison_managed_llm_execution.py +850 -0
- infinity_context_server/memory_comparison_managed_llm_execution_dispatch.py +269 -0
- infinity_context_server/memory_comparison_managed_llm_execution_ports.py +225 -0
- infinity_context_server/memory_comparison_managed_mem0_auth.py +65 -0
- infinity_context_server/memory_comparison_managed_mem0_runtime_authority.py +241 -0
- infinity_context_server/memory_comparison_managed_mem0_runtime_http.py +541 -0
- infinity_context_server/memory_comparison_managed_plan_builder.py +685 -0
- infinity_context_server/memory_comparison_managed_preflight.py +907 -0
- infinity_context_server/memory_comparison_managed_preflight_cli.py +431 -0
- infinity_context_server/memory_comparison_managed_production_cli.py +325 -0
- infinity_context_server/memory_comparison_managed_production_composition.py +140 -0
- infinity_context_server/memory_comparison_managed_production_ports.py +194 -0
- infinity_context_server/memory_comparison_managed_production_runner.py +450 -0
- infinity_context_server/memory_comparison_managed_projection_manifest.py +438 -0
- infinity_context_server/memory_comparison_managed_provider_calls.py +450 -0
- infinity_context_server/memory_comparison_managed_quality_projection.py +347 -0
- infinity_context_server/memory_comparison_managed_registry_policy_lifecycle.py +677 -0
- infinity_context_server/memory_comparison_managed_run.py +892 -0
- infinity_context_server/memory_comparison_managed_run_contract.py +454 -0
- infinity_context_server/memory_comparison_managed_run_ports.py +79 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials.py +916 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_capability.py +361 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_context.py +132 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_integrity.py +213 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_models.py +81 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_targets.py +28 -0
- infinity_context_server/memory_comparison_mem0_contract.py +491 -0
- infinity_context_server/memory_comparison_mem0_http_observation.py +296 -0
- infinity_context_server/memory_comparison_mem0_locomo_prompts.py +328 -0
- infinity_context_server/memory_comparison_mem0_longmemeval_prompts.py +365 -0
- infinity_context_server/memory_comparison_mem0_official_chat.py +504 -0
- infinity_context_server/memory_comparison_mem0_official_prompt_renderer.py +307 -0
- infinity_context_server/memory_comparison_mem0_oss_contract.py +456 -0
- infinity_context_server/memory_comparison_mem0_oss_manifest.py +563 -0
- infinity_context_server/memory_comparison_mem0_platform_contract.py +467 -0
- infinity_context_server/memory_comparison_mem0_runtime_attestation.py +861 -0
- infinity_context_server/memory_comparison_models.py +398 -0
- infinity_context_server/memory_comparison_openai_official_transport.py +525 -0
- infinity_context_server/memory_comparison_preflight.py +1147 -0
- infinity_context_server/memory_comparison_probe_transport.py +154 -0
- infinity_context_server/memory_comparison_prompt_policy.py +603 -0
- infinity_context_server/memory_comparison_provider_provenance.py +392 -0
- infinity_context_server/memory_comparison_quality_accessors.py +339 -0
- infinity_context_server/memory_comparison_quality_actionable_gaps.py +2038 -0
- infinity_context_server/memory_comparison_quality_answer_context_gaps.py +450 -0
- infinity_context_server/memory_comparison_quality_answer_context_risks.py +75 -0
- infinity_context_server/memory_comparison_quality_bundle_gaps.py +860 -0
- infinity_context_server/memory_comparison_quality_bundle_table.py +805 -0
- infinity_context_server/memory_comparison_quality_diagnostics.py +2798 -0
- infinity_context_server/memory_comparison_quality_fusion.py +241 -0
- infinity_context_server/memory_comparison_quality_query_plan_gaps.py +533 -0
- infinity_context_server/memory_comparison_quality_query_role_gaps.py +845 -0
- infinity_context_server/memory_comparison_quality_query_roles.py +815 -0
- infinity_context_server/memory_comparison_quality_rerank_gaps.py +492 -0
- infinity_context_server/memory_comparison_quality_selected_weakness.py +544 -0
- infinity_context_server/memory_comparison_quality_support.py +921 -0
- infinity_context_server/memory_comparison_query_integrity.py +301 -0
- infinity_context_server/memory_comparison_query_plan.py +524 -0
- infinity_context_server/memory_comparison_query_terms.py +2055 -0
- infinity_context_server/memory_comparison_relation_support.py +2100 -0
- infinity_context_server/memory_comparison_rerank.py +3209 -0
- infinity_context_server/memory_comparison_rerank_intents.py +405 -0
- infinity_context_server/memory_comparison_rerank_policies.py +1726 -0
- infinity_context_server/memory_comparison_rerank_policy.py +675 -0
- infinity_context_server/memory_comparison_rerank_shapes.py +152 -0
- infinity_context_server/memory_comparison_rerank_terms.py +973 -0
- infinity_context_server/memory_comparison_rerank_text.py +722 -0
- infinity_context_server/memory_comparison_retrieval_policy.py +108 -0
- infinity_context_server/memory_comparison_retrieval_width.py +383 -0
- infinity_context_server/memory_comparison_service_probe.py +278 -0
- infinity_context_server/memory_comparison_service_probes.py +547 -0
- infinity_context_server/memory_comparison_session_identity_contract.py +328 -0
- infinity_context_server/memory_comparison_source_identity.py +1655 -0
- infinity_context_server/memory_comparison_subscription_chat.py +717 -0
- infinity_context_server/memory_comparison_subscription_live_probe.py +323 -0
- infinity_context_server/memory_comparison_subscription_probe.py +368 -0
- infinity_context_server/memory_comparison_target_identity.py +42 -0
- infinity_context_server/memory_comparison_temporal_grounding.py +771 -0
- infinity_context_server/memory_comparison_token_budget_contract.py +665 -0
- infinity_context_server/memory_comparison_token_latency.py +136 -0
- infinity_context_server/memory_scope_transfer.py +933 -0
- infinity_context_server/memory_scope_transfer_assets.py +181 -0
- infinity_context_server/memory_scope_transfer_conflicts.py +565 -0
- infinity_context_server/memory_scope_transfer_context.py +295 -0
- infinity_context_server/memory_scope_transfer_extractions.py +390 -0
- infinity_context_server/memory_scope_transfer_facts.py +65 -0
- infinity_context_server/memory_scope_transfer_records.py +630 -0
- infinity_context_server/memory_scope_transfer_relations.py +84 -0
- infinity_context_server/memory_scope_transfer_remap.py +710 -0
- infinity_context_server/memory_scope_transfer_scope.py +267 -0
- infinity_context_server/memory_scope_transfer_support.py +108 -0
- infinity_context_server/memory_scope_transfer_temporal.py +24 -0
- infinity_context_server/metrics.py +264 -0
- infinity_context_server/official_public_benchmark.py +979 -0
- infinity_context_server/pagination.py +60 -0
- infinity_context_server/processes/__init__.py +38 -0
- infinity_context_server/processes/extractions.py +40 -0
- infinity_context_server/processes/outbox.py +47 -0
- infinity_context_server/processes/projections.py +372 -0
- infinity_context_server/provider_budget.py +59 -0
- infinity_context_server/provider_circuit.py +333 -0
- infinity_context_server/public_benchmark.py +2532 -0
- infinity_context_server/public_benchmark_artifacts.py +91 -0
- infinity_context_server/public_benchmark_case_diagnostics.py +231 -0
- infinity_context_server/public_benchmark_checkpoint.py +751 -0
- infinity_context_server/public_benchmark_environment.py +102 -0
- infinity_context_server/public_benchmark_execution.py +445 -0
- infinity_context_server/public_benchmark_http.py +39 -0
- infinity_context_server/public_benchmark_manifest.py +129 -0
- infinity_context_server/public_benchmark_metrics.py +645 -0
- infinity_context_server/public_benchmark_metrics_policy.py +117 -0
- infinity_context_server/public_benchmark_models.py +112 -0
- infinity_context_server/public_benchmark_progress.py +224 -0
- infinity_context_server/public_benchmark_results.py +76 -0
- infinity_context_server/public_benchmark_run_diagnostics.py +163 -0
- infinity_context_server/public_benchmark_selection.py +379 -0
- infinity_context_server/public_benchmark_transport.py +62 -0
- infinity_context_server/public_benchmark_unsupported.py +228 -0
- infinity_context_server/ranked_evidence_answer_support.py +665 -0
- infinity_context_server/ranked_evidence_document_seed_contract.py +30 -0
- infinity_context_server/ranked_evidence_evaluator_helpers.py +135 -0
- infinity_context_server/ranked_evidence_retrieval_request.py +36 -0
- infinity_context_server/ranked_evidence_seed_case.py +109 -0
- infinity_context_server/ranked_evidence_semantic_gate.py +980 -0
- infinity_context_server/ranked_evidence_semantic_gate_cli.py +137 -0
- infinity_context_server/ranked_evidence_semantic_gate_decision.py +163 -0
- infinity_context_server/ranked_evidence_semantic_metrics.py +375 -0
- infinity_context_server/ranked_evidence_session_identity.py +100 -0
- infinity_context_server/storage_maintenance.py +187 -0
- infinity_context_server/top_evidence_dataset_profile.py +442 -0
- infinity_context_server/top_evidence_policy.py +274 -0
- infinity_context_server/top_evidence_preflight.py +693 -0
- infinity_context_server/web/assets/memory-browser-capture.js +252 -0
- infinity_context_server/web/assets/memory-browser-operations.js +143 -0
- infinity_context_server/web/assets/memory-browser-review.js +687 -0
- infinity_context_server/web/assets/memory-browser.css +854 -0
- infinity_context_server/web/assets/memory-browser.js +3299 -0
- infinity_context_server/web/index.html +261 -0
- infinity_context_server/web_ui.py +29 -0
- infinity_context_server/worker.py +380 -0
|
@@ -0,0 +1,3101 @@
|
|
|
1
|
+
"""Answer-support policy helpers for context packing."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from infinity_context_core.application.context_diagnostics import (
|
|
8
|
+
context_rank_key,
|
|
9
|
+
diagnostic_retrieval_sources,
|
|
10
|
+
)
|
|
11
|
+
from infinity_context_core.application.context_food_inventory_exact_turns import (
|
|
12
|
+
food_inventory_answer_support_applies,
|
|
13
|
+
food_inventory_answer_support_rank,
|
|
14
|
+
food_inventory_role_alignment_rank,
|
|
15
|
+
)
|
|
16
|
+
from infinity_context_core.application.context_item_purchase_evidence import (
|
|
17
|
+
has_item_purchase_object_evidence,
|
|
18
|
+
)
|
|
19
|
+
from infinity_context_core.application.context_packer_answer_support_patterns import (
|
|
20
|
+
_ACTIVITY_CONTEXT_RE,
|
|
21
|
+
_ACTIVITY_DIRECT_PARTICIPATION_RE,
|
|
22
|
+
_ANIMAL_CARE_DIRECT_INSTRUCTION_RE,
|
|
23
|
+
_ANIMAL_CARE_GENERIC_HABITAT_RE,
|
|
24
|
+
_ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_REASONS,
|
|
25
|
+
_ANSWER_SUPPORT_EXCLUDED_QUERY_REASONS,
|
|
26
|
+
_BIRDWATCHING_CITY_SCHEDULE_CONTENT_RE,
|
|
27
|
+
_BOOK_SUGGESTION_DIRECT_RE,
|
|
28
|
+
_BROAD_EVIDENCE_ANSWER_SUPPORT_REASONS,
|
|
29
|
+
_BUSINESS_DIRECT_JOB_LOSS_RE,
|
|
30
|
+
_BUSINESS_DIRECT_START_REASON_RE,
|
|
31
|
+
_CHILDHOOD_POSSESSION_DIRECT_RE,
|
|
32
|
+
_CHILDHOOD_POSSESSION_OBJECT_RE,
|
|
33
|
+
_CHILDREN_PREFERENCE_CONTEXT_RE,
|
|
34
|
+
_CHILDREN_PREFERENCE_DIRECT_RE,
|
|
35
|
+
_CLASSICAL_MUSIC_PREFERENCE_DIRECT_RE,
|
|
36
|
+
_COLLECTIBLE_OBJECT_CONTEXT_RE,
|
|
37
|
+
_COLLECTIBLE_OBJECT_DIRECT_RE,
|
|
38
|
+
_COMMON_INTEREST_ANIMAL_AFFINITY_SLOT_RE,
|
|
39
|
+
_COMMON_INTEREST_INSPIRATIONAL_AFFINITY_SLOT_RE,
|
|
40
|
+
_COMMON_INTEREST_MOVIE_QUESTION_ONLY_RE,
|
|
41
|
+
_COMMON_INTEREST_MOVIE_SEEN_QUERY_RE,
|
|
42
|
+
_COMMON_INTEREST_MOVIE_SEEN_SLOT_RE,
|
|
43
|
+
_COMMON_INTEREST_MOVIE_SLOT_RE,
|
|
44
|
+
_COMMON_INTEREST_PERSONAL_DESSERT_PREFERENCE_RE,
|
|
45
|
+
_COMMON_INTEREST_PERSONAL_HOBBY_SLOT_RE,
|
|
46
|
+
_COMMON_INTEREST_SELF_DESSERT_EVIDENCE_RE,
|
|
47
|
+
_COMMON_INTEREST_SHARED_DESSERT_BRIDGE_RE,
|
|
48
|
+
_COUNT_AGGREGATION_COVERAGE_REASONS,
|
|
49
|
+
_CREATIVE_WORK_SUBMISSION_DIRECT_RE,
|
|
50
|
+
_CREATIVE_WRITING_INVENTORY_DIRECT_RE,
|
|
51
|
+
_DEGREE_COMPLETION_TEMPORAL_QUERY_RE,
|
|
52
|
+
_DIALOGUE_MARKER_RE,
|
|
53
|
+
_DIRECT_EVIDENCE_QUERY_FOCUS_REASONS,
|
|
54
|
+
_DIVERSITY_FAMILY_PRIORITY,
|
|
55
|
+
_DIVERSITY_PRECISE_TURN_REASONS,
|
|
56
|
+
_EXACT_PRECISE_CONTENT_TURN_REASONS,
|
|
57
|
+
_INSPIRATION_SOURCE_CONTEXT_RE,
|
|
58
|
+
_INSPIRATION_SOURCE_DIRECT_RE,
|
|
59
|
+
_INSPIRATION_SOURCE_QUERY_RE,
|
|
60
|
+
_INVENTORY_FRIEND_PLACE_DIRECT_RE,
|
|
61
|
+
_INVENTORY_FRIEND_PLACE_SHELTER_ACTIVITY_REPEAT_RE,
|
|
62
|
+
_INVENTORY_FRIEND_PLACE_SHELTER_ANCHOR_RE,
|
|
63
|
+
_INVENTORY_SHELTER_SLOT_RE,
|
|
64
|
+
_MAX_ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON,
|
|
65
|
+
_MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS,
|
|
66
|
+
_MAX_ANSWER_SUPPORT_EVENT_SLOT_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON,
|
|
67
|
+
_MAX_ANSWER_SUPPORT_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON,
|
|
68
|
+
_MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS,
|
|
69
|
+
_MILITARY_SERVICE_GOAL_DIRECT_RE,
|
|
70
|
+
_MUSIC_ARTIST_DIRECT_ANSWER_RE,
|
|
71
|
+
_MUSIC_EVENT_ATTENDANCE_QUERY_RE,
|
|
72
|
+
_NAMED_ACQUISITION_OBJECT_QUERY_RE,
|
|
73
|
+
_OUTDOOR_NATURE_MEMORY_CONTEXT_RE,
|
|
74
|
+
_OUTDOOR_NATURE_MEMORY_DIRECT_RE,
|
|
75
|
+
_PET_ACQUISITION_DATE_ANCHOR_SUPPORT_RE,
|
|
76
|
+
_PET_ACQUISITION_OBJECT_ANCHOR_RE,
|
|
77
|
+
_PLACE_AREA_DIRECT_LOCATION_RE,
|
|
78
|
+
_PLACE_AREA_LANDMARK_LOCATION_RE,
|
|
79
|
+
_PLACE_AREA_STATE_FUTURE_RE,
|
|
80
|
+
_PLACE_AREA_STATE_QUERY_RE,
|
|
81
|
+
_PLACE_AREA_STATE_VISIT_RE,
|
|
82
|
+
_POTTERY_TYPE_DIRECT_MADE_OBJECT_RE,
|
|
83
|
+
_POTTERY_TYPE_FRIENDSHIP_COMPANION_RE,
|
|
84
|
+
_POTTERY_TYPE_GENERIC_ANSWER_OBJECT_RE,
|
|
85
|
+
_POTTERY_TYPE_PROJECT_COMPANION_RE,
|
|
86
|
+
_PRECISE_TURN_ANSWER_SUPPORT_REASONS,
|
|
87
|
+
_PUBLIC_OFFICE_SERVICE_DIRECT_RE,
|
|
88
|
+
_QUERY_OBJECT_TOKEN_RE,
|
|
89
|
+
_RECOGNITION_CERTIFICATE_QUERY_RE,
|
|
90
|
+
_RECOGNITION_CERTIFICATE_VISUAL_ANSWER_RE,
|
|
91
|
+
_SCREENPLAY_REJECTION_DIRECT_RE,
|
|
92
|
+
_SENTIMENTAL_REMINDER_CONTEXT_RE,
|
|
93
|
+
_SENTIMENTAL_REMINDER_DIRECT_RE,
|
|
94
|
+
_SUPPORT_CAREER_MOTIVATION_CONTEXT_RE,
|
|
95
|
+
_SUPPORT_CAREER_MOTIVATION_DIRECT_RE,
|
|
96
|
+
_TEMPORAL_ANSWER_SUPPORT_QUERY_RE,
|
|
97
|
+
_TEMPORAL_ANSWER_SUPPORT_REASONS,
|
|
98
|
+
_TEMPORAL_DIRECT_ANSWER_RE,
|
|
99
|
+
_TEMPORAL_QUERY_OBJECT_STOPWORDS,
|
|
100
|
+
)
|
|
101
|
+
from infinity_context_core.application.context_packer_answer_support_slots import (
|
|
102
|
+
_activity_answer_slot,
|
|
103
|
+
_aggregation_marker_coverage_slot,
|
|
104
|
+
_animal_evidence_answer_slot,
|
|
105
|
+
_animal_evidence_answer_slot_from_family,
|
|
106
|
+
_animal_evidence_answer_slot_priority_for_family,
|
|
107
|
+
_animal_evidence_slot_for_text,
|
|
108
|
+
_book_reading_answer_content_rank,
|
|
109
|
+
_broad_evidence_turn_slot,
|
|
110
|
+
_business_commonality_answer_slot,
|
|
111
|
+
_career_answer_slot,
|
|
112
|
+
_career_answer_slot_from_family,
|
|
113
|
+
_career_answer_slot_priority,
|
|
114
|
+
_cause_event_answer_slot,
|
|
115
|
+
_charity_brand_sponsorship_answer_slot,
|
|
116
|
+
_common_interest_answer_slot,
|
|
117
|
+
_common_interest_answer_slot_from_family,
|
|
118
|
+
_common_interest_answer_slot_priority,
|
|
119
|
+
_degree_policy_answer_slot,
|
|
120
|
+
_family_activity_answer_object_rank,
|
|
121
|
+
_general_activity_answer_slot_for_text,
|
|
122
|
+
_inference_answer_slot,
|
|
123
|
+
_inventory_answer_slot,
|
|
124
|
+
_inventory_answer_slot_for_text,
|
|
125
|
+
_inventory_answer_slot_from_family,
|
|
126
|
+
_inventory_list_answer_object_rank,
|
|
127
|
+
_is_activity_participation_answer_reason,
|
|
128
|
+
_is_common_interest_answer_reason,
|
|
129
|
+
_is_community_participation_reason,
|
|
130
|
+
_is_conversational_support_turn,
|
|
131
|
+
_is_count_aggregation_coverage_item,
|
|
132
|
+
_is_family_activity_reason,
|
|
133
|
+
_is_inventory_list_reason,
|
|
134
|
+
_is_pottery_type_inventory_item,
|
|
135
|
+
_is_pottery_type_reason,
|
|
136
|
+
_is_support_network_reason,
|
|
137
|
+
_pottery_type_answer_object_rank,
|
|
138
|
+
_support_network_answer_object_rank,
|
|
139
|
+
_travel_country_inventory_slot_for_text,
|
|
140
|
+
)
|
|
141
|
+
from infinity_context_core.application.context_packer_answer_support_utils import (
|
|
142
|
+
_answer_support_activity_family_slot,
|
|
143
|
+
_answer_support_exact_query_object_hits,
|
|
144
|
+
_artifact_diversity_hint,
|
|
145
|
+
_compound_diversity_family,
|
|
146
|
+
_diagnostic_list,
|
|
147
|
+
_diagnostic_score_signals,
|
|
148
|
+
_diagnostic_signal_text,
|
|
149
|
+
_diagnostic_signal_truthy,
|
|
150
|
+
_diagnostic_text,
|
|
151
|
+
_diversity_family_base,
|
|
152
|
+
_has_any_exact_turn_source_ref,
|
|
153
|
+
_has_primary_exact_turn_source_ref,
|
|
154
|
+
_inventory_first_mention_rank,
|
|
155
|
+
_numeric_signal,
|
|
156
|
+
_primary_exact_turn_source_id,
|
|
157
|
+
_source_group_key,
|
|
158
|
+
_source_key,
|
|
159
|
+
_typed_diversity_family,
|
|
160
|
+
)
|
|
161
|
+
from infinity_context_core.application.context_packer_inventory_slots import (
|
|
162
|
+
_answer_support_exact_turn_alignment_rank,
|
|
163
|
+
_exercise_activity_answer_content_rank,
|
|
164
|
+
_inventory_answer_slot_priority_for_family,
|
|
165
|
+
_painting_inventory_answer_content_rank,
|
|
166
|
+
)
|
|
167
|
+
from infinity_context_core.application.context_recommendation_answer_support import (
|
|
168
|
+
is_concrete_recommendation_answer,
|
|
169
|
+
is_recommendation_list_reason,
|
|
170
|
+
recommendation_family_priority,
|
|
171
|
+
recommendation_list_answer_support_rank,
|
|
172
|
+
recommendation_query_focus_applies,
|
|
173
|
+
recommendation_role_alignment_rank,
|
|
174
|
+
)
|
|
175
|
+
from infinity_context_core.application.context_relationship_status_evidence import (
|
|
176
|
+
is_relationship_status_answer_evidence,
|
|
177
|
+
relationship_status_answer_rank,
|
|
178
|
+
)
|
|
179
|
+
from infinity_context_core.application.context_source_sibling_place_evidence import (
|
|
180
|
+
country_destination_answer_support_rank,
|
|
181
|
+
is_country_destination_source_sibling_answer_evidence,
|
|
182
|
+
is_place_inference_source_sibling_answer_evidence,
|
|
183
|
+
is_query_destination_source_sibling_anchor,
|
|
184
|
+
is_themed_location_source_sibling_answer_evidence,
|
|
185
|
+
query_destination_places,
|
|
186
|
+
)
|
|
187
|
+
from infinity_context_core.application.context_source_siblings import (
|
|
188
|
+
_query_person_matches_text as _source_sibling_query_person_matches_text,
|
|
189
|
+
)
|
|
190
|
+
from infinity_context_core.application.context_source_siblings import (
|
|
191
|
+
is_named_preference_source_sibling_answer_evidence,
|
|
192
|
+
)
|
|
193
|
+
from infinity_context_core.application.context_state_residence_inference import (
|
|
194
|
+
state_residence_inference_signal,
|
|
195
|
+
)
|
|
196
|
+
from infinity_context_core.application.context_travel_hobby_writing_evidence import (
|
|
197
|
+
TRAVEL_HOBBY_WRITING_REASON,
|
|
198
|
+
travel_hobby_writing_answer_rank,
|
|
199
|
+
)
|
|
200
|
+
from infinity_context_core.application.dto import ContextItem
|
|
201
|
+
|
|
202
|
+
_EN_SHARED_VOLUNTEERING_QUERY_RE = re.compile(
|
|
203
|
+
r"\b(?:both|common|shared|mutual)\b(?=.{0,160}\bvolunteer(?:ed|ing|s)?\b)|"
|
|
204
|
+
r"\bvolunteer(?:ed|ing|s)?\b(?=.{0,160}\b(?:both|common|shared|mutual)\b)|"
|
|
205
|
+
r"\bwhat\s+type\s+of\s+volunteering\b",
|
|
206
|
+
re.IGNORECASE | re.DOTALL,
|
|
207
|
+
)
|
|
208
|
+
_SHARED_VOLUNTEERING_QUERY_REASONS = frozenset(
|
|
209
|
+
{
|
|
210
|
+
"decomposition-inventory-list",
|
|
211
|
+
"volunteering-inventory-bridge",
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
_SHARED_VOLUNTEERING_FIRST_MENTION_SLOTS = frozenset(
|
|
215
|
+
{
|
|
216
|
+
"shelter",
|
|
217
|
+
"shelter_activity",
|
|
218
|
+
"shelter_anchor",
|
|
219
|
+
"shelter_service_activity",
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
_RELATIONSHIP_STATUS_SELF_DISCLOSURE_RE = re.compile(
|
|
223
|
+
r"\b(?:my|our)\s+(?:husband|wife|spouse|boyfriend|girlfriend|fianc[eé]e?|"
|
|
224
|
+
r"romantic\s+partner|life\s+partner)\b|"
|
|
225
|
+
r"\b(?:i|we)\s+(?:got\s+married|am\s+married|are\s+married|was\s+married|"
|
|
226
|
+
r"were\s+married)\b|"
|
|
227
|
+
r"\b(?:i'm|we're)\s+married\b|"
|
|
228
|
+
r"\bwhere\s+i\s+got\s+married\b",
|
|
229
|
+
re.IGNORECASE,
|
|
230
|
+
)
|
|
231
|
+
_RELATIONSHIP_STATUS_QUESTION_ONLY_RE = re.compile(
|
|
232
|
+
r"\b(?:are\s+you\s+married|have\s+you\s+been\s+married|"
|
|
233
|
+
r"how\s+long\s+have\s+you\s+been\s+married|"
|
|
234
|
+
r"what\s+do\s+you\s+value\s+in\s+your\s+relationship|"
|
|
235
|
+
r"do\s+you\s+have\s+(?:a\s+)?(?:husband|wife|spouse|partner))\?",
|
|
236
|
+
re.IGNORECASE,
|
|
237
|
+
)
|
|
238
|
+
_NEUTRAL_FIRST_MENTION_RANK = (9999, 9999)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _diversity_candidates(items: list[ContextItem]) -> dict[str, ContextItem]:
|
|
242
|
+
candidates: dict[str, ContextItem] = {}
|
|
243
|
+
for item in items:
|
|
244
|
+
family = _diversity_family(item)
|
|
245
|
+
existing = candidates.get(family)
|
|
246
|
+
if existing is None or _diversity_candidate_item_key(item) < (
|
|
247
|
+
_diversity_candidate_item_key(existing)
|
|
248
|
+
):
|
|
249
|
+
candidates[family] = item
|
|
250
|
+
return candidates
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _ordered_diversity_families(candidates: dict[str, ContextItem]) -> tuple[str, ...]:
|
|
254
|
+
priority = {family: index for index, family in enumerate(_DIVERSITY_FAMILY_PRIORITY)}
|
|
255
|
+
return tuple(
|
|
256
|
+
sorted(
|
|
257
|
+
candidates,
|
|
258
|
+
key=lambda family: (
|
|
259
|
+
priority.get(_diversity_family_base(family), len(priority)),
|
|
260
|
+
context_rank_key(candidates[family]),
|
|
261
|
+
family,
|
|
262
|
+
),
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _diversity_family(item: ContextItem) -> str:
|
|
268
|
+
if item.item_type == "anchor":
|
|
269
|
+
return _typed_diversity_family(
|
|
270
|
+
"anchor",
|
|
271
|
+
_diagnostic_text(item, "anchor_kind"),
|
|
272
|
+
)
|
|
273
|
+
if item.item_type == "extraction_artifact":
|
|
274
|
+
return _typed_diversity_family(
|
|
275
|
+
"extraction_artifact",
|
|
276
|
+
_artifact_diversity_hint(item),
|
|
277
|
+
)
|
|
278
|
+
if item.item_type in _DIVERSITY_FAMILY_PRIORITY:
|
|
279
|
+
return item.item_type
|
|
280
|
+
return item.item_type or "unknown"
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _diversity_candidate_item_key(item: ContextItem) -> tuple[object, ...]:
|
|
284
|
+
query_reason = _answer_support_query_reason(item)
|
|
285
|
+
broad_window_rank = 1
|
|
286
|
+
if (
|
|
287
|
+
query_reason in _DIVERSITY_PRECISE_TURN_REASONS
|
|
288
|
+
and _has_primary_exact_turn_source_ref(item)
|
|
289
|
+
) or (
|
|
290
|
+
query_reason in _BROAD_EVIDENCE_ANSWER_SUPPORT_REASONS
|
|
291
|
+
and len(item.source_refs) > 1
|
|
292
|
+
):
|
|
293
|
+
broad_window_rank = 0
|
|
294
|
+
return (
|
|
295
|
+
broad_window_rank,
|
|
296
|
+
context_rank_key(item),
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _answer_support_diversity_candidates(
|
|
301
|
+
items: list[ContextItem],
|
|
302
|
+
*,
|
|
303
|
+
query: str = "",
|
|
304
|
+
) -> dict[str, ContextItem]:
|
|
305
|
+
candidates: dict[str, ContextItem] = {}
|
|
306
|
+
for item in items:
|
|
307
|
+
family = _answer_support_diversity_family(item)
|
|
308
|
+
if not family:
|
|
309
|
+
continue
|
|
310
|
+
existing = candidates.get(family)
|
|
311
|
+
if existing is None or _answer_support_family_item_key_for_query(
|
|
312
|
+
item, query=query
|
|
313
|
+
) < (
|
|
314
|
+
_answer_support_family_item_key_for_query(existing, query=query)
|
|
315
|
+
):
|
|
316
|
+
candidates[family] = item
|
|
317
|
+
return candidates
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _answer_support_source_ref_ids_sample(
|
|
321
|
+
ordered_families: tuple[str, ...],
|
|
322
|
+
candidates: dict[str, ContextItem],
|
|
323
|
+
) -> tuple[str, ...]:
|
|
324
|
+
source_ids: list[str] = []
|
|
325
|
+
for family in ordered_families:
|
|
326
|
+
item = candidates.get(family)
|
|
327
|
+
if item is None:
|
|
328
|
+
continue
|
|
329
|
+
source_id = _primary_exact_turn_source_id(item) or _source_key(item)
|
|
330
|
+
source_id = source_id.strip()
|
|
331
|
+
if source_id and source_id not in source_ids:
|
|
332
|
+
source_ids.append(source_id)
|
|
333
|
+
if len(source_ids) >= 40:
|
|
334
|
+
return tuple(source_ids)
|
|
335
|
+
return tuple(source_ids)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def _answer_support_selected_source_ref_ids_sample(
|
|
339
|
+
selected: tuple[ContextItem, ...],
|
|
340
|
+
) -> tuple[str, ...]:
|
|
341
|
+
source_ids: list[str] = []
|
|
342
|
+
for item in selected:
|
|
343
|
+
if not _answer_support_diversity_family(item):
|
|
344
|
+
continue
|
|
345
|
+
for ref in item.source_refs:
|
|
346
|
+
source_id = str(ref.source_id).strip()
|
|
347
|
+
if source_id and source_id not in source_ids:
|
|
348
|
+
source_ids.append(source_id)
|
|
349
|
+
if len(source_ids) >= 40:
|
|
350
|
+
return tuple(source_ids)
|
|
351
|
+
return tuple(source_ids)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _answer_support_selected_families_sample(
|
|
355
|
+
selected: tuple[ContextItem, ...],
|
|
356
|
+
) -> tuple[str, ...]:
|
|
357
|
+
families: list[str] = []
|
|
358
|
+
for item in selected:
|
|
359
|
+
family = _answer_support_diversity_family(item)
|
|
360
|
+
if family and family not in families:
|
|
361
|
+
families.append(family)
|
|
362
|
+
if len(families) >= 40:
|
|
363
|
+
return tuple(families)
|
|
364
|
+
return tuple(families)
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _ordered_answer_support_families(candidates: dict[str, ContextItem]) -> tuple[str, ...]:
|
|
368
|
+
return _ordered_answer_support_families_for_query(candidates, query="")
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def _ordered_answer_support_families_for_query(
|
|
372
|
+
candidates: dict[str, ContextItem],
|
|
373
|
+
*,
|
|
374
|
+
query: str,
|
|
375
|
+
) -> tuple[str, ...]:
|
|
376
|
+
marker_source_group_counts = _marker_coverage_source_group_counts(candidates)
|
|
377
|
+
broad_turn_source_group_counts = _broad_turn_source_group_counts(candidates)
|
|
378
|
+
pet_acquisition_named_object_source_groups = (
|
|
379
|
+
_pet_acquisition_named_object_source_groups(
|
|
380
|
+
candidates,
|
|
381
|
+
query=query,
|
|
382
|
+
)
|
|
383
|
+
)
|
|
384
|
+
ordered = tuple(
|
|
385
|
+
sorted(
|
|
386
|
+
candidates,
|
|
387
|
+
key=lambda family: (
|
|
388
|
+
_answer_support_query_focus_priority(
|
|
389
|
+
family,
|
|
390
|
+
item=candidates[family],
|
|
391
|
+
query=query,
|
|
392
|
+
),
|
|
393
|
+
_answer_support_family_priority(
|
|
394
|
+
family,
|
|
395
|
+
item=candidates[family],
|
|
396
|
+
query=query,
|
|
397
|
+
marker_source_group_counts=marker_source_group_counts,
|
|
398
|
+
broad_turn_source_group_counts=broad_turn_source_group_counts,
|
|
399
|
+
pet_acquisition_named_object_source_groups=(
|
|
400
|
+
pet_acquisition_named_object_source_groups
|
|
401
|
+
),
|
|
402
|
+
),
|
|
403
|
+
_answer_support_family_item_key_for_query(candidates[family], query=query),
|
|
404
|
+
family,
|
|
405
|
+
),
|
|
406
|
+
)
|
|
407
|
+
)
|
|
408
|
+
return _round_robin_inventory_slot_families(
|
|
409
|
+
ordered,
|
|
410
|
+
candidates=candidates,
|
|
411
|
+
query=query,
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def _answer_support_query_focus_priority(
|
|
416
|
+
family: str,
|
|
417
|
+
*,
|
|
418
|
+
item: ContextItem,
|
|
419
|
+
query: str,
|
|
420
|
+
) -> int:
|
|
421
|
+
query_reason = _answer_support_query_reason(item)
|
|
422
|
+
if (
|
|
423
|
+
_recognition_award_visual_answer_rank(
|
|
424
|
+
item,
|
|
425
|
+
query=query,
|
|
426
|
+
query_reason=query_reason,
|
|
427
|
+
)
|
|
428
|
+
== 0
|
|
429
|
+
):
|
|
430
|
+
return -4
|
|
431
|
+
if recommendation_query_focus_applies(
|
|
432
|
+
text=item.text,
|
|
433
|
+
query=query,
|
|
434
|
+
query_reason=query_reason,
|
|
435
|
+
has_exact_turn=_has_any_exact_turn_source_ref(item),
|
|
436
|
+
):
|
|
437
|
+
return -3
|
|
438
|
+
if (
|
|
439
|
+
food_inventory_answer_support_applies(
|
|
440
|
+
query=query,
|
|
441
|
+
query_reason=query_reason,
|
|
442
|
+
)
|
|
443
|
+
and food_inventory_answer_support_rank(
|
|
444
|
+
text=item.text,
|
|
445
|
+
query=query,
|
|
446
|
+
query_reason=query_reason,
|
|
447
|
+
has_exact_turn=_has_any_exact_turn_source_ref(item),
|
|
448
|
+
)
|
|
449
|
+
== 0
|
|
450
|
+
and food_inventory_role_alignment_rank(
|
|
451
|
+
text=item.text,
|
|
452
|
+
query=query,
|
|
453
|
+
query_reason=query_reason,
|
|
454
|
+
)
|
|
455
|
+
<= 1
|
|
456
|
+
):
|
|
457
|
+
return -3
|
|
458
|
+
if (
|
|
459
|
+
query_reason in _DIRECT_EVIDENCE_QUERY_FOCUS_REASONS
|
|
460
|
+
and _has_any_exact_turn_source_ref(item)
|
|
461
|
+
and _precise_answer_content_rank(item, query_reason=query_reason) == 0
|
|
462
|
+
):
|
|
463
|
+
return -3
|
|
464
|
+
if (
|
|
465
|
+
_diversity_family_base(family)
|
|
466
|
+
in {
|
|
467
|
+
"query_reason_inventory_slot",
|
|
468
|
+
"query_reason_inventory_slot_source_group",
|
|
469
|
+
}
|
|
470
|
+
and _is_cause_inventory_answer_support_item(item)
|
|
471
|
+
):
|
|
472
|
+
return -4
|
|
473
|
+
if (
|
|
474
|
+
_diversity_family_base(family)
|
|
475
|
+
in {
|
|
476
|
+
"query_reason_animal_evidence_slot",
|
|
477
|
+
"query_reason_animal_evidence_slot_source_group",
|
|
478
|
+
}
|
|
479
|
+
and _has_any_exact_turn_source_ref(item)
|
|
480
|
+
):
|
|
481
|
+
return -3
|
|
482
|
+
if _is_degree_completion_temporal_answer_support_item(item, query=query):
|
|
483
|
+
return -3
|
|
484
|
+
if _is_exact_business_direct_answer_support_item(item):
|
|
485
|
+
return -3
|
|
486
|
+
if _is_exact_screenplay_rejection_answer_support_item(item):
|
|
487
|
+
return -3
|
|
488
|
+
if _is_exact_common_interest_answer_support_item(item):
|
|
489
|
+
return -3
|
|
490
|
+
if _is_exact_named_preference_answer_support_item(item, query=query):
|
|
491
|
+
return -4
|
|
492
|
+
if _is_exact_place_inference_answer_support_item(item, query=query):
|
|
493
|
+
return -4
|
|
494
|
+
if _is_exact_themed_location_inference_answer_support_item(item, query=query):
|
|
495
|
+
return -4
|
|
496
|
+
if _is_exact_query_destination_answer_support_item(item, query=query):
|
|
497
|
+
return -5
|
|
498
|
+
if _is_exact_country_destination_answer_support_item(item, query=query):
|
|
499
|
+
return -5
|
|
500
|
+
if (
|
|
501
|
+
query_reason == TRAVEL_HOBBY_WRITING_REASON
|
|
502
|
+
and _has_any_exact_turn_source_ref(item)
|
|
503
|
+
and travel_hobby_writing_answer_rank(item.text) <= 1
|
|
504
|
+
):
|
|
505
|
+
return -6 + travel_hobby_writing_answer_rank(item.text)
|
|
506
|
+
country_destination_rank = _country_destination_answer_support_rank(
|
|
507
|
+
item,
|
|
508
|
+
query=query,
|
|
509
|
+
)
|
|
510
|
+
if country_destination_rank < 5:
|
|
511
|
+
return -4 + country_destination_rank
|
|
512
|
+
if _is_direct_place_area_state_answer_support_item(
|
|
513
|
+
item,
|
|
514
|
+
query=query,
|
|
515
|
+
family=family,
|
|
516
|
+
):
|
|
517
|
+
return -3
|
|
518
|
+
if _is_state_residence_geo_answer_support_item(item, query=query):
|
|
519
|
+
return -3
|
|
520
|
+
if _is_direct_outdoor_activity_answer_support_item(
|
|
521
|
+
item,
|
|
522
|
+
query=query,
|
|
523
|
+
family=family,
|
|
524
|
+
):
|
|
525
|
+
return -3
|
|
526
|
+
if (
|
|
527
|
+
query_reason == "item_purchase_bridge"
|
|
528
|
+
and _answer_support_inventory_family_slot(family)
|
|
529
|
+
and has_item_purchase_object_evidence(item.text)
|
|
530
|
+
and _has_any_exact_turn_source_ref(item)
|
|
531
|
+
):
|
|
532
|
+
return -3
|
|
533
|
+
if (
|
|
534
|
+
_answer_support_query_reason(item).replace("_", "-")
|
|
535
|
+
== "travel-country-inventory-bridge"
|
|
536
|
+
and _travel_country_inventory_slot_for_text(item.text)
|
|
537
|
+
and _has_any_exact_turn_source_ref(item)
|
|
538
|
+
):
|
|
539
|
+
return -3
|
|
540
|
+
if _is_exact_named_game_inventory_answer_support_item(family, item=item):
|
|
541
|
+
return -3
|
|
542
|
+
if query_reason.replace("_", "-") == "book-reading-list-bridge" and (
|
|
543
|
+
_diversity_family_base(family)
|
|
544
|
+
in {
|
|
545
|
+
"query_reason_marker_coverage_source_group",
|
|
546
|
+
"temporal_source_sibling_marker",
|
|
547
|
+
"temporal_source_sibling_marker_source_group",
|
|
548
|
+
}
|
|
549
|
+
):
|
|
550
|
+
return 2
|
|
551
|
+
if not query or _MUSIC_EVENT_ATTENDANCE_QUERY_RE.search(query) is None:
|
|
552
|
+
return 0
|
|
553
|
+
query_reason = _answer_support_query_reason(item).replace("_", "-")
|
|
554
|
+
if query_reason not in {
|
|
555
|
+
"classical-music-preference-bridge",
|
|
556
|
+
"music-event-inventory-bridge",
|
|
557
|
+
}:
|
|
558
|
+
return 0
|
|
559
|
+
if _diversity_family_base(family) not in {
|
|
560
|
+
"query_reason_inventory_slot",
|
|
561
|
+
"query_reason_inventory_slot_source_group",
|
|
562
|
+
"query_reason_marker_coverage_source_group",
|
|
563
|
+
"query_reason_source_group",
|
|
564
|
+
"temporal_source_sibling_marker", "temporal_source_sibling_marker_source_group",
|
|
565
|
+
}:
|
|
566
|
+
return 0
|
|
567
|
+
slot = _inventory_answer_slot_for_text(item.text)
|
|
568
|
+
if slot in {"music_live_event", "music_violin_concert"}:
|
|
569
|
+
return -2
|
|
570
|
+
if slot == "music_event":
|
|
571
|
+
return -1
|
|
572
|
+
return 0
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def _answer_support_item_limit(candidates: dict[str, ContextItem]) -> int:
|
|
576
|
+
inventory_slots_by_reason: dict[str, set[str]] = {}
|
|
577
|
+
animal_slots_by_reason: dict[str, set[str]] = {}
|
|
578
|
+
common_interest_exact_family_counts_by_reason: dict[str, int] = {}
|
|
579
|
+
exact_marker_reasons: set[str] = set()
|
|
580
|
+
has_pet_acquisition_support = False
|
|
581
|
+
travel_country_exact_family_count = 0
|
|
582
|
+
recommendation_exact_family_count = 0
|
|
583
|
+
for family, item in candidates.items():
|
|
584
|
+
query_reason = _answer_support_query_reason(item)
|
|
585
|
+
if query_reason == "pet_acquisition_date_bridge":
|
|
586
|
+
has_pet_acquisition_support = True
|
|
587
|
+
if is_concrete_recommendation_answer(
|
|
588
|
+
text=item.text,
|
|
589
|
+
query_reason=query_reason,
|
|
590
|
+
) and _has_any_exact_turn_source_ref(item):
|
|
591
|
+
recommendation_exact_family_count += 1
|
|
592
|
+
if _diversity_family_base(family) == "query_reason_exact_marker_source_group":
|
|
593
|
+
exact_marker_reasons.add(query_reason.replace("_", "-"))
|
|
594
|
+
reason = query_reason.replace("_", "-")
|
|
595
|
+
if (
|
|
596
|
+
reason == "travel-country-inventory-bridge"
|
|
597
|
+
and _travel_country_inventory_slot_for_text(item.text)
|
|
598
|
+
and _has_any_exact_turn_source_ref(item)
|
|
599
|
+
):
|
|
600
|
+
travel_country_exact_family_count += 1
|
|
601
|
+
if slot := _answer_support_inventory_family_slot(family):
|
|
602
|
+
inventory_slots_by_reason.setdefault(reason, set()).add(slot)
|
|
603
|
+
if animal_slot := _answer_support_animal_evidence_family_slot(family):
|
|
604
|
+
animal_slots_by_reason.setdefault(reason, set()).add(animal_slot)
|
|
605
|
+
if (
|
|
606
|
+
_answer_support_common_interest_family_slot(family)
|
|
607
|
+
and _is_exact_common_interest_answer_support_item(item)
|
|
608
|
+
):
|
|
609
|
+
common_interest_exact_family_counts_by_reason[reason] = (
|
|
610
|
+
common_interest_exact_family_counts_by_reason.get(reason, 0) + 1
|
|
611
|
+
)
|
|
612
|
+
if "pottery-type-bridge" in exact_marker_reasons:
|
|
613
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
614
|
+
if has_pet_acquisition_support:
|
|
615
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
616
|
+
if any(
|
|
617
|
+
count > _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
618
|
+
for count in common_interest_exact_family_counts_by_reason.values()
|
|
619
|
+
):
|
|
620
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
621
|
+
if travel_country_exact_family_count > _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS:
|
|
622
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
623
|
+
if recommendation_exact_family_count > _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS:
|
|
624
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
625
|
+
if any(
|
|
626
|
+
len(slots) > _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
627
|
+
for slots in inventory_slots_by_reason.values()
|
|
628
|
+
):
|
|
629
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
630
|
+
if any(
|
|
631
|
+
len(slots) > _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
632
|
+
for slots in animal_slots_by_reason.values()
|
|
633
|
+
):
|
|
634
|
+
return _MAX_INVENTORY_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
635
|
+
return _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def _round_robin_inventory_slot_families(
|
|
639
|
+
families: tuple[str, ...],
|
|
640
|
+
*,
|
|
641
|
+
candidates: dict[str, ContextItem],
|
|
642
|
+
query: str = "",
|
|
643
|
+
) -> tuple[str, ...]:
|
|
644
|
+
if query and _PLACE_AREA_STATE_QUERY_RE.search(query) is not None:
|
|
645
|
+
return families
|
|
646
|
+
coverage_positions = tuple(
|
|
647
|
+
index
|
|
648
|
+
for index, family in enumerate(families)
|
|
649
|
+
if _answer_support_coverage_family_slot(family)
|
|
650
|
+
)
|
|
651
|
+
if len(coverage_positions) < 3:
|
|
652
|
+
return families
|
|
653
|
+
slot_counts: dict[str, int] = {}
|
|
654
|
+
ranked: list[tuple[int, int, int, str]] = []
|
|
655
|
+
for index in coverage_positions:
|
|
656
|
+
family = families[index]
|
|
657
|
+
slot = _answer_support_coverage_family_slot(family)
|
|
658
|
+
coverage_round = slot_counts.get(slot, 0)
|
|
659
|
+
slot_counts[slot] = coverage_round + 1
|
|
660
|
+
slot_priority = _answer_support_coverage_family_slot_priority(family)
|
|
661
|
+
if (
|
|
662
|
+
slot.startswith("common_interest:")
|
|
663
|
+
and _is_exact_common_interest_answer_support_item(candidates[family])
|
|
664
|
+
and _common_interest_direct_evidence_rank(
|
|
665
|
+
candidates[family],
|
|
666
|
+
query_reason=_answer_support_query_reason(candidates[family]),
|
|
667
|
+
)
|
|
668
|
+
== 0
|
|
669
|
+
):
|
|
670
|
+
slot_priority -= 2
|
|
671
|
+
if _is_single_exact_cause_inventory_answer_support_item(candidates[family]):
|
|
672
|
+
coverage_round = 0
|
|
673
|
+
elif slot_priority < 0:
|
|
674
|
+
coverage_round = max(0, coverage_round - 2)
|
|
675
|
+
elif slot_priority >= 3:
|
|
676
|
+
coverage_round += 2
|
|
677
|
+
ranked.append((coverage_round, slot_priority, index, family))
|
|
678
|
+
reranked_inventory = iter(family for _, _, _, family in sorted(ranked))
|
|
679
|
+
inventory_position_set = set(coverage_positions)
|
|
680
|
+
return tuple(
|
|
681
|
+
next(reranked_inventory) if index in inventory_position_set else family
|
|
682
|
+
for index, family in enumerate(families)
|
|
683
|
+
)
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def _answer_support_coverage_family_slot(family: str) -> str:
|
|
687
|
+
inventory_slot = _answer_support_inventory_family_slot(family)
|
|
688
|
+
if inventory_slot:
|
|
689
|
+
return f"inventory:{inventory_slot}"
|
|
690
|
+
animal_slot = _answer_support_animal_evidence_family_slot(family)
|
|
691
|
+
if animal_slot:
|
|
692
|
+
return f"animal:{animal_slot}"
|
|
693
|
+
common_interest_slot = _answer_support_common_interest_family_slot(family)
|
|
694
|
+
if common_interest_slot:
|
|
695
|
+
return f"common_interest:{common_interest_slot}"
|
|
696
|
+
activity_slot = _answer_support_activity_family_slot(family)
|
|
697
|
+
if activity_slot:
|
|
698
|
+
return f"activity:{activity_slot}"
|
|
699
|
+
career_slot = _answer_support_career_family_slot(family)
|
|
700
|
+
if career_slot:
|
|
701
|
+
return f"career:{career_slot}"
|
|
702
|
+
return ""
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def _answer_support_coverage_family_slot_priority(family: str) -> int:
|
|
706
|
+
inventory_slot = _answer_support_inventory_family_slot(family)
|
|
707
|
+
if inventory_slot:
|
|
708
|
+
return _inventory_answer_slot_priority_for_family(
|
|
709
|
+
inventory_slot,
|
|
710
|
+
family=family,
|
|
711
|
+
)
|
|
712
|
+
animal_slot = _answer_support_animal_evidence_family_slot(family)
|
|
713
|
+
if animal_slot:
|
|
714
|
+
return _animal_evidence_answer_slot_priority_for_family(
|
|
715
|
+
animal_slot,
|
|
716
|
+
family=family,
|
|
717
|
+
)
|
|
718
|
+
common_interest_slot = _answer_support_common_interest_family_slot(family)
|
|
719
|
+
if common_interest_slot:
|
|
720
|
+
return _common_interest_answer_slot_priority(common_interest_slot)
|
|
721
|
+
career_slot = _answer_support_career_family_slot(family)
|
|
722
|
+
if career_slot:
|
|
723
|
+
return _career_answer_slot_priority(career_slot)
|
|
724
|
+
return 0
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
def _answer_support_inventory_family_slot(family: str) -> str:
|
|
728
|
+
if _diversity_family_base(family) not in {
|
|
729
|
+
"query_reason_inventory_slot",
|
|
730
|
+
"query_reason_inventory_slot_source_group",
|
|
731
|
+
}:
|
|
732
|
+
return ""
|
|
733
|
+
return _inventory_answer_slot_from_family(family)
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
def _answer_support_animal_evidence_family_slot(family: str) -> str:
|
|
737
|
+
if _diversity_family_base(family) not in {
|
|
738
|
+
"query_reason_animal_evidence_slot",
|
|
739
|
+
"query_reason_animal_evidence_slot_source_group",
|
|
740
|
+
}:
|
|
741
|
+
return ""
|
|
742
|
+
return _animal_evidence_answer_slot_from_family(family)
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
def _answer_support_career_family_slot(family: str) -> str:
|
|
746
|
+
if _diversity_family_base(family) not in {
|
|
747
|
+
"query_reason_career_slot",
|
|
748
|
+
"query_reason_career_slot_marker_source_group",
|
|
749
|
+
"query_reason_career_slot_source_group",
|
|
750
|
+
}:
|
|
751
|
+
return ""
|
|
752
|
+
return _career_answer_slot_from_family(family)
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
def _answer_support_common_interest_family_slot(family: str) -> str:
|
|
756
|
+
if _diversity_family_base(family) not in {
|
|
757
|
+
"query_reason_common_interest_slot",
|
|
758
|
+
"query_reason_common_interest_slot_source_group",
|
|
759
|
+
"query_reason_common_interest_slot_marker_source_group",
|
|
760
|
+
}:
|
|
761
|
+
return ""
|
|
762
|
+
return _common_interest_answer_slot_from_family(family)
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
def _relationship_status_answer_support_rank(
|
|
766
|
+
item: ContextItem,
|
|
767
|
+
*,
|
|
768
|
+
query: str,
|
|
769
|
+
query_reason: str,
|
|
770
|
+
) -> int:
|
|
771
|
+
if not is_relationship_status_answer_evidence(
|
|
772
|
+
expansion_reason=query_reason,
|
|
773
|
+
text=item.text,
|
|
774
|
+
):
|
|
775
|
+
return 9
|
|
776
|
+
if query and not _source_sibling_query_person_matches_text(
|
|
777
|
+
expansion_query=query,
|
|
778
|
+
text=item.text,
|
|
779
|
+
):
|
|
780
|
+
return 8
|
|
781
|
+
answer_rank = relationship_status_answer_rank(item.text)
|
|
782
|
+
if answer_rank >= 9:
|
|
783
|
+
return answer_rank
|
|
784
|
+
if _RELATIONSHIP_STATUS_SELF_DISCLOSURE_RE.search(item.text) is not None:
|
|
785
|
+
return answer_rank
|
|
786
|
+
if _RELATIONSHIP_STATUS_QUESTION_ONLY_RE.search(item.text) is not None:
|
|
787
|
+
return min(8, answer_rank + 5)
|
|
788
|
+
if _has_any_exact_turn_source_ref(item):
|
|
789
|
+
return min(8, answer_rank + 1)
|
|
790
|
+
return min(8, answer_rank + 2)
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
def _is_relationship_status_direct_answer_support_item(
|
|
794
|
+
item: ContextItem,
|
|
795
|
+
*,
|
|
796
|
+
query: str,
|
|
797
|
+
) -> bool:
|
|
798
|
+
return (
|
|
799
|
+
_relationship_status_answer_support_rank(
|
|
800
|
+
item,
|
|
801
|
+
query=query,
|
|
802
|
+
query_reason=_answer_support_query_reason(item),
|
|
803
|
+
)
|
|
804
|
+
<= 1
|
|
805
|
+
)
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def _answer_support_family_priority(
|
|
809
|
+
family: str,
|
|
810
|
+
*,
|
|
811
|
+
item: ContextItem,
|
|
812
|
+
query: str,
|
|
813
|
+
marker_source_group_counts: dict[str, int],
|
|
814
|
+
broad_turn_source_group_counts: dict[str, int],
|
|
815
|
+
pet_acquisition_named_object_source_groups: frozenset[str] = frozenset(),
|
|
816
|
+
) -> int:
|
|
817
|
+
base = _diversity_family_base(family)
|
|
818
|
+
recommendation_priority = recommendation_family_priority(
|
|
819
|
+
text=item.text,
|
|
820
|
+
query=query,
|
|
821
|
+
query_reason=_answer_support_query_reason(item),
|
|
822
|
+
)
|
|
823
|
+
if recommendation_priority is not None:
|
|
824
|
+
return recommendation_priority
|
|
825
|
+
relationship_status_rank = _relationship_status_answer_support_rank(
|
|
826
|
+
item,
|
|
827
|
+
query=query,
|
|
828
|
+
query_reason=_answer_support_query_reason(item),
|
|
829
|
+
)
|
|
830
|
+
if relationship_status_rank < 9:
|
|
831
|
+
return -5 + relationship_status_rank
|
|
832
|
+
if (
|
|
833
|
+
base
|
|
834
|
+
in {
|
|
835
|
+
"query_reason_inventory_slot",
|
|
836
|
+
"query_reason_inventory_slot_source_group",
|
|
837
|
+
}
|
|
838
|
+
and _is_cause_inventory_answer_support_item(item)
|
|
839
|
+
):
|
|
840
|
+
if _has_primary_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
841
|
+
return -5
|
|
842
|
+
if _has_any_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
843
|
+
return -4
|
|
844
|
+
return -3
|
|
845
|
+
if _is_pet_acquisition_date_anchor_answer_support_item(item):
|
|
846
|
+
if _answer_support_source_group(item) in pet_acquisition_named_object_source_groups:
|
|
847
|
+
return -3
|
|
848
|
+
return -1
|
|
849
|
+
if base in {
|
|
850
|
+
"query_reason_animal_evidence_slot",
|
|
851
|
+
"query_reason_animal_evidence_slot_source_group",
|
|
852
|
+
}:
|
|
853
|
+
return _animal_evidence_answer_slot_priority_for_family(
|
|
854
|
+
_animal_evidence_answer_slot_from_family(family),
|
|
855
|
+
family=family,
|
|
856
|
+
) - (2 if _has_any_exact_turn_source_ref(item) else 0)
|
|
857
|
+
if _is_exact_named_game_inventory_answer_support_item(family, item=item):
|
|
858
|
+
return -3
|
|
859
|
+
if _is_exact_named_preference_answer_support_item(item, query=query):
|
|
860
|
+
return -4
|
|
861
|
+
if _is_exact_place_inference_answer_support_item(item, query=query):
|
|
862
|
+
return -4
|
|
863
|
+
if _is_exact_themed_location_inference_answer_support_item(item, query=query):
|
|
864
|
+
return -4
|
|
865
|
+
if _is_exact_query_destination_answer_support_item(item, query=query):
|
|
866
|
+
return -5
|
|
867
|
+
if _is_exact_country_destination_answer_support_item(item, query=query):
|
|
868
|
+
return -5
|
|
869
|
+
country_destination_rank = _country_destination_answer_support_rank(
|
|
870
|
+
item,
|
|
871
|
+
query=query,
|
|
872
|
+
)
|
|
873
|
+
if country_destination_rank < 5:
|
|
874
|
+
return -4 + country_destination_rank
|
|
875
|
+
if _is_exact_business_direct_answer_support_item(item):
|
|
876
|
+
return -3
|
|
877
|
+
if base in {
|
|
878
|
+
"query_reason_common_interest_slot",
|
|
879
|
+
"query_reason_common_interest_slot_source_group",
|
|
880
|
+
"query_reason_common_interest_slot_marker_source_group",
|
|
881
|
+
}:
|
|
882
|
+
slot_priority = _common_interest_answer_slot_priority(
|
|
883
|
+
_common_interest_answer_slot_from_family(family)
|
|
884
|
+
)
|
|
885
|
+
direct_evidence_adjustment = (
|
|
886
|
+
3
|
|
887
|
+
if (
|
|
888
|
+
_is_exact_common_interest_answer_support_item(item)
|
|
889
|
+
and _common_interest_direct_evidence_rank(
|
|
890
|
+
item,
|
|
891
|
+
query_reason=_answer_support_query_reason(item),
|
|
892
|
+
)
|
|
893
|
+
== 0
|
|
894
|
+
)
|
|
895
|
+
else 0
|
|
896
|
+
)
|
|
897
|
+
return (
|
|
898
|
+
slot_priority
|
|
899
|
+
- (2 if _has_any_exact_turn_source_ref(item) else 1)
|
|
900
|
+
- direct_evidence_adjustment
|
|
901
|
+
)
|
|
902
|
+
if _answer_support_exact_query_object_hits(item, query=query):
|
|
903
|
+
return -1
|
|
904
|
+
if _is_degree_completion_temporal_answer_support_item(item, query=query):
|
|
905
|
+
return -3
|
|
906
|
+
if _is_state_residence_geo_answer_support_item(item, query=query):
|
|
907
|
+
return -3
|
|
908
|
+
if _is_exact_precise_content_answer_support_item(item):
|
|
909
|
+
return -2
|
|
910
|
+
if base in {
|
|
911
|
+
"temporal_source_sibling_marker",
|
|
912
|
+
"temporal_source_sibling_marker_source_group",
|
|
913
|
+
}:
|
|
914
|
+
return 2
|
|
915
|
+
if base == "query_reason_count_coverage_source_group":
|
|
916
|
+
return 0
|
|
917
|
+
if (
|
|
918
|
+
base == "query_reason_broad_turn_source_group"
|
|
919
|
+
and _numeric_signal(
|
|
920
|
+
_diagnostic_score_signals(item).get("book_author_preference_world_evidence")
|
|
921
|
+
)
|
|
922
|
+
>= 3
|
|
923
|
+
and broad_turn_source_group_counts.get(_broad_turn_family_source_group(family), 0) > 1
|
|
924
|
+
):
|
|
925
|
+
return 0
|
|
926
|
+
if base in {
|
|
927
|
+
"query_reason_activity_slot",
|
|
928
|
+
"query_reason_activity_slot_source_group",
|
|
929
|
+
}:
|
|
930
|
+
if _answer_support_query_reason(item) in {
|
|
931
|
+
"art_style_bridge",
|
|
932
|
+
"painting_inventory_bridge",
|
|
933
|
+
}:
|
|
934
|
+
return _inventory_answer_slot_priority_for_family(
|
|
935
|
+
_answer_support_activity_family_slot(family),
|
|
936
|
+
family=family,
|
|
937
|
+
)
|
|
938
|
+
return 0
|
|
939
|
+
if base == "query_reason_exact_marker_source_group" and _is_conversational_support_turn(
|
|
940
|
+
item
|
|
941
|
+
):
|
|
942
|
+
return 0
|
|
943
|
+
if base == "query_reason_exact_marker_source_group":
|
|
944
|
+
return 2
|
|
945
|
+
query_reason = _answer_support_query_reason(item)
|
|
946
|
+
if query_reason == "support_origin_bridge":
|
|
947
|
+
if _precise_answer_content_rank(item, query_reason=query_reason) == 0:
|
|
948
|
+
return -5 if _has_any_exact_turn_source_ref(item) else -3
|
|
949
|
+
return -1
|
|
950
|
+
if (
|
|
951
|
+
query_reason == "support_career_motivation_bridge"
|
|
952
|
+
and _precise_answer_content_rank(item, query_reason=query_reason) == 0
|
|
953
|
+
):
|
|
954
|
+
return 0
|
|
955
|
+
if (
|
|
956
|
+
_is_support_network_reason(query_reason)
|
|
957
|
+
and _support_network_answer_object_rank(item.text) == 0
|
|
958
|
+
):
|
|
959
|
+
return 0
|
|
960
|
+
if (
|
|
961
|
+
base == "query_reason_broad_turn_source_group"
|
|
962
|
+
and query_reason == "birdwatching_city_schedule_bridge"
|
|
963
|
+
):
|
|
964
|
+
return 0
|
|
965
|
+
if _is_pottery_type_reason(query_reason) and base in {
|
|
966
|
+
"query_reason",
|
|
967
|
+
"query_reason_marker_coverage_source_group",
|
|
968
|
+
"query_reason_source_group",
|
|
969
|
+
}:
|
|
970
|
+
return -4
|
|
971
|
+
if (
|
|
972
|
+
base == "query_reason_marker_coverage_source_group"
|
|
973
|
+
and _is_pottery_type_inventory_item(item, query_reason=query_reason)
|
|
974
|
+
):
|
|
975
|
+
return -4
|
|
976
|
+
if (
|
|
977
|
+
base
|
|
978
|
+
in {
|
|
979
|
+
"query_reason_inventory_slot",
|
|
980
|
+
"query_reason_inventory_slot_source_group",
|
|
981
|
+
}
|
|
982
|
+
and _place_area_state_query_applies(query=query, query_reason=query_reason)
|
|
983
|
+
):
|
|
984
|
+
return _place_area_state_answer_support_rank(
|
|
985
|
+
item,
|
|
986
|
+
query=query,
|
|
987
|
+
query_reason=query_reason,
|
|
988
|
+
)
|
|
989
|
+
if base in {
|
|
990
|
+
"query_reason_inventory_slot",
|
|
991
|
+
"query_reason_inventory_slot_source_group",
|
|
992
|
+
}:
|
|
993
|
+
if query_reason == TRAVEL_HOBBY_WRITING_REASON:
|
|
994
|
+
return travel_hobby_writing_answer_rank(item.text) - (
|
|
995
|
+
3 if _has_any_exact_turn_source_ref(item) else 0
|
|
996
|
+
)
|
|
997
|
+
return _inventory_answer_slot_priority_for_family(
|
|
998
|
+
_inventory_answer_slot_from_family(family),
|
|
999
|
+
family=family,
|
|
1000
|
+
)
|
|
1001
|
+
if base in {
|
|
1002
|
+
"query_reason_career_slot",
|
|
1003
|
+
"query_reason_career_slot_marker_source_group",
|
|
1004
|
+
"query_reason_career_slot_source_group",
|
|
1005
|
+
}:
|
|
1006
|
+
slot_priority = _career_answer_slot_priority(_career_answer_slot_from_family(family))
|
|
1007
|
+
if _precise_answer_content_rank(item, query_reason=query_reason) == 0:
|
|
1008
|
+
if _has_primary_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
1009
|
+
return slot_priority - 4
|
|
1010
|
+
if _has_any_exact_turn_source_ref(item):
|
|
1011
|
+
return slot_priority - 3
|
|
1012
|
+
return slot_priority
|
|
1013
|
+
if base == "query_reason_marker_coverage_source_group":
|
|
1014
|
+
if _is_family_activity_reason(query_reason):
|
|
1015
|
+
return 4
|
|
1016
|
+
if (
|
|
1017
|
+
query_reason == "decomposition_inventory_list"
|
|
1018
|
+
and _pottery_type_answer_content_rank(item.text) <= 3
|
|
1019
|
+
):
|
|
1020
|
+
return 0
|
|
1021
|
+
answer_object_rank = _answer_object_rank(
|
|
1022
|
+
item,
|
|
1023
|
+
query_reason=query_reason,
|
|
1024
|
+
)
|
|
1025
|
+
if query_reason == "book_reading_list_bridge":
|
|
1026
|
+
if (
|
|
1027
|
+
_book_reading_answer_content_rank(item.text) <= 1
|
|
1028
|
+
and answer_object_rank <= 1
|
|
1029
|
+
):
|
|
1030
|
+
return 2 + answer_object_rank
|
|
1031
|
+
return 6
|
|
1032
|
+
if answer_object_rank <= 1:
|
|
1033
|
+
return 1 + answer_object_rank
|
|
1034
|
+
source_group = _marker_coverage_family_source_group(family)
|
|
1035
|
+
if marker_source_group_counts.get(source_group, 0) > 1:
|
|
1036
|
+
return min(answer_object_rank + 1, 3)
|
|
1037
|
+
return min(answer_object_rank + 2, 5)
|
|
1038
|
+
return 2
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
def _is_exact_conversational_support_family(family: str, *, item: ContextItem) -> bool:
|
|
1042
|
+
return (
|
|
1043
|
+
_diversity_family_base(family) == "query_reason_exact_marker_source_group"
|
|
1044
|
+
and _is_conversational_support_turn(item)
|
|
1045
|
+
)
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
def _is_exact_named_game_inventory_answer_support_item(
|
|
1049
|
+
family: str,
|
|
1050
|
+
*,
|
|
1051
|
+
item: ContextItem,
|
|
1052
|
+
) -> bool:
|
|
1053
|
+
query_reason = _answer_support_query_reason(item)
|
|
1054
|
+
if query_reason != "board_game_inventory_bridge":
|
|
1055
|
+
return False
|
|
1056
|
+
if _diversity_family_base(family) not in {
|
|
1057
|
+
"query_reason_inventory_slot",
|
|
1058
|
+
"query_reason_inventory_slot_source_group",
|
|
1059
|
+
}:
|
|
1060
|
+
return False
|
|
1061
|
+
return (
|
|
1062
|
+
_inventory_answer_slot(item, query_reason=query_reason).startswith("game_named_")
|
|
1063
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1064
|
+
)
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
def _is_exact_animal_evidence_answer_family(
|
|
1068
|
+
family: str,
|
|
1069
|
+
*,
|
|
1070
|
+
item: ContextItem,
|
|
1071
|
+
) -> bool:
|
|
1072
|
+
return bool(_answer_support_animal_evidence_family_slot(family)) and (
|
|
1073
|
+
_has_any_exact_turn_source_ref(item)
|
|
1074
|
+
)
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
def _is_exact_temporal_query_object_family(
|
|
1078
|
+
family: str,
|
|
1079
|
+
*,
|
|
1080
|
+
item: ContextItem,
|
|
1081
|
+
query: str,
|
|
1082
|
+
) -> bool:
|
|
1083
|
+
query_reason = _answer_support_query_reason(item)
|
|
1084
|
+
base = _diversity_family_base(family)
|
|
1085
|
+
if _is_degree_completion_temporal_answer_support_item(item, query=query):
|
|
1086
|
+
return True
|
|
1087
|
+
if (
|
|
1088
|
+
base
|
|
1089
|
+
in {
|
|
1090
|
+
"query_reason_source_group",
|
|
1091
|
+
"query_reason_activity_slot_source_group",
|
|
1092
|
+
"query_reason_inventory_slot_source_group",
|
|
1093
|
+
}
|
|
1094
|
+
and _answer_support_exact_query_object_hits(item, query=query) > 0
|
|
1095
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1096
|
+
):
|
|
1097
|
+
return True
|
|
1098
|
+
return (
|
|
1099
|
+
_TEMPORAL_ANSWER_SUPPORT_QUERY_RE.search(query) is not None
|
|
1100
|
+
and base in {
|
|
1101
|
+
"temporal_source_sibling_marker",
|
|
1102
|
+
"temporal_source_sibling_marker_source_group",
|
|
1103
|
+
"query_reason_source_group",
|
|
1104
|
+
}
|
|
1105
|
+
and _temporal_answer_support_query_object_hits(
|
|
1106
|
+
item,
|
|
1107
|
+
query=query,
|
|
1108
|
+
query_reason=query_reason,
|
|
1109
|
+
)
|
|
1110
|
+
> 0
|
|
1111
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1112
|
+
)
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
def _is_degree_completion_temporal_answer_support_item(
|
|
1116
|
+
item: ContextItem,
|
|
1117
|
+
*,
|
|
1118
|
+
query: str,
|
|
1119
|
+
) -> bool:
|
|
1120
|
+
if not query:
|
|
1121
|
+
return False
|
|
1122
|
+
if _DEGREE_COMPLETION_TEMPORAL_QUERY_RE.search(query) is None:
|
|
1123
|
+
return False
|
|
1124
|
+
if _answer_support_query_reason(item) != "degree_policy_inference_bridge":
|
|
1125
|
+
return False
|
|
1126
|
+
if _degree_policy_answer_slot(item.text) != "degree_completion_context":
|
|
1127
|
+
return False
|
|
1128
|
+
return _has_any_exact_turn_source_ref(item)
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
def _is_exact_precise_content_answer_support_item(item: ContextItem) -> bool:
|
|
1132
|
+
if not _has_any_exact_turn_source_ref(item):
|
|
1133
|
+
return False
|
|
1134
|
+
query_reason = _answer_support_query_reason(item)
|
|
1135
|
+
if query_reason not in _EXACT_PRECISE_CONTENT_TURN_REASONS:
|
|
1136
|
+
return False
|
|
1137
|
+
return _precise_answer_content_rank(item, query_reason=query_reason) == 0
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
def _is_exact_named_preference_answer_support_item(
|
|
1141
|
+
item: ContextItem,
|
|
1142
|
+
*,
|
|
1143
|
+
query: str,
|
|
1144
|
+
) -> bool:
|
|
1145
|
+
if not query or not _has_any_exact_turn_source_ref(item):
|
|
1146
|
+
return False
|
|
1147
|
+
query_reason = _answer_support_query_reason(item)
|
|
1148
|
+
if query_reason.replace("_", "-") not in {
|
|
1149
|
+
"decomposition-inference-support",
|
|
1150
|
+
"original-query",
|
|
1151
|
+
}:
|
|
1152
|
+
return False
|
|
1153
|
+
if (
|
|
1154
|
+
_numeric_signal(_diagnostic_score_signals(item).get("source_sibling_answer_evidence"))
|
|
1155
|
+
<= 0
|
|
1156
|
+
):
|
|
1157
|
+
return False
|
|
1158
|
+
return is_named_preference_source_sibling_answer_evidence(
|
|
1159
|
+
expansion_query=query,
|
|
1160
|
+
expansion_reason=query_reason,
|
|
1161
|
+
text=item.text,
|
|
1162
|
+
)
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
def _is_exact_place_inference_answer_support_item(
|
|
1166
|
+
item: ContextItem,
|
|
1167
|
+
*,
|
|
1168
|
+
query: str,
|
|
1169
|
+
) -> bool:
|
|
1170
|
+
if not query or not _has_any_exact_turn_source_ref(item):
|
|
1171
|
+
return False
|
|
1172
|
+
query_reason = _answer_support_query_reason(item)
|
|
1173
|
+
return is_place_inference_source_sibling_answer_evidence(
|
|
1174
|
+
expansion_query=query,
|
|
1175
|
+
expansion_reason=query_reason,
|
|
1176
|
+
text=item.text,
|
|
1177
|
+
)
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
def _is_exact_themed_location_inference_answer_support_item(
|
|
1181
|
+
item: ContextItem,
|
|
1182
|
+
*,
|
|
1183
|
+
query: str,
|
|
1184
|
+
) -> bool:
|
|
1185
|
+
if not query or not _has_any_exact_turn_source_ref(item):
|
|
1186
|
+
return False
|
|
1187
|
+
query_reason = _answer_support_query_reason(item)
|
|
1188
|
+
return is_themed_location_source_sibling_answer_evidence(
|
|
1189
|
+
expansion_query=query,
|
|
1190
|
+
expansion_reason=query_reason,
|
|
1191
|
+
text=item.text,
|
|
1192
|
+
)
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
def _is_exact_query_destination_answer_support_item(
|
|
1196
|
+
item: ContextItem,
|
|
1197
|
+
*,
|
|
1198
|
+
query: str,
|
|
1199
|
+
) -> bool:
|
|
1200
|
+
if not query or not _has_any_exact_turn_source_ref(item):
|
|
1201
|
+
return False
|
|
1202
|
+
query_reason = _answer_support_query_reason(item).replace("_", "-")
|
|
1203
|
+
if query_reason not in {
|
|
1204
|
+
"decomposition-inference-support",
|
|
1205
|
+
"original-query",
|
|
1206
|
+
"place-area-inventory-bridge",
|
|
1207
|
+
"themed-location-destination-anchor-bridge",
|
|
1208
|
+
"themed-location-destination-bridge",
|
|
1209
|
+
"travel-country-inventory-bridge",
|
|
1210
|
+
"trip-destination-bridge",
|
|
1211
|
+
}:
|
|
1212
|
+
return False
|
|
1213
|
+
if not query_destination_places(query):
|
|
1214
|
+
return False
|
|
1215
|
+
return is_query_destination_source_sibling_anchor(
|
|
1216
|
+
expansion_query=query,
|
|
1217
|
+
expansion_reason=query_reason,
|
|
1218
|
+
text=item.text,
|
|
1219
|
+
)
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
def _is_exact_country_destination_answer_support_item(
|
|
1223
|
+
item: ContextItem,
|
|
1224
|
+
*,
|
|
1225
|
+
query: str,
|
|
1226
|
+
) -> bool:
|
|
1227
|
+
if not query or not _has_any_exact_turn_source_ref(item):
|
|
1228
|
+
return False
|
|
1229
|
+
return is_country_destination_source_sibling_answer_evidence(
|
|
1230
|
+
expansion_query=query,
|
|
1231
|
+
expansion_reason=_answer_support_query_reason(item),
|
|
1232
|
+
text=item.text,
|
|
1233
|
+
)
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
def _country_destination_answer_support_rank(
|
|
1237
|
+
item: ContextItem,
|
|
1238
|
+
*,
|
|
1239
|
+
query: str,
|
|
1240
|
+
) -> int:
|
|
1241
|
+
if not query:
|
|
1242
|
+
return 5
|
|
1243
|
+
return country_destination_answer_support_rank(
|
|
1244
|
+
expansion_query=query,
|
|
1245
|
+
text=item.text,
|
|
1246
|
+
has_exact_turn=_has_any_exact_turn_source_ref(item),
|
|
1247
|
+
)
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
def _is_exact_business_direct_answer_support_item(item: ContextItem) -> bool:
|
|
1251
|
+
return (
|
|
1252
|
+
_answer_support_query_reason(item)
|
|
1253
|
+
in {"business_commonality_bridge", "business_start_reason_bridge"}
|
|
1254
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1255
|
+
and _business_commonality_answer_content_rank(item.text) == 0
|
|
1256
|
+
)
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
def _is_exact_screenplay_rejection_answer_support_item(item: ContextItem) -> bool:
|
|
1260
|
+
return (
|
|
1261
|
+
_answer_support_query_reason(item) == "screenplay_count_bridge"
|
|
1262
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1263
|
+
and _screenplay_rejection_answer_content_rank(item.text) == 0
|
|
1264
|
+
)
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
def _is_exact_common_interest_answer_support_item(item: ContextItem) -> bool:
|
|
1268
|
+
query_reason = _answer_support_query_reason(item)
|
|
1269
|
+
return (
|
|
1270
|
+
_is_common_interest_answer_reason(query_reason)
|
|
1271
|
+
and _has_primary_exact_turn_source_ref(item)
|
|
1272
|
+
and bool(_common_interest_answer_slot(item, query_reason=query_reason))
|
|
1273
|
+
)
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
def _is_exact_place_area_state_answer_support_item(
|
|
1277
|
+
item: ContextItem,
|
|
1278
|
+
*,
|
|
1279
|
+
query: str,
|
|
1280
|
+
) -> bool:
|
|
1281
|
+
query_reason = _answer_support_query_reason(item)
|
|
1282
|
+
if _is_state_residence_geo_answer_support_item(item, query=query):
|
|
1283
|
+
return True
|
|
1284
|
+
return (
|
|
1285
|
+
_place_area_state_query_applies(query=query, query_reason=query_reason)
|
|
1286
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1287
|
+
and _place_area_state_answer_support_rank(
|
|
1288
|
+
item,
|
|
1289
|
+
query=query,
|
|
1290
|
+
query_reason=query_reason,
|
|
1291
|
+
)
|
|
1292
|
+
== 0
|
|
1293
|
+
)
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
def _is_exact_inspiration_source_answer_support_item(
|
|
1297
|
+
item: ContextItem,
|
|
1298
|
+
*,
|
|
1299
|
+
query: str,
|
|
1300
|
+
) -> bool:
|
|
1301
|
+
return (
|
|
1302
|
+
bool(query and _INSPIRATION_SOURCE_QUERY_RE.search(query))
|
|
1303
|
+
and _has_any_exact_turn_source_ref(item)
|
|
1304
|
+
and _inspiration_source_answer_content_rank(item.text) == 0
|
|
1305
|
+
)
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
def _marker_coverage_source_group_counts(candidates: dict[str, ContextItem]) -> dict[str, int]:
|
|
1309
|
+
counts: dict[str, int] = {}
|
|
1310
|
+
for family in candidates:
|
|
1311
|
+
if _diversity_family_base(family) != "query_reason_marker_coverage_source_group":
|
|
1312
|
+
continue
|
|
1313
|
+
source_group = _marker_coverage_family_source_group(family)
|
|
1314
|
+
if source_group:
|
|
1315
|
+
counts[source_group] = counts.get(source_group, 0) + 1
|
|
1316
|
+
return counts
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
def _broad_turn_source_group_counts(candidates: dict[str, ContextItem]) -> dict[str, int]:
|
|
1320
|
+
counts: dict[str, int] = {}
|
|
1321
|
+
for family in candidates:
|
|
1322
|
+
if _diversity_family_base(family) != "query_reason_broad_turn_source_group":
|
|
1323
|
+
continue
|
|
1324
|
+
source_group = _broad_turn_family_source_group(family)
|
|
1325
|
+
if source_group:
|
|
1326
|
+
counts[source_group] = counts.get(source_group, 0) + 1
|
|
1327
|
+
return counts
|
|
1328
|
+
|
|
1329
|
+
|
|
1330
|
+
def _broad_turn_family_source_group(family: str) -> str:
|
|
1331
|
+
parts = family.split(":")
|
|
1332
|
+
if len(parts) >= 4:
|
|
1333
|
+
return parts[-1]
|
|
1334
|
+
return ""
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
def _pet_acquisition_named_object_source_groups(
|
|
1338
|
+
candidates: dict[str, ContextItem],
|
|
1339
|
+
*,
|
|
1340
|
+
query: str,
|
|
1341
|
+
) -> frozenset[str]:
|
|
1342
|
+
object_terms = _pet_acquisition_named_object_terms(query)
|
|
1343
|
+
if not object_terms:
|
|
1344
|
+
return frozenset()
|
|
1345
|
+
source_groups: set[str] = set()
|
|
1346
|
+
for item in candidates.values():
|
|
1347
|
+
if _answer_support_query_reason(item) != "pet_acquisition_date_bridge":
|
|
1348
|
+
continue
|
|
1349
|
+
source_group = _answer_support_source_group(item)
|
|
1350
|
+
if not source_group:
|
|
1351
|
+
continue
|
|
1352
|
+
text = item.text.casefold()
|
|
1353
|
+
if any(re.search(rf"\b{re.escape(term)}\b", text) for term in object_terms):
|
|
1354
|
+
source_groups.add(source_group)
|
|
1355
|
+
return frozenset(source_groups)
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
def _pet_acquisition_named_object_terms(query: str) -> tuple[str, ...]:
|
|
1359
|
+
terms: list[str] = []
|
|
1360
|
+
for match in _NAMED_ACQUISITION_OBJECT_QUERY_RE.finditer(query):
|
|
1361
|
+
term = match.group("object").strip().casefold()
|
|
1362
|
+
if term and term not in terms:
|
|
1363
|
+
terms.append(term)
|
|
1364
|
+
return tuple(terms)
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
def _marker_coverage_family_source_group(family: str) -> str:
|
|
1368
|
+
parts = family.split(":")
|
|
1369
|
+
if len(parts) >= 4:
|
|
1370
|
+
return parts[-1]
|
|
1371
|
+
return ""
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
def _answer_support_source_group_reason_key(family: str) -> str:
|
|
1375
|
+
parts = family.split(":")
|
|
1376
|
+
if len(parts) < 3 or parts[0] not in {
|
|
1377
|
+
"query_reason_activity_slot_source_group",
|
|
1378
|
+
"query_reason_broad_turn_source_group",
|
|
1379
|
+
"query_reason_career_slot_marker_source_group",
|
|
1380
|
+
"query_reason_career_slot_source_group",
|
|
1381
|
+
"query_reason_common_interest_slot_marker_source_group",
|
|
1382
|
+
"query_reason_common_interest_slot_source_group",
|
|
1383
|
+
"query_reason_count_coverage_source_group",
|
|
1384
|
+
"query_reason_exact_marker_source_group",
|
|
1385
|
+
"query_reason_inference_slot_source_group",
|
|
1386
|
+
"query_reason_inventory_slot_source_group",
|
|
1387
|
+
"query_reason_marker_coverage_source_group",
|
|
1388
|
+
"query_reason_source_group",
|
|
1389
|
+
}:
|
|
1390
|
+
return ""
|
|
1391
|
+
if (
|
|
1392
|
+
parts[0] == "query_reason_activity_slot_source_group"
|
|
1393
|
+
and len(parts) >= 4
|
|
1394
|
+
and (
|
|
1395
|
+
_is_family_activity_reason(parts[1])
|
|
1396
|
+
)
|
|
1397
|
+
):
|
|
1398
|
+
return f"{parts[1]}:{parts[2]}"
|
|
1399
|
+
if parts[0] == "query_reason_inventory_slot_source_group" and len(parts) >= 4:
|
|
1400
|
+
return f"{parts[1]}:{parts[2]}"
|
|
1401
|
+
if (
|
|
1402
|
+
parts[0]
|
|
1403
|
+
in {
|
|
1404
|
+
"query_reason_common_interest_slot_source_group",
|
|
1405
|
+
"query_reason_common_interest_slot_marker_source_group",
|
|
1406
|
+
}
|
|
1407
|
+
and len(parts) >= 4
|
|
1408
|
+
):
|
|
1409
|
+
return f"{parts[1]}:{parts[2]}"
|
|
1410
|
+
return parts[1]
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
def _answer_support_source_group_limit(
|
|
1414
|
+
reason: str,
|
|
1415
|
+
*,
|
|
1416
|
+
family: str,
|
|
1417
|
+
item: ContextItem,
|
|
1418
|
+
) -> int:
|
|
1419
|
+
if _is_count_aggregation_reason(reason):
|
|
1420
|
+
return _MAX_ANSWER_SUPPORT_DIVERSITY_ITEMS
|
|
1421
|
+
normalized_reason = reason.replace("_", "-")
|
|
1422
|
+
base_reason = normalized_reason.split(":", 1)[0]
|
|
1423
|
+
if base_reason in {
|
|
1424
|
+
"cause-event-inventory-bridge",
|
|
1425
|
+
"cause-education-infrastructure-inventory-bridge",
|
|
1426
|
+
"cause-veterans-inventory-bridge",
|
|
1427
|
+
}:
|
|
1428
|
+
return _MAX_ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON
|
|
1429
|
+
if base_reason == "decomposition-inventory-list":
|
|
1430
|
+
parts = normalized_reason.split(":")
|
|
1431
|
+
if len(parts) >= 2 and parts[1] in {
|
|
1432
|
+
"dessert",
|
|
1433
|
+
"dessert-cobbler",
|
|
1434
|
+
"dessert-pie",
|
|
1435
|
+
"dessert-sundae",
|
|
1436
|
+
"animal-shelter",
|
|
1437
|
+
"shelter",
|
|
1438
|
+
"shelter-activity",
|
|
1439
|
+
"shelter-anchor",
|
|
1440
|
+
"shelter-service-activity",
|
|
1441
|
+
}:
|
|
1442
|
+
return _MAX_ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON
|
|
1443
|
+
family_base = _diversity_family_base(family)
|
|
1444
|
+
aggregation_family_bases = {
|
|
1445
|
+
"query_reason_activity_slot_source_group",
|
|
1446
|
+
"query_reason_broad_turn_source_group",
|
|
1447
|
+
"query_reason_career_slot_marker_source_group",
|
|
1448
|
+
"query_reason_career_slot_source_group",
|
|
1449
|
+
"query_reason_common_interest_slot_marker_source_group",
|
|
1450
|
+
"query_reason_common_interest_slot_source_group",
|
|
1451
|
+
"query_reason_count_coverage_source_group",
|
|
1452
|
+
"query_reason_exact_marker_source_group",
|
|
1453
|
+
"query_reason_inference_slot_source_group",
|
|
1454
|
+
"query_reason_inventory_slot_source_group",
|
|
1455
|
+
"query_reason_marker_coverage_source_group",
|
|
1456
|
+
}
|
|
1457
|
+
if (
|
|
1458
|
+
(
|
|
1459
|
+
reason in _ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_REASONS
|
|
1460
|
+
or normalized_reason in _ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_REASONS
|
|
1461
|
+
)
|
|
1462
|
+
and (
|
|
1463
|
+
family_base in aggregation_family_bases
|
|
1464
|
+
or (item.source_refs and family_base == "query_reason_source_group")
|
|
1465
|
+
)
|
|
1466
|
+
):
|
|
1467
|
+
return _MAX_ANSWER_SUPPORT_AGGREGATION_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON
|
|
1468
|
+
if (
|
|
1469
|
+
reason.startswith("decomposition-")
|
|
1470
|
+
and reason.endswith("-event")
|
|
1471
|
+
and reason not in {"decomposition-event-context", "decomposition-event-sequence"}
|
|
1472
|
+
):
|
|
1473
|
+
return _MAX_ANSWER_SUPPORT_EVENT_SLOT_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON
|
|
1474
|
+
return _MAX_ANSWER_SUPPORT_SOURCE_GROUP_DIVERSITY_ITEMS_PER_REASON
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
def _is_count_aggregation_reason(reason: str) -> bool:
|
|
1478
|
+
normalized_reason = reason.replace("-", "_")
|
|
1479
|
+
return reason in _COUNT_AGGREGATION_COVERAGE_REASONS or (
|
|
1480
|
+
normalized_reason in _COUNT_AGGREGATION_COVERAGE_REASONS
|
|
1481
|
+
)
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
def _answer_support_diversity_family(item: ContextItem) -> str:
|
|
1485
|
+
query_reason = _answer_support_query_reason(item)
|
|
1486
|
+
if _is_temporal_answer_support_item(item, query_reason=query_reason):
|
|
1487
|
+
source_group = _answer_support_source_group(item)
|
|
1488
|
+
marker = _primary_exact_turn_marker(item) or _first_dialogue_marker(item.text)
|
|
1489
|
+
if source_group:
|
|
1490
|
+
return _compound_diversity_family(
|
|
1491
|
+
"temporal_source_sibling_marker_source_group",
|
|
1492
|
+
marker or "temporal",
|
|
1493
|
+
source_group,
|
|
1494
|
+
)
|
|
1495
|
+
return _compound_diversity_family(
|
|
1496
|
+
"temporal_source_sibling_marker",
|
|
1497
|
+
marker or item.item_id,
|
|
1498
|
+
)
|
|
1499
|
+
|
|
1500
|
+
if query_reason and query_reason != "original_query":
|
|
1501
|
+
if query_reason in _ANSWER_SUPPORT_EXCLUDED_QUERY_REASONS:
|
|
1502
|
+
return ""
|
|
1503
|
+
source_group = _answer_support_source_group(item)
|
|
1504
|
+
career_slot = _career_answer_slot(item, query_reason=query_reason)
|
|
1505
|
+
activity_slot = _activity_answer_slot(item, query_reason=query_reason)
|
|
1506
|
+
inference_slot = _inference_answer_slot(item, query_reason=query_reason)
|
|
1507
|
+
inventory_slot = _inventory_answer_slot(item, query_reason=query_reason)
|
|
1508
|
+
animal_evidence_slot = _animal_evidence_answer_slot(
|
|
1509
|
+
item,
|
|
1510
|
+
query_reason=query_reason,
|
|
1511
|
+
)
|
|
1512
|
+
common_interest_slot = _common_interest_answer_slot(
|
|
1513
|
+
item,
|
|
1514
|
+
query_reason=query_reason,
|
|
1515
|
+
)
|
|
1516
|
+
exact_support_marker = _exact_answer_support_marker_slot(
|
|
1517
|
+
item,
|
|
1518
|
+
query_reason=query_reason,
|
|
1519
|
+
)
|
|
1520
|
+
if source_group:
|
|
1521
|
+
if exact_support_marker and _exact_marker_should_precede_inventory(
|
|
1522
|
+
item,
|
|
1523
|
+
marker=exact_support_marker,
|
|
1524
|
+
):
|
|
1525
|
+
return _compound_diversity_family(
|
|
1526
|
+
"query_reason_exact_marker_source_group",
|
|
1527
|
+
query_reason,
|
|
1528
|
+
exact_support_marker,
|
|
1529
|
+
source_group,
|
|
1530
|
+
)
|
|
1531
|
+
if broad_turn_slot := _broad_evidence_turn_slot(item, query_reason=query_reason):
|
|
1532
|
+
return _compound_diversity_family(
|
|
1533
|
+
"query_reason_broad_turn_source_group",
|
|
1534
|
+
query_reason,
|
|
1535
|
+
broad_turn_slot,
|
|
1536
|
+
source_group,
|
|
1537
|
+
)
|
|
1538
|
+
if _is_count_aggregation_coverage_item(item, query_reason=query_reason):
|
|
1539
|
+
return _compound_diversity_family(
|
|
1540
|
+
"query_reason_count_coverage_source_group",
|
|
1541
|
+
query_reason,
|
|
1542
|
+
source_group,
|
|
1543
|
+
)
|
|
1544
|
+
if common_interest_slot and not (
|
|
1545
|
+
query_reason == "hobby_interest_bridge" and animal_evidence_slot
|
|
1546
|
+
):
|
|
1547
|
+
marker = _primary_exact_turn_marker(item)
|
|
1548
|
+
if marker:
|
|
1549
|
+
return _compound_diversity_family(
|
|
1550
|
+
"query_reason_common_interest_slot_marker_source_group",
|
|
1551
|
+
query_reason,
|
|
1552
|
+
common_interest_slot,
|
|
1553
|
+
marker,
|
|
1554
|
+
source_group,
|
|
1555
|
+
)
|
|
1556
|
+
return _compound_diversity_family(
|
|
1557
|
+
"query_reason_common_interest_slot_source_group",
|
|
1558
|
+
query_reason,
|
|
1559
|
+
common_interest_slot,
|
|
1560
|
+
source_group,
|
|
1561
|
+
)
|
|
1562
|
+
if animal_evidence_slot:
|
|
1563
|
+
return _compound_diversity_family(
|
|
1564
|
+
"query_reason_animal_evidence_slot_source_group",
|
|
1565
|
+
query_reason,
|
|
1566
|
+
animal_evidence_slot,
|
|
1567
|
+
source_group,
|
|
1568
|
+
)
|
|
1569
|
+
if inventory_slot and _inventory_slot_precedes_marker_coverage(
|
|
1570
|
+
inventory_slot,
|
|
1571
|
+
):
|
|
1572
|
+
return _compound_diversity_family(
|
|
1573
|
+
"query_reason_inventory_slot_source_group",
|
|
1574
|
+
query_reason,
|
|
1575
|
+
inventory_slot,
|
|
1576
|
+
source_group,
|
|
1577
|
+
)
|
|
1578
|
+
if marker_slot := _aggregation_marker_coverage_slot(
|
|
1579
|
+
item,
|
|
1580
|
+
query_reason=query_reason,
|
|
1581
|
+
):
|
|
1582
|
+
return _compound_diversity_family(
|
|
1583
|
+
"query_reason_marker_coverage_source_group",
|
|
1584
|
+
query_reason,
|
|
1585
|
+
marker_slot,
|
|
1586
|
+
source_group,
|
|
1587
|
+
)
|
|
1588
|
+
if inventory_slot:
|
|
1589
|
+
return _compound_diversity_family(
|
|
1590
|
+
"query_reason_inventory_slot_source_group",
|
|
1591
|
+
query_reason,
|
|
1592
|
+
inventory_slot,
|
|
1593
|
+
source_group,
|
|
1594
|
+
)
|
|
1595
|
+
if exact_support_marker:
|
|
1596
|
+
return _compound_diversity_family(
|
|
1597
|
+
"query_reason_exact_marker_source_group",
|
|
1598
|
+
query_reason,
|
|
1599
|
+
exact_support_marker,
|
|
1600
|
+
source_group,
|
|
1601
|
+
)
|
|
1602
|
+
if activity_slot:
|
|
1603
|
+
return _compound_diversity_family(
|
|
1604
|
+
"query_reason_activity_slot_source_group",
|
|
1605
|
+
query_reason,
|
|
1606
|
+
activity_slot,
|
|
1607
|
+
source_group,
|
|
1608
|
+
)
|
|
1609
|
+
if career_slot:
|
|
1610
|
+
marker = _primary_exact_turn_marker(item)
|
|
1611
|
+
if marker and not _is_business_commonality_reason(query_reason):
|
|
1612
|
+
return _compound_diversity_family(
|
|
1613
|
+
"query_reason_career_slot_marker_source_group",
|
|
1614
|
+
query_reason,
|
|
1615
|
+
career_slot,
|
|
1616
|
+
marker,
|
|
1617
|
+
source_group,
|
|
1618
|
+
)
|
|
1619
|
+
return _compound_diversity_family(
|
|
1620
|
+
"query_reason_career_slot_source_group",
|
|
1621
|
+
query_reason,
|
|
1622
|
+
career_slot,
|
|
1623
|
+
source_group,
|
|
1624
|
+
)
|
|
1625
|
+
if inference_slot:
|
|
1626
|
+
return _compound_diversity_family(
|
|
1627
|
+
"query_reason_inference_slot_source_group",
|
|
1628
|
+
query_reason,
|
|
1629
|
+
inference_slot,
|
|
1630
|
+
source_group,
|
|
1631
|
+
)
|
|
1632
|
+
if _diagnostic_signal_truthy(item, "source_sibling_dialogue_visual_reference"):
|
|
1633
|
+
return _compound_diversity_family(
|
|
1634
|
+
"query_reason_source_group_visual_reference",
|
|
1635
|
+
query_reason,
|
|
1636
|
+
source_group,
|
|
1637
|
+
)
|
|
1638
|
+
return _compound_diversity_family(
|
|
1639
|
+
"query_reason_source_group",
|
|
1640
|
+
query_reason,
|
|
1641
|
+
source_group,
|
|
1642
|
+
)
|
|
1643
|
+
if activity_slot:
|
|
1644
|
+
return _compound_diversity_family(
|
|
1645
|
+
"query_reason_activity_slot",
|
|
1646
|
+
query_reason,
|
|
1647
|
+
activity_slot,
|
|
1648
|
+
)
|
|
1649
|
+
if common_interest_slot and not (
|
|
1650
|
+
query_reason == "hobby_interest_bridge" and animal_evidence_slot
|
|
1651
|
+
):
|
|
1652
|
+
return _compound_diversity_family(
|
|
1653
|
+
"query_reason_common_interest_slot",
|
|
1654
|
+
query_reason,
|
|
1655
|
+
common_interest_slot,
|
|
1656
|
+
)
|
|
1657
|
+
if animal_evidence_slot:
|
|
1658
|
+
return _compound_diversity_family(
|
|
1659
|
+
"query_reason_animal_evidence_slot",
|
|
1660
|
+
query_reason,
|
|
1661
|
+
animal_evidence_slot,
|
|
1662
|
+
)
|
|
1663
|
+
if inventory_slot:
|
|
1664
|
+
return _compound_diversity_family(
|
|
1665
|
+
"query_reason_inventory_slot",
|
|
1666
|
+
query_reason,
|
|
1667
|
+
inventory_slot,
|
|
1668
|
+
)
|
|
1669
|
+
if career_slot:
|
|
1670
|
+
return _compound_diversity_family(
|
|
1671
|
+
"query_reason_career_slot",
|
|
1672
|
+
query_reason,
|
|
1673
|
+
career_slot,
|
|
1674
|
+
)
|
|
1675
|
+
if inference_slot:
|
|
1676
|
+
return _compound_diversity_family(
|
|
1677
|
+
"query_reason_inference_slot",
|
|
1678
|
+
query_reason,
|
|
1679
|
+
inference_slot,
|
|
1680
|
+
)
|
|
1681
|
+
return _typed_diversity_family("query_reason", query_reason)
|
|
1682
|
+
if (
|
|
1683
|
+
_has_any_exact_turn_source_ref(item)
|
|
1684
|
+
and _numeric_signal(
|
|
1685
|
+
_diagnostic_score_signals(item).get("source_sibling_answer_evidence")
|
|
1686
|
+
)
|
|
1687
|
+
> 0
|
|
1688
|
+
):
|
|
1689
|
+
source_group = _answer_support_source_group(item)
|
|
1690
|
+
if source_group:
|
|
1691
|
+
return _compound_diversity_family(
|
|
1692
|
+
"query_reason_source_group",
|
|
1693
|
+
"source_sibling_answer_evidence",
|
|
1694
|
+
source_group,
|
|
1695
|
+
)
|
|
1696
|
+
matched_anchor_kinds = _diagnostic_list(item, "context_requirement_matched_anchor_kinds")
|
|
1697
|
+
if matched_anchor_kinds:
|
|
1698
|
+
return _typed_diversity_family("requirement_anchor", matched_anchor_kinds[0])
|
|
1699
|
+
|
|
1700
|
+
matched_modalities = _diagnostic_list(item, "context_requirement_matched_modalities")
|
|
1701
|
+
if matched_modalities:
|
|
1702
|
+
return _typed_diversity_family("requirement_modality", matched_modalities[0])
|
|
1703
|
+
|
|
1704
|
+
if _is_weak_vector_requirement_candidate(item):
|
|
1705
|
+
return ""
|
|
1706
|
+
|
|
1707
|
+
matched_features = _diagnostic_list(item, "context_requirement_matched_evidence_features")
|
|
1708
|
+
if matched_features:
|
|
1709
|
+
return _typed_diversity_family("requirement_feature", matched_features[0])
|
|
1710
|
+
|
|
1711
|
+
return ""
|
|
1712
|
+
|
|
1713
|
+
|
|
1714
|
+
def _inventory_slot_precedes_marker_coverage(slot: str) -> bool:
|
|
1715
|
+
return slot in {
|
|
1716
|
+
"game_win_result",
|
|
1717
|
+
"gratitude_note_writer",
|
|
1718
|
+
"shelter_food_dropoff",
|
|
1719
|
+
"skill_game_coaching",
|
|
1720
|
+
"skill_recipe_teaching",
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
|
|
1724
|
+
def _is_weak_vector_requirement_candidate(item: ContextItem) -> bool:
|
|
1725
|
+
retrieval_sources = set(diagnostic_retrieval_sources(item.diagnostics))
|
|
1726
|
+
if retrieval_sources != {"vector_chunks"}:
|
|
1727
|
+
return False
|
|
1728
|
+
signals = _diagnostic_score_signals(item)
|
|
1729
|
+
return (
|
|
1730
|
+
_numeric_signal(signals.get("unique_term_hits")) <= 0
|
|
1731
|
+
and _numeric_signal(signals.get("distinctive_term_hits")) <= 0
|
|
1732
|
+
and _numeric_signal(signals.get("phrase_bigram_hits")) <= 0
|
|
1733
|
+
)
|
|
1734
|
+
|
|
1735
|
+
|
|
1736
|
+
def _first_dialogue_marker(text: str) -> str:
|
|
1737
|
+
match = _DIALOGUE_MARKER_RE.search(text)
|
|
1738
|
+
return match.group(0) if match is not None else ""
|
|
1739
|
+
def _primary_exact_turn_marker(item: ContextItem) -> str:
|
|
1740
|
+
source_id = _primary_exact_turn_source_id(item)
|
|
1741
|
+
match = _DIALOGUE_MARKER_RE.search(source_id)
|
|
1742
|
+
return match.group(0) if match is not None else ""
|
|
1743
|
+
def _exact_marker_should_precede_inventory(item: ContextItem, *, marker: str) -> bool:
|
|
1744
|
+
if len(item.source_refs) != 1:
|
|
1745
|
+
return False
|
|
1746
|
+
first_marker = _first_dialogue_marker(item.text)
|
|
1747
|
+
return bool(first_marker and marker and first_marker != marker)
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
def _answer_support_query_reason(item: ContextItem) -> str:
|
|
1751
|
+
query_reason = _diagnostic_signal_text(item, "query_expansion_reason")
|
|
1752
|
+
deterministic_reason = _diagnostic_signal_text(item, "deterministic_rerank_query_reason")
|
|
1753
|
+
if (
|
|
1754
|
+
deterministic_reason
|
|
1755
|
+
and deterministic_reason != "original_query"
|
|
1756
|
+
and query_reason
|
|
1757
|
+
in {
|
|
1758
|
+
"decomposition_evidence_reason",
|
|
1759
|
+
"decomposition_inference_support",
|
|
1760
|
+
}
|
|
1761
|
+
):
|
|
1762
|
+
return deterministic_reason
|
|
1763
|
+
return (
|
|
1764
|
+
query_reason
|
|
1765
|
+
or _diagnostic_signal_text(item, "bm25_lexical_query_reason")
|
|
1766
|
+
or deterministic_reason
|
|
1767
|
+
)
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
def _answer_support_source_group(item: ContextItem) -> str:
|
|
1771
|
+
aggregation_source_group = _diagnostic_text(item, "keyword_aggregation_source_group")
|
|
1772
|
+
if aggregation_source_group:
|
|
1773
|
+
return aggregation_source_group
|
|
1774
|
+
if set(diagnostic_retrieval_sources(item.diagnostics)).intersection(
|
|
1775
|
+
{
|
|
1776
|
+
"keyword_aggregation_chunks",
|
|
1777
|
+
"keyword_source_sibling_chunks",
|
|
1778
|
+
}
|
|
1779
|
+
):
|
|
1780
|
+
return _source_group_key(item)
|
|
1781
|
+
if _has_derived_source_group_ref(item):
|
|
1782
|
+
return _source_group_key(item)
|
|
1783
|
+
return ""
|
|
1784
|
+
|
|
1785
|
+
|
|
1786
|
+
def _exact_answer_support_marker_slot(item: ContextItem, *, query_reason: str) -> str:
|
|
1787
|
+
if not _is_pottery_type_reason(query_reason):
|
|
1788
|
+
return ""
|
|
1789
|
+
if (
|
|
1790
|
+
_numeric_signal(_diagnostic_score_signals(item).get("source_sibling_answer_evidence")) <= 0
|
|
1791
|
+
and "keyword_source_sibling_chunks" not in diagnostic_retrieval_sources(item.diagnostics)
|
|
1792
|
+
):
|
|
1793
|
+
return ""
|
|
1794
|
+
marker = _primary_exact_turn_marker(item)
|
|
1795
|
+
if not marker:
|
|
1796
|
+
return ""
|
|
1797
|
+
if re.search(rf"\b{re.escape(marker)}\b", item.text) is None:
|
|
1798
|
+
return ""
|
|
1799
|
+
return marker
|
|
1800
|
+
|
|
1801
|
+
def _has_derived_source_group_ref(item: ContextItem) -> bool:
|
|
1802
|
+
if not item.source_refs:
|
|
1803
|
+
return False
|
|
1804
|
+
source_group_key = _source_group_key(item)
|
|
1805
|
+
return source_group_key != _source_key(item)
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
def _is_exact_cause_inventory_answer_support_item(item: ContextItem) -> bool:
|
|
1809
|
+
if not _has_any_exact_turn_source_ref(item):
|
|
1810
|
+
return False
|
|
1811
|
+
return _is_cause_inventory_answer_support_item(item)
|
|
1812
|
+
|
|
1813
|
+
|
|
1814
|
+
def _is_single_exact_cause_inventory_answer_support_item(item: ContextItem) -> bool:
|
|
1815
|
+
return (
|
|
1816
|
+
len(item.source_refs) == 1
|
|
1817
|
+
and _has_primary_exact_turn_source_ref(item)
|
|
1818
|
+
and _is_cause_inventory_answer_support_item(item)
|
|
1819
|
+
)
|
|
1820
|
+
|
|
1821
|
+
|
|
1822
|
+
def _is_cause_inventory_answer_support_item(item: ContextItem) -> bool:
|
|
1823
|
+
query_reason = _answer_support_query_reason(item)
|
|
1824
|
+
if query_reason not in {
|
|
1825
|
+
"cause_event_inventory_bridge",
|
|
1826
|
+
"cause_education_infrastructure_inventory_bridge",
|
|
1827
|
+
"cause_veterans_inventory_bridge",
|
|
1828
|
+
}:
|
|
1829
|
+
return False
|
|
1830
|
+
return bool(_inventory_answer_slot(item, query_reason=query_reason))
|
|
1831
|
+
|
|
1832
|
+
|
|
1833
|
+
def _answer_support_family_item_key(item: ContextItem) -> tuple[float | int | str, ...]:
|
|
1834
|
+
return _answer_support_family_item_key_for_query(item, query="")
|
|
1835
|
+
|
|
1836
|
+
|
|
1837
|
+
def _answer_support_family_item_key_for_query(
|
|
1838
|
+
item: ContextItem,
|
|
1839
|
+
*,
|
|
1840
|
+
query: str,
|
|
1841
|
+
) -> tuple[float | int | str, ...]:
|
|
1842
|
+
signals = _diagnostic_score_signals(item)
|
|
1843
|
+
query_reason = _answer_support_query_reason(item)
|
|
1844
|
+
if _is_count_aggregation_coverage_item(item, query_reason=query_reason):
|
|
1845
|
+
signal_rank = (
|
|
1846
|
+
-_numeric_signal(signals.get("item_purchase_object_evidence")),
|
|
1847
|
+
-_numeric_signal(signals.get("symbol_importance_visual_evidence")),
|
|
1848
|
+
-_numeric_signal(signals.get("friend_place_shelter_anchor_evidence")),
|
|
1849
|
+
-_numeric_signal(signals.get("cause_awareness_answer_evidence")),
|
|
1850
|
+
-_numeric_signal(signals.get("choice_reason_answer_evidence")),
|
|
1851
|
+
-_numeric_signal(signals.get("future_plan_timing_answer_evidence")),
|
|
1852
|
+
-_numeric_signal(signals.get("birdwatching_city_schedule_answer_evidence")),
|
|
1853
|
+
-_numeric_signal(signals.get("source_sibling_answer_evidence")),
|
|
1854
|
+
-_numeric_signal(signals.get("distinctive_term_hits")),
|
|
1855
|
+
-_numeric_signal(signals.get("phrase_bigram_hits")),
|
|
1856
|
+
)
|
|
1857
|
+
else:
|
|
1858
|
+
signal_rank = (
|
|
1859
|
+
-_numeric_signal(signals.get("item_purchase_object_evidence")),
|
|
1860
|
+
-_numeric_signal(signals.get("symbol_importance_visual_evidence")),
|
|
1861
|
+
-_numeric_signal(signals.get("friend_place_shelter_anchor_evidence")),
|
|
1862
|
+
-_numeric_signal(signals.get("cause_awareness_answer_evidence")),
|
|
1863
|
+
-_numeric_signal(signals.get("choice_reason_answer_evidence")),
|
|
1864
|
+
-_numeric_signal(signals.get("future_plan_timing_answer_evidence")),
|
|
1865
|
+
-_numeric_signal(signals.get("birdwatching_city_schedule_answer_evidence")),
|
|
1866
|
+
-_numeric_signal(signals.get("source_sibling_answer_evidence")),
|
|
1867
|
+
-_numeric_signal(signals.get("phrase_bigram_hits")),
|
|
1868
|
+
-_numeric_signal(signals.get("distinctive_term_hits")),
|
|
1869
|
+
)
|
|
1870
|
+
exact_alignment_slot = _inventory_answer_slot(item, query_reason=query_reason)
|
|
1871
|
+
exact_alignment_slot_detector = _inventory_answer_slot_for_text
|
|
1872
|
+
if not exact_alignment_slot:
|
|
1873
|
+
exact_alignment_slot = _animal_evidence_answer_slot(
|
|
1874
|
+
item,
|
|
1875
|
+
query_reason=query_reason,
|
|
1876
|
+
)
|
|
1877
|
+
|
|
1878
|
+
def exact_alignment_slot_detector(text: str) -> str:
|
|
1879
|
+
return _animal_evidence_slot_for_text(
|
|
1880
|
+
text,
|
|
1881
|
+
query_reason=query_reason,
|
|
1882
|
+
)
|
|
1883
|
+
|
|
1884
|
+
return (
|
|
1885
|
+
_degree_completion_temporal_answer_support_rank(item, query=query),
|
|
1886
|
+
_common_interest_animal_answer_shape_rank(
|
|
1887
|
+
item,
|
|
1888
|
+
query=query,
|
|
1889
|
+
query_reason=query_reason,
|
|
1890
|
+
),
|
|
1891
|
+
_common_interest_direct_evidence_rank(
|
|
1892
|
+
item,
|
|
1893
|
+
query_reason=query_reason,
|
|
1894
|
+
),
|
|
1895
|
+
_common_interest_movie_seen_query_rank(
|
|
1896
|
+
item,
|
|
1897
|
+
query=query,
|
|
1898
|
+
query_reason=query_reason,
|
|
1899
|
+
),
|
|
1900
|
+
_common_interest_first_mention_rank(
|
|
1901
|
+
item,
|
|
1902
|
+
query=query,
|
|
1903
|
+
query_reason=query_reason,
|
|
1904
|
+
),
|
|
1905
|
+
_shared_volunteering_first_mention_rank(
|
|
1906
|
+
item,
|
|
1907
|
+
query=query,
|
|
1908
|
+
query_reason=query_reason,
|
|
1909
|
+
),
|
|
1910
|
+
_recognition_award_visual_answer_rank(
|
|
1911
|
+
item,
|
|
1912
|
+
query=query,
|
|
1913
|
+
query_reason=query_reason,
|
|
1914
|
+
),
|
|
1915
|
+
_activity_competition_visual_answer_rank(
|
|
1916
|
+
item,
|
|
1917
|
+
query=query,
|
|
1918
|
+
query_reason=query_reason,
|
|
1919
|
+
),
|
|
1920
|
+
recommendation_list_answer_support_rank(
|
|
1921
|
+
text=item.text,
|
|
1922
|
+
query_reason=query_reason,
|
|
1923
|
+
),
|
|
1924
|
+
recommendation_role_alignment_rank(
|
|
1925
|
+
text=item.text,
|
|
1926
|
+
query=query,
|
|
1927
|
+
query_reason=query_reason,
|
|
1928
|
+
),
|
|
1929
|
+
_relationship_status_answer_support_rank(
|
|
1930
|
+
item,
|
|
1931
|
+
query=query,
|
|
1932
|
+
query_reason=query_reason,
|
|
1933
|
+
),
|
|
1934
|
+
food_inventory_answer_support_rank(
|
|
1935
|
+
text=item.text,
|
|
1936
|
+
query=query,
|
|
1937
|
+
query_reason=query_reason,
|
|
1938
|
+
has_exact_turn=_has_any_exact_turn_source_ref(item),
|
|
1939
|
+
),
|
|
1940
|
+
food_inventory_role_alignment_rank(
|
|
1941
|
+
text=item.text,
|
|
1942
|
+
query=query,
|
|
1943
|
+
query_reason=query_reason,
|
|
1944
|
+
),
|
|
1945
|
+
_career_exact_turn_answer_support_rank(item, query_reason=query_reason),
|
|
1946
|
+
-_answer_support_exact_query_object_hits(item, query=query),
|
|
1947
|
+
_answer_support_exact_turn_alignment_rank(
|
|
1948
|
+
text=item.text,
|
|
1949
|
+
source_ids=tuple(str(ref.source_id) for ref in item.source_refs),
|
|
1950
|
+
inventory_slot=exact_alignment_slot,
|
|
1951
|
+
slot_detector=exact_alignment_slot_detector,
|
|
1952
|
+
query_reason=query_reason,
|
|
1953
|
+
),
|
|
1954
|
+
_place_area_state_answer_support_rank(
|
|
1955
|
+
item,
|
|
1956
|
+
query=query,
|
|
1957
|
+
query_reason=query_reason,
|
|
1958
|
+
),
|
|
1959
|
+
_country_destination_answer_support_rank(item, query=query),
|
|
1960
|
+
_state_residence_answer_support_rank(
|
|
1961
|
+
item,
|
|
1962
|
+
query=query,
|
|
1963
|
+
query_reason=query_reason,
|
|
1964
|
+
),
|
|
1965
|
+
_business_dialogue_marker_answer_support_rank(item, query_reason=query_reason),
|
|
1966
|
+
_common_interest_answer_support_rank(item, query_reason=query_reason),
|
|
1967
|
+
_precise_turn_answer_support_rank(item, query_reason=query_reason),
|
|
1968
|
+
_pet_acquisition_date_anchor_answer_support_rank(
|
|
1969
|
+
item,
|
|
1970
|
+
query_reason=query_reason,
|
|
1971
|
+
),
|
|
1972
|
+
_precise_answer_content_rank(item, query_reason=query_reason),
|
|
1973
|
+
_answer_object_rank(item, query_reason=query_reason),
|
|
1974
|
+
_marker_coverage_answer_support_rank(item, query_reason=query_reason),
|
|
1975
|
+
_birdwatching_city_schedule_exact_turn_rank(item, query_reason=query_reason),
|
|
1976
|
+
-_temporal_answer_support_query_object_hits(
|
|
1977
|
+
item,
|
|
1978
|
+
query=query,
|
|
1979
|
+
query_reason=query_reason,
|
|
1980
|
+
),
|
|
1981
|
+
_temporal_answer_support_source_span_rank(item, query_reason=query_reason),
|
|
1982
|
+
_inventory_first_mention_rank(
|
|
1983
|
+
source_id=_primary_exact_turn_source_id(item),
|
|
1984
|
+
query=query,
|
|
1985
|
+
enabled=(
|
|
1986
|
+
_is_community_participation_reason(query_reason)
|
|
1987
|
+
or _is_business_commonality_reason(query_reason)
|
|
1988
|
+
or (
|
|
1989
|
+
query_reason.replace("_", "-") == "destress-activity-bridge"
|
|
1990
|
+
and _precise_answer_content_rank(item, query_reason=query_reason) == 0
|
|
1991
|
+
)
|
|
1992
|
+
),
|
|
1993
|
+
),
|
|
1994
|
+
-len(item.source_refs),
|
|
1995
|
+
*signal_rank,
|
|
1996
|
+
-len(diagnostic_retrieval_sources(item.diagnostics)),
|
|
1997
|
+
context_rank_key(item),
|
|
1998
|
+
)
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
def _common_interest_first_mention_rank(
|
|
2002
|
+
item: ContextItem,
|
|
2003
|
+
*,
|
|
2004
|
+
query: str,
|
|
2005
|
+
query_reason: str,
|
|
2006
|
+
) -> tuple[int, int]:
|
|
2007
|
+
return _inventory_first_mention_rank(
|
|
2008
|
+
source_id=_primary_exact_turn_source_id(item),
|
|
2009
|
+
query=query,
|
|
2010
|
+
enabled=(
|
|
2011
|
+
_is_common_interest_answer_reason(query_reason)
|
|
2012
|
+
and _is_exact_common_interest_answer_support_item(item)
|
|
2013
|
+
),
|
|
2014
|
+
)
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
def _shared_volunteering_first_mention_rank(
|
|
2018
|
+
item: ContextItem,
|
|
2019
|
+
*,
|
|
2020
|
+
query: str,
|
|
2021
|
+
query_reason: str,
|
|
2022
|
+
) -> tuple[int, int]:
|
|
2023
|
+
if (
|
|
2024
|
+
query_reason.replace("_", "-") not in _SHARED_VOLUNTEERING_QUERY_REASONS
|
|
2025
|
+
or _EN_SHARED_VOLUNTEERING_QUERY_RE.search(query) is None
|
|
2026
|
+
):
|
|
2027
|
+
return _NEUTRAL_FIRST_MENTION_RANK
|
|
2028
|
+
slot = _inventory_answer_slot(item, query_reason=query_reason).replace("-", "_")
|
|
2029
|
+
if slot not in _SHARED_VOLUNTEERING_FIRST_MENTION_SLOTS:
|
|
2030
|
+
return _NEUTRAL_FIRST_MENTION_RANK
|
|
2031
|
+
return _inventory_first_mention_rank(
|
|
2032
|
+
source_id=_primary_exact_turn_source_id(item),
|
|
2033
|
+
query=query,
|
|
2034
|
+
enabled=True,
|
|
2035
|
+
)
|
|
2036
|
+
|
|
2037
|
+
|
|
2038
|
+
def _career_exact_turn_answer_support_rank(
|
|
2039
|
+
item: ContextItem,
|
|
2040
|
+
*,
|
|
2041
|
+
query_reason: str,
|
|
2042
|
+
) -> int:
|
|
2043
|
+
if not _career_answer_slot(item, query_reason=query_reason):
|
|
2044
|
+
return 0
|
|
2045
|
+
if _has_primary_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
2046
|
+
return 0
|
|
2047
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2048
|
+
return 1
|
|
2049
|
+
return 2
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
def _recognition_award_visual_answer_rank(
|
|
2053
|
+
item: ContextItem,
|
|
2054
|
+
*,
|
|
2055
|
+
query: str,
|
|
2056
|
+
query_reason: str,
|
|
2057
|
+
) -> int:
|
|
2058
|
+
if query_reason != "recognition_award_bridge":
|
|
2059
|
+
return 1
|
|
2060
|
+
if _RECOGNITION_CERTIFICATE_QUERY_RE.search(query) is None:
|
|
2061
|
+
return 1
|
|
2062
|
+
if not _has_any_exact_turn_source_ref(item):
|
|
2063
|
+
return 1
|
|
2064
|
+
return 0 if _RECOGNITION_CERTIFICATE_VISUAL_ANSWER_RE.search(item.text) else 1
|
|
2065
|
+
|
|
2066
|
+
|
|
2067
|
+
def _common_interest_movie_seen_query_rank(
|
|
2068
|
+
item: ContextItem,
|
|
2069
|
+
*,
|
|
2070
|
+
query: str,
|
|
2071
|
+
query_reason: str,
|
|
2072
|
+
) -> int:
|
|
2073
|
+
if not (
|
|
2074
|
+
_is_common_interest_answer_reason(query_reason)
|
|
2075
|
+
and _COMMON_INTEREST_MOVIE_SEEN_QUERY_RE.search(query) is not None
|
|
2076
|
+
):
|
|
2077
|
+
return 0
|
|
2078
|
+
text = item.text
|
|
2079
|
+
if _COMMON_INTEREST_MOVIE_SEEN_SLOT_RE.search(text) is not None:
|
|
2080
|
+
return 0
|
|
2081
|
+
if _COMMON_INTEREST_MOVIE_QUESTION_ONLY_RE.search(text) is not None:
|
|
2082
|
+
return 4
|
|
2083
|
+
if _COMMON_INTEREST_MOVIE_SLOT_RE.search(text) is not None:
|
|
2084
|
+
return 2
|
|
2085
|
+
return 5
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
_COMMON_INTEREST_ANIMAL_ANSWER_QUERY_RE = re.compile(
|
|
2089
|
+
r"\b(?:what|which)\s+animals?\b|"
|
|
2090
|
+
r"\banimals?\b(?=.{0,140}\b(?:both|same|shared|share|like|likes|"
|
|
2091
|
+
r"love|loves|enjoy|enjoys|prefer|prefers)\b)|"
|
|
2092
|
+
r"\b(?:both|same|shared|share|like|likes|love|loves|enjoy|enjoys|"
|
|
2093
|
+
r"prefer|prefers)\b(?=.{0,140}\banimals?\b)",
|
|
2094
|
+
re.IGNORECASE | re.DOTALL,
|
|
2095
|
+
)
|
|
2096
|
+
_COMMON_INTEREST_EXPLICIT_ANIMAL_CHOICE_RE = re.compile(
|
|
2097
|
+
r"\b(?:drawn\s+to|chose|choose|chooses|like|likes|love|loves|"
|
|
2098
|
+
r"enjoy|enjoys|prefer|prefers)\s+(?:the\s+|these\s+|those\s+|my\s+|"
|
|
2099
|
+
r"their\s+|a\s+|an\s+)?(?:turtles?|pets?|animals?|reptiles?)\b|"
|
|
2100
|
+
r"\b(?:turtles?|pets?|animals?|reptiles?)\b"
|
|
2101
|
+
r"(?=.{0,180}\b(?:drawn|unique|slow\s+pace|low[-\s]?maintenance|"
|
|
2102
|
+
r"calming|calm|love|loves|like|likes|enjoy|enjoys|prefer|prefers)\b)",
|
|
2103
|
+
re.IGNORECASE | re.DOTALL,
|
|
2104
|
+
)
|
|
2105
|
+
_COMMON_INTEREST_ANIMAL_FALSE_FRIEND_RE = re.compile(
|
|
2106
|
+
r"\banimals?\s+like\b|"
|
|
2107
|
+
r"\bother\s+animals?\b(?=.{0,120}\b(?:consider|allerg(?:y|ic)|"
|
|
2108
|
+
r"pictures?|pics?)\b)|"
|
|
2109
|
+
r"\b(?:send|sending)\s+(?:you\s+)?(?:pictures?|pics?)\b",
|
|
2110
|
+
re.IGNORECASE | re.DOTALL,
|
|
2111
|
+
)
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
def _common_interest_animal_answer_shape_rank(
|
|
2115
|
+
item: ContextItem,
|
|
2116
|
+
*,
|
|
2117
|
+
query: str,
|
|
2118
|
+
query_reason: str,
|
|
2119
|
+
) -> int:
|
|
2120
|
+
if not (
|
|
2121
|
+
_is_common_interest_answer_reason(query_reason)
|
|
2122
|
+
and query
|
|
2123
|
+
and _COMMON_INTEREST_ANIMAL_ANSWER_QUERY_RE.search(query) is not None
|
|
2124
|
+
):
|
|
2125
|
+
return 0
|
|
2126
|
+
text = item.text
|
|
2127
|
+
if _COMMON_INTEREST_ANIMAL_FALSE_FRIEND_RE.search(text) is not None:
|
|
2128
|
+
return 4
|
|
2129
|
+
if _COMMON_INTEREST_EXPLICIT_ANIMAL_CHOICE_RE.search(text) is not None:
|
|
2130
|
+
return 0
|
|
2131
|
+
if _COMMON_INTEREST_INSPIRATIONAL_AFFINITY_SLOT_RE.search(text) is not None:
|
|
2132
|
+
return 1
|
|
2133
|
+
if _COMMON_INTEREST_ANIMAL_AFFINITY_SLOT_RE.search(text) is not None:
|
|
2134
|
+
return 2
|
|
2135
|
+
return 5
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
_ACTIVITY_COMPETITION_VISUAL_QUERY_RE = re.compile(
|
|
2139
|
+
r"\b(?:dancers?|photo|picture|image|dance\s+festival|festival|"
|
|
2140
|
+
r"attitude|participat(?:e|ing)|part\s+of)\b",
|
|
2141
|
+
re.IGNORECASE,
|
|
2142
|
+
)
|
|
2143
|
+
_ACTIVITY_COMPETITION_ATTITUDE_QUERY_RE = re.compile(
|
|
2144
|
+
r"\b(?:attitude|participat(?:e|ing)|part\s+of)\b",
|
|
2145
|
+
re.IGNORECASE,
|
|
2146
|
+
)
|
|
2147
|
+
_ACTIVITY_COMPETITION_DANCER_REPLY_RE = re.compile(
|
|
2148
|
+
r"\b(?:dancers?|they(?:'re| are)|ones?)\b"
|
|
2149
|
+
r"(?=.{0,220}\b(?:perform(?:ing|ance)?|grace|graceful|"
|
|
2150
|
+
r"skill|practic(?:e|ed|ing)|impress)\b)",
|
|
2151
|
+
re.IGNORECASE | re.DOTALL,
|
|
2152
|
+
)
|
|
2153
|
+
_ACTIVITY_COMPETITION_ATTITUDE_REPLY_RE = re.compile(
|
|
2154
|
+
r"\b(?:glad\s+to\s+be\s+part\s+of\s+it|part\s+of\s+it|"
|
|
2155
|
+
r"awesome|excited)\b",
|
|
2156
|
+
re.IGNORECASE | re.DOTALL,
|
|
2157
|
+
)
|
|
2158
|
+
_ACTIVITY_COMPETITION_VISUAL_ANSWER_RE = re.compile(
|
|
2159
|
+
r"\b(?:dancers?|dance|festival|perform(?:ing|ance)?|stage)\b"
|
|
2160
|
+
r"(?=.{0,260}\b(?:photo|picture|image\s+caption|visual\s+query|"
|
|
2161
|
+
r"grace|graceful|skill|practic(?:e|ed|ing)|impress|part\s+of\s+it|"
|
|
2162
|
+
r"glad|awesome|excited|memories|grand\s+opening)\b)",
|
|
2163
|
+
re.IGNORECASE | re.DOTALL,
|
|
2164
|
+
)
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
def _activity_competition_visual_answer_rank(
|
|
2168
|
+
item: ContextItem,
|
|
2169
|
+
*,
|
|
2170
|
+
query: str,
|
|
2171
|
+
query_reason: str,
|
|
2172
|
+
) -> int:
|
|
2173
|
+
if query_reason != "activity_competition_evidence_bridge":
|
|
2174
|
+
return 0
|
|
2175
|
+
if not query or _ACTIVITY_COMPETITION_VISUAL_QUERY_RE.search(query) is None:
|
|
2176
|
+
return 0
|
|
2177
|
+
if _ACTIVITY_COMPETITION_ATTITUDE_QUERY_RE.search(query) is not None:
|
|
2178
|
+
if _ACTIVITY_COMPETITION_ATTITUDE_REPLY_RE.search(item.text) is not None:
|
|
2179
|
+
return 0
|
|
2180
|
+
if _ACTIVITY_COMPETITION_VISUAL_ANSWER_RE.search(item.text) is not None:
|
|
2181
|
+
return 2
|
|
2182
|
+
if _general_activity_answer_slot_for_text(item.text.casefold()):
|
|
2183
|
+
return 3
|
|
2184
|
+
return 5
|
|
2185
|
+
if _ACTIVITY_COMPETITION_DANCER_REPLY_RE.search(item.text) is not None:
|
|
2186
|
+
return 0
|
|
2187
|
+
if _ACTIVITY_COMPETITION_VISUAL_ANSWER_RE.search(item.text) is not None:
|
|
2188
|
+
return 1
|
|
2189
|
+
if _ACTIVITY_COMPETITION_ATTITUDE_REPLY_RE.search(item.text) is not None:
|
|
2190
|
+
return 2
|
|
2191
|
+
if _general_activity_answer_slot_for_text(item.text.casefold()):
|
|
2192
|
+
return 3
|
|
2193
|
+
return 5
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
def _common_interest_direct_evidence_rank(
|
|
2197
|
+
item: ContextItem,
|
|
2198
|
+
*,
|
|
2199
|
+
query_reason: str,
|
|
2200
|
+
) -> int:
|
|
2201
|
+
if not (
|
|
2202
|
+
_is_common_interest_answer_reason(query_reason)
|
|
2203
|
+
and _is_exact_common_interest_answer_support_item(item)
|
|
2204
|
+
):
|
|
2205
|
+
return 0
|
|
2206
|
+
text = item.text
|
|
2207
|
+
if _COMMON_INTEREST_MOVIE_SEEN_SLOT_RE.search(text) is not None:
|
|
2208
|
+
return 0
|
|
2209
|
+
if _COMMON_INTEREST_MOVIE_SLOT_RE.search(text) is not None:
|
|
2210
|
+
if _COMMON_INTEREST_MOVIE_QUESTION_ONLY_RE.search(text) is not None:
|
|
2211
|
+
return 2
|
|
2212
|
+
return 0
|
|
2213
|
+
if _COMMON_INTEREST_PERSONAL_HOBBY_SLOT_RE.search(text) is not None:
|
|
2214
|
+
return 0
|
|
2215
|
+
if _COMMON_INTEREST_ANIMAL_AFFINITY_SLOT_RE.search(text) is not None:
|
|
2216
|
+
return 0
|
|
2217
|
+
if _COMMON_INTEREST_INSPIRATIONAL_AFFINITY_SLOT_RE.search(text) is not None:
|
|
2218
|
+
return 0
|
|
2219
|
+
if _COMMON_INTEREST_SHARED_DESSERT_BRIDGE_RE.search(text) is not None:
|
|
2220
|
+
return 0
|
|
2221
|
+
if _COMMON_INTEREST_SELF_DESSERT_EVIDENCE_RE.search(text) is not None:
|
|
2222
|
+
return 0
|
|
2223
|
+
if _COMMON_INTEREST_PERSONAL_DESSERT_PREFERENCE_RE.search(text) is not None:
|
|
2224
|
+
return 2
|
|
2225
|
+
return 1
|
|
2226
|
+
|
|
2227
|
+
|
|
2228
|
+
def _degree_completion_temporal_answer_support_rank(
|
|
2229
|
+
item: ContextItem,
|
|
2230
|
+
*,
|
|
2231
|
+
query: str,
|
|
2232
|
+
) -> int:
|
|
2233
|
+
return 0 if _is_degree_completion_temporal_answer_support_item(item, query=query) else 1
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
def _common_interest_answer_support_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2237
|
+
if not _is_common_interest_answer_reason(query_reason):
|
|
2238
|
+
return 0
|
|
2239
|
+
slot = _common_interest_answer_slot(item, query_reason=query_reason)
|
|
2240
|
+
if not slot:
|
|
2241
|
+
return 5
|
|
2242
|
+
slot_priority = _common_interest_answer_slot_priority(slot)
|
|
2243
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2244
|
+
return slot_priority
|
|
2245
|
+
return min(slot_priority + 1, 4)
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
def _place_area_state_answer_support_rank(
|
|
2249
|
+
item: ContextItem,
|
|
2250
|
+
*,
|
|
2251
|
+
query: str,
|
|
2252
|
+
query_reason: str,
|
|
2253
|
+
) -> int:
|
|
2254
|
+
if not _place_area_state_query_applies(query=query, query_reason=query_reason):
|
|
2255
|
+
return 0
|
|
2256
|
+
slot = _inventory_answer_slot(item, query_reason=query_reason)
|
|
2257
|
+
if not (
|
|
2258
|
+
slot.startswith("state_")
|
|
2259
|
+
or slot in {"country", "travel_place", "travel_place_realized"}
|
|
2260
|
+
):
|
|
2261
|
+
return 3
|
|
2262
|
+
has_direct_location = (
|
|
2263
|
+
_PLACE_AREA_DIRECT_LOCATION_RE.search(item.text) is not None
|
|
2264
|
+
or _PLACE_AREA_LANDMARK_LOCATION_RE.search(item.text) is not None
|
|
2265
|
+
)
|
|
2266
|
+
has_state_visit = _PLACE_AREA_STATE_VISIT_RE.search(item.text) is not None
|
|
2267
|
+
if (
|
|
2268
|
+
_has_any_exact_turn_source_ref(item)
|
|
2269
|
+
and (slot.endswith("_realized") or has_state_visit)
|
|
2270
|
+
and _PLACE_AREA_STATE_FUTURE_RE.search(item.text) is None
|
|
2271
|
+
and not (
|
|
2272
|
+
_place_area_state_query_wants_concrete_state(query)
|
|
2273
|
+
and slot in {"state_east_coast", "state_pacific_northwest"}
|
|
2274
|
+
)
|
|
2275
|
+
):
|
|
2276
|
+
return 0
|
|
2277
|
+
if (
|
|
2278
|
+
_has_any_exact_turn_source_ref(item)
|
|
2279
|
+
and has_direct_location
|
|
2280
|
+
and _PLACE_AREA_STATE_FUTURE_RE.search(item.text) is None
|
|
2281
|
+
):
|
|
2282
|
+
return 1
|
|
2283
|
+
if (
|
|
2284
|
+
_place_area_state_query_wants_concrete_state(query)
|
|
2285
|
+
and slot
|
|
2286
|
+
in {"state_east_coast", "state_pacific_northwest", "travel_place"}
|
|
2287
|
+
):
|
|
2288
|
+
return 2
|
|
2289
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2290
|
+
return 1
|
|
2291
|
+
return 2
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
def _place_area_state_query_applies(*, query: str, query_reason: str) -> bool:
|
|
2295
|
+
if not query or _PLACE_AREA_STATE_QUERY_RE.search(query) is None:
|
|
2296
|
+
return False
|
|
2297
|
+
return query_reason.replace("_", "-") in {
|
|
2298
|
+
"decomposition-inventory-list",
|
|
2299
|
+
"place-area-inventory-bridge",
|
|
2300
|
+
"trip-destination-bridge",
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
def _place_area_state_query_wants_concrete_state(query: str) -> bool:
|
|
2305
|
+
return re.search(r"\bstates?\b", query, re.IGNORECASE) is not None
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
_STATE_RESIDENCE_ANSWER_EVIDENCE_REASONS = frozenset(
|
|
2309
|
+
{
|
|
2310
|
+
"inference_state_residence_city_state_evidence",
|
|
2311
|
+
"inference_state_residence_named_state_evidence",
|
|
2312
|
+
"inference_state_residence_geo_evidence",
|
|
2313
|
+
}
|
|
2314
|
+
)
|
|
2315
|
+
_STATE_RESIDENCE_MAP_TRAIL_RE = re.compile(
|
|
2316
|
+
r"\bmap\b(?=.{0,160}\btrails?\b)|\btrails?\b(?=.{0,160}\bmap\b)",
|
|
2317
|
+
re.IGNORECASE | re.DOTALL,
|
|
2318
|
+
)
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
def _state_residence_answer_support_rank(
|
|
2322
|
+
item: ContextItem,
|
|
2323
|
+
*,
|
|
2324
|
+
query: str,
|
|
2325
|
+
query_reason: str,
|
|
2326
|
+
) -> int:
|
|
2327
|
+
if query_reason != "state_residence_inference_bridge" or not query:
|
|
2328
|
+
return 0
|
|
2329
|
+
signal = state_residence_inference_signal(query=query, text=item.text)
|
|
2330
|
+
if signal.reason == "inference_state_residence_geo_evidence":
|
|
2331
|
+
has_map_trail = _STATE_RESIDENCE_MAP_TRAIL_RE.search(item.text) is not None
|
|
2332
|
+
if has_map_trail and _has_any_exact_turn_source_ref(item):
|
|
2333
|
+
return 0
|
|
2334
|
+
if has_map_trail:
|
|
2335
|
+
return 1
|
|
2336
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2337
|
+
return 2
|
|
2338
|
+
return 3
|
|
2339
|
+
if signal.reason in _STATE_RESIDENCE_ANSWER_EVIDENCE_REASONS:
|
|
2340
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2341
|
+
return 1
|
|
2342
|
+
return 2
|
|
2343
|
+
if signal.penalty > 0:
|
|
2344
|
+
return 5
|
|
2345
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2346
|
+
return 4
|
|
2347
|
+
return 5
|
|
2348
|
+
|
|
2349
|
+
|
|
2350
|
+
def _is_state_residence_geo_answer_support_item(
|
|
2351
|
+
item: ContextItem,
|
|
2352
|
+
*,
|
|
2353
|
+
query: str,
|
|
2354
|
+
) -> bool:
|
|
2355
|
+
query_reason = _answer_support_query_reason(item)
|
|
2356
|
+
if query_reason != "state_residence_inference_bridge" or not query:
|
|
2357
|
+
return False
|
|
2358
|
+
return (
|
|
2359
|
+
_state_residence_answer_support_rank(
|
|
2360
|
+
item,
|
|
2361
|
+
query=query,
|
|
2362
|
+
query_reason=query_reason,
|
|
2363
|
+
)
|
|
2364
|
+
== 0
|
|
2365
|
+
)
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
def _is_direct_place_area_state_answer_support_item(
|
|
2369
|
+
item: ContextItem,
|
|
2370
|
+
*,
|
|
2371
|
+
query: str,
|
|
2372
|
+
family: str,
|
|
2373
|
+
) -> bool:
|
|
2374
|
+
query_reason = _answer_support_query_reason(item)
|
|
2375
|
+
if not _place_area_state_query_applies(query=query, query_reason=query_reason):
|
|
2376
|
+
return False
|
|
2377
|
+
if _diversity_family_base(family) not in {
|
|
2378
|
+
"query_reason_inventory_slot",
|
|
2379
|
+
"query_reason_inventory_slot_source_group",
|
|
2380
|
+
}:
|
|
2381
|
+
return False
|
|
2382
|
+
return (
|
|
2383
|
+
_place_area_state_answer_support_rank(
|
|
2384
|
+
item,
|
|
2385
|
+
query=query,
|
|
2386
|
+
query_reason=query_reason,
|
|
2387
|
+
)
|
|
2388
|
+
== 0
|
|
2389
|
+
)
|
|
2390
|
+
|
|
2391
|
+
|
|
2392
|
+
def _is_direct_outdoor_activity_answer_support_item(
|
|
2393
|
+
item: ContextItem,
|
|
2394
|
+
*,
|
|
2395
|
+
query: str,
|
|
2396
|
+
family: str,
|
|
2397
|
+
) -> bool:
|
|
2398
|
+
if not query or not re.search(
|
|
2399
|
+
r"\b(?:outdoor|outdoors|hiking|hike|mountaineering|picnic|"
|
|
2400
|
+
r"waterfall|colleagues?|workmates?|friends?)\b",
|
|
2401
|
+
query,
|
|
2402
|
+
re.IGNORECASE,
|
|
2403
|
+
):
|
|
2404
|
+
return False
|
|
2405
|
+
if _answer_support_query_reason(item) != "outdoor_activity_inventory_bridge":
|
|
2406
|
+
return False
|
|
2407
|
+
if _diversity_family_base(family) not in {
|
|
2408
|
+
"query_reason_inventory_slot",
|
|
2409
|
+
"query_reason_inventory_slot_source_group",
|
|
2410
|
+
}:
|
|
2411
|
+
return False
|
|
2412
|
+
slot = _inventory_answer_slot(item, query_reason="outdoor_activity_inventory_bridge")
|
|
2413
|
+
return slot in {
|
|
2414
|
+
"outdoor_visual_group",
|
|
2415
|
+
"outdoor_mountaineering",
|
|
2416
|
+
"outdoor_hiking",
|
|
2417
|
+
"outdoor_picnic",
|
|
2418
|
+
"outdoor_waterfall",
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
def _birdwatching_city_schedule_exact_turn_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2423
|
+
if query_reason != "birdwatching_city_schedule_bridge":
|
|
2424
|
+
return 0
|
|
2425
|
+
if _has_any_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
2426
|
+
return 0
|
|
2427
|
+
return 1
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
def _pet_acquisition_date_anchor_answer_support_rank(
|
|
2431
|
+
item: ContextItem,
|
|
2432
|
+
*,
|
|
2433
|
+
query_reason: str,
|
|
2434
|
+
) -> int:
|
|
2435
|
+
return 0 if _is_pet_acquisition_date_anchor_answer_support_item(item) else 1
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
def _is_pet_acquisition_date_anchor_answer_support_item(item: ContextItem) -> bool:
|
|
2439
|
+
query_reason = _answer_support_query_reason(item)
|
|
2440
|
+
text = item.text
|
|
2441
|
+
signals = _diagnostic_score_signals(item)
|
|
2442
|
+
signal_reason = str(signals.get("query_expansion_reason") or "").strip()
|
|
2443
|
+
if (
|
|
2444
|
+
query_reason == "pet_acquisition_date_bridge"
|
|
2445
|
+
and _numeric_signal(signals.get("exact_source_repair_date_anchor")) > 0
|
|
2446
|
+
and _is_temporal_answer_support_item(item, query_reason=query_reason)
|
|
2447
|
+
):
|
|
2448
|
+
return True
|
|
2449
|
+
if (
|
|
2450
|
+
query_reason == "pet_acquisition_date_bridge"
|
|
2451
|
+
and _is_temporal_answer_support_item(item, query_reason=query_reason)
|
|
2452
|
+
and _PET_ACQUISITION_DATE_ANCHOR_SUPPORT_RE.search(text) is not None
|
|
2453
|
+
):
|
|
2454
|
+
return True
|
|
2455
|
+
return (
|
|
2456
|
+
query_reason in {"pet_acquisition_date_bridge", "decomposition_temporal_answer"}
|
|
2457
|
+
and (
|
|
2458
|
+
signal_reason == "pet_acquisition_date_bridge"
|
|
2459
|
+
or _PET_ACQUISITION_OBJECT_ANCHOR_RE.search(text) is not None
|
|
2460
|
+
)
|
|
2461
|
+
and _is_temporal_answer_support_item(item, query_reason=query_reason)
|
|
2462
|
+
and _PET_ACQUISITION_DATE_ANCHOR_SUPPORT_RE.search(text) is not None
|
|
2463
|
+
)
|
|
2464
|
+
|
|
2465
|
+
|
|
2466
|
+
def _temporal_answer_support_source_span_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2467
|
+
if not _is_temporal_answer_support_item(item, query_reason=query_reason):
|
|
2468
|
+
return 0
|
|
2469
|
+
if _has_primary_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
2470
|
+
return 0
|
|
2471
|
+
if _has_primary_exact_turn_source_ref(item):
|
|
2472
|
+
return 1
|
|
2473
|
+
if _has_any_exact_turn_source_ref(item) and len(item.source_refs) == 1:
|
|
2474
|
+
return 2
|
|
2475
|
+
if _has_any_exact_turn_source_ref(item):
|
|
2476
|
+
return 3
|
|
2477
|
+
return 4
|
|
2478
|
+
|
|
2479
|
+
|
|
2480
|
+
def _temporal_answer_support_query_object_hits(
|
|
2481
|
+
item: ContextItem,
|
|
2482
|
+
*,
|
|
2483
|
+
query: str,
|
|
2484
|
+
query_reason: str,
|
|
2485
|
+
) -> int:
|
|
2486
|
+
if not query or not _is_temporal_answer_support_item(item, query_reason=query_reason):
|
|
2487
|
+
return 0
|
|
2488
|
+
query_tokens = tuple(
|
|
2489
|
+
dict.fromkeys(
|
|
2490
|
+
token.casefold()
|
|
2491
|
+
for token in _QUERY_OBJECT_TOKEN_RE.findall(query)
|
|
2492
|
+
if len(token) >= 3
|
|
2493
|
+
and token.casefold() not in _TEMPORAL_QUERY_OBJECT_STOPWORDS
|
|
2494
|
+
and not token[:1].isupper()
|
|
2495
|
+
)
|
|
2496
|
+
)
|
|
2497
|
+
if not query_tokens:
|
|
2498
|
+
return 0
|
|
2499
|
+
text = item.text.casefold()
|
|
2500
|
+
return sum(1 for token in query_tokens if re.search(rf"\b{re.escape(token)}\b", text))
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
def _answer_object_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2504
|
+
if _is_support_network_reason(query_reason):
|
|
2505
|
+
return _support_network_answer_object_rank(item.text)
|
|
2506
|
+
if _is_pottery_type_reason(query_reason):
|
|
2507
|
+
return _pottery_type_answer_object_rank(item.text)
|
|
2508
|
+
if _is_pottery_type_inventory_item(item, query_reason=query_reason):
|
|
2509
|
+
return _pottery_type_answer_object_rank(item.text)
|
|
2510
|
+
if _is_family_activity_reason(query_reason):
|
|
2511
|
+
return _family_activity_answer_object_rank(item.text)
|
|
2512
|
+
if query_reason == "cause_event_inventory_bridge":
|
|
2513
|
+
return _cause_event_answer_content_rank(item.text)
|
|
2514
|
+
if query_reason == "childhood_possession_inventory_bridge":
|
|
2515
|
+
return _childhood_possession_answer_content_rank(item.text)
|
|
2516
|
+
if _is_inventory_list_reason(query_reason):
|
|
2517
|
+
return _inventory_list_answer_object_rank(item.text)
|
|
2518
|
+
return 2
|
|
2519
|
+
|
|
2520
|
+
def _marker_coverage_answer_support_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2521
|
+
if not _aggregation_marker_coverage_slot(item, query_reason=query_reason):
|
|
2522
|
+
return 0
|
|
2523
|
+
markers = tuple(
|
|
2524
|
+
dict.fromkeys(match.group(0) for match in _DIALOGUE_MARKER_RE.finditer(item.text))
|
|
2525
|
+
)
|
|
2526
|
+
return -len(markers)
|
|
2527
|
+
|
|
2528
|
+
|
|
2529
|
+
def _is_temporal_answer_support_item(item: ContextItem, *, query_reason: str) -> bool:
|
|
2530
|
+
if _numeric_signal(_diagnostic_score_signals(item).get("source_sibling_answer_evidence")) <= 0:
|
|
2531
|
+
return False
|
|
2532
|
+
if not _has_any_exact_turn_source_ref(item):
|
|
2533
|
+
return False
|
|
2534
|
+
if (
|
|
2535
|
+
query_reason in {"business_commonality_bridge", "business_start_reason_bridge"}
|
|
2536
|
+
and _business_commonality_answer_slot(item.text)
|
|
2537
|
+
):
|
|
2538
|
+
return False
|
|
2539
|
+
signals = _diagnostic_score_signals(item)
|
|
2540
|
+
if _numeric_signal(signals.get("exact_source_repair_date_anchor")) > 0:
|
|
2541
|
+
return True
|
|
2542
|
+
normalized_reason = query_reason.replace("_", "-")
|
|
2543
|
+
if normalized_reason in _TEMPORAL_ANSWER_SUPPORT_REASONS:
|
|
2544
|
+
return True
|
|
2545
|
+
if query_reason == "outdoor_activity_inventory_bridge" or (
|
|
2546
|
+
_is_community_participation_reason(query_reason)
|
|
2547
|
+
and _inventory_answer_slot(item, query_reason=query_reason)
|
|
2548
|
+
):
|
|
2549
|
+
return False
|
|
2550
|
+
if normalized_reason in {"place-area-inventory-bridge", "trip-destination-bridge"} and (
|
|
2551
|
+
_inventory_answer_slot(item, query_reason=query_reason)
|
|
2552
|
+
):
|
|
2553
|
+
return False
|
|
2554
|
+
return _TEMPORAL_DIRECT_ANSWER_RE.search(item.text) is not None
|
|
2555
|
+
|
|
2556
|
+
def _precise_turn_answer_support_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2557
|
+
if _is_temporal_answer_support_item(item, query_reason=query_reason):
|
|
2558
|
+
return 0
|
|
2559
|
+
if _is_count_aggregation_coverage_item(item, query_reason=query_reason):
|
|
2560
|
+
return 0
|
|
2561
|
+
if (
|
|
2562
|
+
_is_family_activity_reason(query_reason)
|
|
2563
|
+
and _answer_object_rank(item, query_reason=query_reason) == 0
|
|
2564
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2565
|
+
):
|
|
2566
|
+
return 0
|
|
2567
|
+
if (
|
|
2568
|
+
_is_activity_participation_answer_reason(query_reason)
|
|
2569
|
+
and _activity_answer_content_rank(item.text) == 0
|
|
2570
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2571
|
+
):
|
|
2572
|
+
return 0
|
|
2573
|
+
if (
|
|
2574
|
+
query_reason == "birdwatching_city_schedule_bridge"
|
|
2575
|
+
and _numeric_signal(
|
|
2576
|
+
_diagnostic_score_signals(item).get("birdwatching_city_schedule_answer_evidence")
|
|
2577
|
+
)
|
|
2578
|
+
>= 2
|
|
2579
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2580
|
+
):
|
|
2581
|
+
return 0
|
|
2582
|
+
if (
|
|
2583
|
+
query_reason == "birdwatching_city_schedule_bridge"
|
|
2584
|
+
and _birdwatching_city_schedule_answer_content_rank(item.text) <= 1
|
|
2585
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2586
|
+
):
|
|
2587
|
+
return 0
|
|
2588
|
+
if (
|
|
2589
|
+
query_reason in {"book_reading_list_bridge", "creative_writing_career_bridge"}
|
|
2590
|
+
and _book_reading_answer_content_rank(item.text) <= 1
|
|
2591
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2592
|
+
):
|
|
2593
|
+
return 0
|
|
2594
|
+
if (
|
|
2595
|
+
query_reason == "decomposition_inventory_list"
|
|
2596
|
+
and _book_reading_answer_content_rank(item.text) <= 1
|
|
2597
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2598
|
+
):
|
|
2599
|
+
return 0
|
|
2600
|
+
if (
|
|
2601
|
+
query_reason == "music_artist_answer_bridge"
|
|
2602
|
+
and _music_artist_answer_content_rank(item.text) <= 1
|
|
2603
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2604
|
+
):
|
|
2605
|
+
return 0
|
|
2606
|
+
if (
|
|
2607
|
+
_is_inventory_list_reason(query_reason)
|
|
2608
|
+
and _answer_object_rank(item, query_reason=query_reason) <= 1
|
|
2609
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2610
|
+
):
|
|
2611
|
+
return 0
|
|
2612
|
+
if (
|
|
2613
|
+
_is_common_interest_answer_reason(query_reason)
|
|
2614
|
+
and _common_interest_answer_slot(item, query_reason=query_reason)
|
|
2615
|
+
and _has_any_exact_turn_source_ref(item)
|
|
2616
|
+
):
|
|
2617
|
+
return 0
|
|
2618
|
+
if query_reason in _BROAD_EVIDENCE_ANSWER_SUPPORT_REASONS:
|
|
2619
|
+
return 2
|
|
2620
|
+
if (
|
|
2621
|
+
query_reason in _COUNT_AGGREGATION_COVERAGE_REASONS
|
|
2622
|
+
and _has_primary_exact_turn_source_ref(item)
|
|
2623
|
+
):
|
|
2624
|
+
return 1
|
|
2625
|
+
if _is_activity_participation_answer_reason(query_reason):
|
|
2626
|
+
return 2
|
|
2627
|
+
if query_reason not in _PRECISE_TURN_ANSWER_SUPPORT_REASONS:
|
|
2628
|
+
return 2
|
|
2629
|
+
return 0 if _has_primary_exact_turn_source_ref(item) else 1
|
|
2630
|
+
|
|
2631
|
+
def _precise_answer_content_rank(item: ContextItem, *, query_reason: str) -> int:
|
|
2632
|
+
if _is_support_network_reason(query_reason):
|
|
2633
|
+
return _support_network_answer_object_rank(item.text)
|
|
2634
|
+
if query_reason in {"career_intent_bridge", "career_path_bridge"}:
|
|
2635
|
+
text = item.text.casefold()
|
|
2636
|
+
if "working with trans people" in text or (
|
|
2637
|
+
"mental health" in text and ("support" in text or "help" in text)
|
|
2638
|
+
):
|
|
2639
|
+
return 0
|
|
2640
|
+
if "counsel" in text or "mental health" in text:
|
|
2641
|
+
return 1
|
|
2642
|
+
return 3
|
|
2643
|
+
if query_reason == "creative_writing_career_bridge":
|
|
2644
|
+
return _book_reading_answer_content_rank(item.text)
|
|
2645
|
+
if query_reason == "birdwatching_city_schedule_bridge":
|
|
2646
|
+
return _birdwatching_city_schedule_answer_content_rank(item.text)
|
|
2647
|
+
if query_reason == "book_reading_list_bridge":
|
|
2648
|
+
return _book_reading_answer_content_rank(item.text)
|
|
2649
|
+
if query_reason == "book_suggestion_bridge":
|
|
2650
|
+
return min(
|
|
2651
|
+
_book_suggestion_answer_content_rank(item.text),
|
|
2652
|
+
recommendation_list_answer_support_rank(
|
|
2653
|
+
text=item.text,
|
|
2654
|
+
query_reason=query_reason,
|
|
2655
|
+
),
|
|
2656
|
+
)
|
|
2657
|
+
if is_recommendation_list_reason(query_reason):
|
|
2658
|
+
recommendation_rank = recommendation_list_answer_support_rank(
|
|
2659
|
+
text=item.text,
|
|
2660
|
+
query_reason=query_reason,
|
|
2661
|
+
)
|
|
2662
|
+
if recommendation_rank <= 2:
|
|
2663
|
+
return recommendation_rank
|
|
2664
|
+
if query_reason == "music_artist_answer_bridge":
|
|
2665
|
+
return _music_artist_answer_content_rank(item.text)
|
|
2666
|
+
if query_reason == "classical_music_preference_bridge":
|
|
2667
|
+
return _classical_music_preference_answer_content_rank(item.text)
|
|
2668
|
+
if query_reason == "sentimental_reminder_bridge":
|
|
2669
|
+
return _sentimental_reminder_answer_content_rank(item.text)
|
|
2670
|
+
if query_reason == "decomposition_collectible_object":
|
|
2671
|
+
return _collectible_object_answer_content_rank(item.text)
|
|
2672
|
+
if query_reason == "outdoor_nature_memory_bridge":
|
|
2673
|
+
return _outdoor_nature_memory_answer_content_rank(item.text)
|
|
2674
|
+
if query_reason == "children_preference_bridge":
|
|
2675
|
+
return _children_preference_answer_content_rank(item.text)
|
|
2676
|
+
if query_reason == "inspiration_source_bridge":
|
|
2677
|
+
return _inspiration_source_answer_content_rank(item.text)
|
|
2678
|
+
if query_reason == "public_office_service_bridge":
|
|
2679
|
+
return _public_office_service_answer_content_rank(item.text)
|
|
2680
|
+
if query_reason == "recognition_award_bridge":
|
|
2681
|
+
return _recognition_award_answer_content_rank(item.text)
|
|
2682
|
+
if query_reason == "relocation_willingness_inference_bridge":
|
|
2683
|
+
return _relocation_willingness_answer_content_rank(item.text)
|
|
2684
|
+
if query_reason == "volunteer_career_inference_bridge":
|
|
2685
|
+
return _volunteer_career_answer_content_rank(item)
|
|
2686
|
+
if _is_activity_participation_answer_reason(query_reason):
|
|
2687
|
+
return _activity_answer_content_rank(item.text)
|
|
2688
|
+
if (
|
|
2689
|
+
query_reason == "decomposition_inventory_list"
|
|
2690
|
+
and _book_reading_answer_content_rank(item.text) <= 1
|
|
2691
|
+
):
|
|
2692
|
+
return _book_reading_answer_content_rank(item.text)
|
|
2693
|
+
if _is_pottery_type_reason(query_reason):
|
|
2694
|
+
return _pottery_type_answer_content_rank(item.text)
|
|
2695
|
+
if query_reason in {"running_reason_bridge", "running_reason_question_bridge"}:
|
|
2696
|
+
text = item.text.casefold()
|
|
2697
|
+
if "what got you into running" in text or "for walking or running" in text:
|
|
2698
|
+
return 0
|
|
2699
|
+
if "running" in text and any(
|
|
2700
|
+
marker in text
|
|
2701
|
+
for marker in (
|
|
2702
|
+
"destress",
|
|
2703
|
+
"de-stress",
|
|
2704
|
+
"clear my mind",
|
|
2705
|
+
"headspace",
|
|
2706
|
+
)
|
|
2707
|
+
):
|
|
2708
|
+
return 0
|
|
2709
|
+
if "running" in text:
|
|
2710
|
+
return 2
|
|
2711
|
+
return 3
|
|
2712
|
+
if query_reason == "shoe_usage_bridge":
|
|
2713
|
+
text = item.text.casefold()
|
|
2714
|
+
if "walking or running" in text or "for walking" in text:
|
|
2715
|
+
return 0
|
|
2716
|
+
if any(marker in text for marker in ("new shoes", "sneakers", "running shoe")):
|
|
2717
|
+
return 1
|
|
2718
|
+
return 3
|
|
2719
|
+
if query_reason == "painting_inventory_bridge":
|
|
2720
|
+
return _painting_inventory_answer_content_rank(item.text)
|
|
2721
|
+
if query_reason == "degree_policy_inference_bridge":
|
|
2722
|
+
return _degree_policy_answer_content_rank(item.text)
|
|
2723
|
+
if query_reason == "childhood_possession_inventory_bridge":
|
|
2724
|
+
return _childhood_possession_answer_content_rank(item.text)
|
|
2725
|
+
if query_reason == "cause_event_inventory_bridge":
|
|
2726
|
+
return _cause_event_answer_content_rank(item.text)
|
|
2727
|
+
if query_reason == "event_participation_help_bridge":
|
|
2728
|
+
if _inventory_answer_slot(item, query_reason=query_reason) in {
|
|
2729
|
+
"community_mentorship_program",
|
|
2730
|
+
"community_school_event",
|
|
2731
|
+
}:
|
|
2732
|
+
return 0
|
|
2733
|
+
return _inventory_list_answer_object_rank(item.text)
|
|
2734
|
+
if query_reason == "transgender_youth_center_event_bridge":
|
|
2735
|
+
return _transgender_youth_center_event_answer_content_rank(item)
|
|
2736
|
+
if query_reason in {"business_commonality_bridge", "business_start_reason_bridge"}:
|
|
2737
|
+
return _business_commonality_answer_content_rank(item.text)
|
|
2738
|
+
if query_reason == "creative_work_submission_bridge":
|
|
2739
|
+
return _creative_work_submission_answer_content_rank(item.text)
|
|
2740
|
+
if query_reason == "creative_writing_inventory_bridge":
|
|
2741
|
+
return _creative_writing_inventory_answer_content_rank(item.text)
|
|
2742
|
+
if query_reason == TRAVEL_HOBBY_WRITING_REASON:
|
|
2743
|
+
return travel_hobby_writing_answer_rank(item.text)
|
|
2744
|
+
if query_reason == "screenplay_count_bridge":
|
|
2745
|
+
return _screenplay_rejection_answer_content_rank(item.text)
|
|
2746
|
+
if query_reason == "charity_brand_sponsorship_bridge":
|
|
2747
|
+
return _charity_brand_sponsorship_answer_content_rank(item.text)
|
|
2748
|
+
if query_reason == "exercise_activity_inventory_bridge":
|
|
2749
|
+
return _exercise_activity_answer_content_rank(item.text)
|
|
2750
|
+
if query_reason == "friend_place_shelter_inventory_bridge":
|
|
2751
|
+
return _friend_place_shelter_answer_content_rank(item.text)
|
|
2752
|
+
if query_reason == "animal_care_instruction_bridge":
|
|
2753
|
+
return _animal_care_instruction_content_rank(item.text)
|
|
2754
|
+
if query_reason in {
|
|
2755
|
+
"support_career_motivation_bridge",
|
|
2756
|
+
"support_origin_bridge",
|
|
2757
|
+
}:
|
|
2758
|
+
return _support_career_motivation_content_rank(item.text)
|
|
2759
|
+
if query_reason != "meteor_shower_feeling_bridge":
|
|
2760
|
+
return 0
|
|
2761
|
+
text = item.text.casefold()
|
|
2762
|
+
if "awe" in text or "tiny" in text:
|
|
2763
|
+
return 0
|
|
2764
|
+
if "felt" in text or "feel" in text or "universe" in text:
|
|
2765
|
+
return 1
|
|
2766
|
+
return 2
|
|
2767
|
+
|
|
2768
|
+
def _support_career_motivation_content_rank(text: str) -> int:
|
|
2769
|
+
if _SUPPORT_CAREER_MOTIVATION_DIRECT_RE.search(text) is not None:
|
|
2770
|
+
return 0
|
|
2771
|
+
if _SUPPORT_CAREER_MOTIVATION_CONTEXT_RE.search(text) is not None:
|
|
2772
|
+
return 1
|
|
2773
|
+
return 3
|
|
2774
|
+
|
|
2775
|
+
def _classical_music_preference_answer_content_rank(text: str) -> int:
|
|
2776
|
+
if _CLASSICAL_MUSIC_PREFERENCE_DIRECT_RE.search(text) is not None:
|
|
2777
|
+
return 0
|
|
2778
|
+
if re.search(r"\b(?:classical|bach|mozart|vivaldi|orchestra|symphony)\b", text, re.IGNORECASE):
|
|
2779
|
+
return 1
|
|
2780
|
+
if re.search(r"\b(?:music|song|tunes?|composer|concert)\b", text, re.IGNORECASE):
|
|
2781
|
+
return 2
|
|
2782
|
+
return 4
|
|
2783
|
+
|
|
2784
|
+
|
|
2785
|
+
def _sentimental_reminder_answer_content_rank(text: str) -> int:
|
|
2786
|
+
if _SENTIMENTAL_REMINDER_DIRECT_RE.search(text) is not None:
|
|
2787
|
+
return 0
|
|
2788
|
+
if _SENTIMENTAL_REMINDER_CONTEXT_RE.search(text) is not None:
|
|
2789
|
+
return 1
|
|
2790
|
+
return 4
|
|
2791
|
+
|
|
2792
|
+
|
|
2793
|
+
def _collectible_object_answer_content_rank(text: str) -> int:
|
|
2794
|
+
if _COLLECTIBLE_OBJECT_DIRECT_RE.search(text) is not None:
|
|
2795
|
+
return 0
|
|
2796
|
+
if _COLLECTIBLE_OBJECT_CONTEXT_RE.search(text) is not None:
|
|
2797
|
+
return 1
|
|
2798
|
+
return 4
|
|
2799
|
+
|
|
2800
|
+
|
|
2801
|
+
def _outdoor_nature_memory_answer_content_rank(text: str) -> int:
|
|
2802
|
+
if _OUTDOOR_NATURE_MEMORY_DIRECT_RE.search(text) is not None:
|
|
2803
|
+
return 0
|
|
2804
|
+
if _OUTDOOR_NATURE_MEMORY_CONTEXT_RE.search(text) is not None:
|
|
2805
|
+
return 1
|
|
2806
|
+
return 4
|
|
2807
|
+
|
|
2808
|
+
|
|
2809
|
+
def _children_preference_answer_content_rank(text: str) -> int:
|
|
2810
|
+
if _CHILDREN_PREFERENCE_DIRECT_RE.search(text) is not None:
|
|
2811
|
+
return 0
|
|
2812
|
+
if _CHILDREN_PREFERENCE_CONTEXT_RE.search(text) is not None:
|
|
2813
|
+
return 1
|
|
2814
|
+
return 4
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
def _childhood_possession_answer_content_rank(text: str) -> int:
|
|
2818
|
+
has_direct_context = _CHILDHOOD_POSSESSION_DIRECT_RE.search(text) is not None
|
|
2819
|
+
has_object = _CHILDHOOD_POSSESSION_OBJECT_RE.search(text) is not None
|
|
2820
|
+
if has_direct_context and has_object:
|
|
2821
|
+
return 0
|
|
2822
|
+
if has_direct_context:
|
|
2823
|
+
return 1
|
|
2824
|
+
if has_object and re.search(r"\b(?:childhood|kid|child|younger)\b", text, re.IGNORECASE):
|
|
2825
|
+
return 2
|
|
2826
|
+
return 5
|
|
2827
|
+
|
|
2828
|
+
|
|
2829
|
+
def _public_office_service_answer_content_rank(text: str) -> int:
|
|
2830
|
+
if _PUBLIC_OFFICE_SERVICE_DIRECT_RE.search(text) is not None:
|
|
2831
|
+
return 0
|
|
2832
|
+
lowered = text.casefold()
|
|
2833
|
+
if "office" in lowered or "politic" in lowered or "campaign" in lowered:
|
|
2834
|
+
return 1
|
|
2835
|
+
return 4
|
|
2836
|
+
|
|
2837
|
+
|
|
2838
|
+
def _recognition_award_answer_content_rank(text: str) -> int:
|
|
2839
|
+
if _RECOGNITION_CERTIFICATE_VISUAL_ANSWER_RE.search(text) is not None:
|
|
2840
|
+
return 0
|
|
2841
|
+
if re.search(
|
|
2842
|
+
r"\b(?:recognition|awards?|medals?|certificates?|honou?rs?|"
|
|
2843
|
+
r"troph(?:y|ies)|prizes?)\b"
|
|
2844
|
+
r"(?=.{0,200}\b(?:receive|received|got|given|gave|earned|won)\b)|"
|
|
2845
|
+
r"\b(?:receive|received|got|given|gave|earned|won)\b"
|
|
2846
|
+
r"(?=.{0,160}\b(?:recognition|awards?|medals?|certificates?|"
|
|
2847
|
+
r"honou?rs?|troph(?:y|ies)|prizes?)\b)",
|
|
2848
|
+
text,
|
|
2849
|
+
re.IGNORECASE | re.DOTALL,
|
|
2850
|
+
):
|
|
2851
|
+
return 1
|
|
2852
|
+
if re.search(
|
|
2853
|
+
r"\b(?:certificate|certificates|diploma|diplomas|degree|"
|
|
2854
|
+
r"graduat(?:e|ed|ion))\b",
|
|
2855
|
+
text,
|
|
2856
|
+
re.IGNORECASE,
|
|
2857
|
+
):
|
|
2858
|
+
return 2
|
|
2859
|
+
return 4
|
|
2860
|
+
|
|
2861
|
+
|
|
2862
|
+
def _inspiration_source_answer_content_rank(text: str) -> int:
|
|
2863
|
+
if _INSPIRATION_SOURCE_DIRECT_RE.search(text) is not None:
|
|
2864
|
+
return 0
|
|
2865
|
+
if _INSPIRATION_SOURCE_CONTEXT_RE.search(text) is not None:
|
|
2866
|
+
return 2
|
|
2867
|
+
return 4
|
|
2868
|
+
|
|
2869
|
+
|
|
2870
|
+
def _relocation_willingness_answer_content_rank(text: str) -> int:
|
|
2871
|
+
if (
|
|
2872
|
+
_PUBLIC_OFFICE_SERVICE_DIRECT_RE.search(text) is not None
|
|
2873
|
+
or _MILITARY_SERVICE_GOAL_DIRECT_RE.search(text) is not None
|
|
2874
|
+
):
|
|
2875
|
+
return 0
|
|
2876
|
+
lowered = text.casefold()
|
|
2877
|
+
if any(marker in lowered for marker in ("military", "country", "office", "politic")):
|
|
2878
|
+
return 1
|
|
2879
|
+
return 4
|
|
2880
|
+
|
|
2881
|
+
|
|
2882
|
+
def _volunteer_career_answer_content_rank(item: ContextItem) -> int:
|
|
2883
|
+
slot = _career_answer_slot(
|
|
2884
|
+
item,
|
|
2885
|
+
query_reason="volunteer_career_inference_bridge",
|
|
2886
|
+
)
|
|
2887
|
+
if slot in {
|
|
2888
|
+
"shelter_operations",
|
|
2889
|
+
"counseling_talks",
|
|
2890
|
+
"volunteer_origin",
|
|
2891
|
+
"start_motivation",
|
|
2892
|
+
}:
|
|
2893
|
+
return 0
|
|
2894
|
+
if slot == "resident_support":
|
|
2895
|
+
return 1
|
|
2896
|
+
if slot == "homeless_shelter":
|
|
2897
|
+
return 2
|
|
2898
|
+
return 4
|
|
2899
|
+
|
|
2900
|
+
|
|
2901
|
+
def _degree_policy_answer_content_rank(text: str) -> int:
|
|
2902
|
+
slot = _degree_policy_answer_slot(text)
|
|
2903
|
+
if slot == "degree_field_inference":
|
|
2904
|
+
return 0
|
|
2905
|
+
if slot == "policy_career_plan":
|
|
2906
|
+
return 1
|
|
2907
|
+
if slot == "degree_completion_context":
|
|
2908
|
+
return 2
|
|
2909
|
+
return 3
|
|
2910
|
+
|
|
2911
|
+
|
|
2912
|
+
def _birdwatching_city_schedule_answer_content_rank(text: str) -> int:
|
|
2913
|
+
if _BIRDWATCHING_CITY_SCHEDULE_CONTENT_RE.search(text) is not None:
|
|
2914
|
+
return 0
|
|
2915
|
+
lowered = text.casefold()
|
|
2916
|
+
if "nature" in lowered and ("city" in lowered or "outdoors" in lowered):
|
|
2917
|
+
return 1
|
|
2918
|
+
return 3
|
|
2919
|
+
|
|
2920
|
+
|
|
2921
|
+
def _book_suggestion_answer_content_rank(text: str) -> int:
|
|
2922
|
+
if _BOOK_SUGGESTION_DIRECT_RE.search(text) is not None:
|
|
2923
|
+
return 0
|
|
2924
|
+
return _book_reading_answer_content_rank(text)
|
|
2925
|
+
|
|
2926
|
+
|
|
2927
|
+
def _music_artist_answer_content_rank(text: str) -> int:
|
|
2928
|
+
if _MUSIC_ARTIST_DIRECT_ANSWER_RE.search(text) is not None:
|
|
2929
|
+
return 0
|
|
2930
|
+
lowered = text.casefold()
|
|
2931
|
+
if "artist" in lowered or "band" in lowered or "singer" in lowered:
|
|
2932
|
+
return 1
|
|
2933
|
+
if "music" in lowered or "song" in lowered or "concert" in lowered:
|
|
2934
|
+
return 3
|
|
2935
|
+
return 5
|
|
2936
|
+
|
|
2937
|
+
|
|
2938
|
+
def _business_commonality_answer_content_rank(text: str) -> int:
|
|
2939
|
+
slot = _business_commonality_answer_slot(text)
|
|
2940
|
+
if slot in {"jon_job_loss", "gina_job_loss"}:
|
|
2941
|
+
if _BUSINESS_DIRECT_JOB_LOSS_RE.search(text) is not None:
|
|
2942
|
+
return 0
|
|
2943
|
+
return 1
|
|
2944
|
+
if slot in {"jon_business_type", "gina_store_start"}:
|
|
2945
|
+
if _BUSINESS_DIRECT_START_REASON_RE.search(text) is not None:
|
|
2946
|
+
return 0
|
|
2947
|
+
return 1
|
|
2948
|
+
if slot == "business_start_generic":
|
|
2949
|
+
return 2
|
|
2950
|
+
return 3
|
|
2951
|
+
|
|
2952
|
+
|
|
2953
|
+
def _cause_event_answer_content_rank(text: str) -> int:
|
|
2954
|
+
if _cause_event_answer_slot(text):
|
|
2955
|
+
return 0
|
|
2956
|
+
lowered = text.casefold()
|
|
2957
|
+
if "cause" in lowered and any(
|
|
2958
|
+
marker in lowered for marker in ("event", "fund", "awareness", "charity")
|
|
2959
|
+
):
|
|
2960
|
+
return 1
|
|
2961
|
+
if any(marker in lowered for marker in ("food drive", "toy drive", "veteran")):
|
|
2962
|
+
return 2
|
|
2963
|
+
return 5
|
|
2964
|
+
|
|
2965
|
+
|
|
2966
|
+
_TRANSGENDER_YOUTH_CENTER_EVENT_DIRECT_RE = re.compile(
|
|
2967
|
+
r"\b(?:youth\s+center|talent\s+show|band|stage|microphone|"
|
|
2968
|
+
r"colorful\s+lights|visual\s+query)\b",
|
|
2969
|
+
re.IGNORECASE,
|
|
2970
|
+
)
|
|
2971
|
+
|
|
2972
|
+
|
|
2973
|
+
def _transgender_youth_center_event_answer_content_rank(item: ContextItem) -> int:
|
|
2974
|
+
if _diagnostic_signal_truthy(item, "source_sibling_dialogue_visual_reference"):
|
|
2975
|
+
return 0
|
|
2976
|
+
return 0 if _TRANSGENDER_YOUTH_CENTER_EVENT_DIRECT_RE.search(item.text) else 5
|
|
2977
|
+
|
|
2978
|
+
|
|
2979
|
+
def _screenplay_rejection_answer_content_rank(text: str) -> int:
|
|
2980
|
+
if _SCREENPLAY_REJECTION_DIRECT_RE.search(text) is not None:
|
|
2981
|
+
return 0
|
|
2982
|
+
lowered = text.casefold()
|
|
2983
|
+
if "rejection" in lowered or "rejected" in lowered:
|
|
2984
|
+
return 1
|
|
2985
|
+
if "script" in lowered or "screenplay" in lowered:
|
|
2986
|
+
return 2
|
|
2987
|
+
return 4
|
|
2988
|
+
|
|
2989
|
+
|
|
2990
|
+
def _creative_work_submission_answer_content_rank(text: str) -> int:
|
|
2991
|
+
if _CREATIVE_WORK_SUBMISSION_DIRECT_RE.search(text) is not None:
|
|
2992
|
+
return 0
|
|
2993
|
+
lowered = text.casefold()
|
|
2994
|
+
if "submit" in lowered or "submission" in lowered:
|
|
2995
|
+
return 1
|
|
2996
|
+
if "screenplay" in lowered or "script" in lowered or "project" in lowered:
|
|
2997
|
+
return 2
|
|
2998
|
+
return 4
|
|
2999
|
+
|
|
3000
|
+
|
|
3001
|
+
def _creative_writing_inventory_answer_content_rank(text: str) -> int:
|
|
3002
|
+
if _CREATIVE_WRITING_INVENTORY_DIRECT_RE.search(text) is not None:
|
|
3003
|
+
return 0
|
|
3004
|
+
lowered = text.casefold()
|
|
3005
|
+
if any(
|
|
3006
|
+
marker in lowered
|
|
3007
|
+
for marker in ("screenplay", "script", "book", "journal", "blog post")
|
|
3008
|
+
):
|
|
3009
|
+
return 1
|
|
3010
|
+
if "writing" in lowered or "wrote" in lowered:
|
|
3011
|
+
return 2
|
|
3012
|
+
return 4
|
|
3013
|
+
|
|
3014
|
+
|
|
3015
|
+
def _business_dialogue_marker_answer_support_rank(
|
|
3016
|
+
item: ContextItem,
|
|
3017
|
+
*,
|
|
3018
|
+
query_reason: str,
|
|
3019
|
+
) -> int:
|
|
3020
|
+
if not _is_business_commonality_reason(query_reason):
|
|
3021
|
+
return 0
|
|
3022
|
+
if _business_commonality_answer_content_rank(item.text) > 1:
|
|
3023
|
+
return 1
|
|
3024
|
+
return 0 if _DIALOGUE_MARKER_RE.search(item.text) is not None else 1
|
|
3025
|
+
|
|
3026
|
+
|
|
3027
|
+
def _is_business_commonality_reason(query_reason: str) -> bool:
|
|
3028
|
+
return query_reason in {"business_commonality_bridge", "business_start_reason_bridge"}
|
|
3029
|
+
|
|
3030
|
+
|
|
3031
|
+
_CHARITY_BRAND_CONCRETE_DEAL_RE = re.compile(
|
|
3032
|
+
r"\b(?:signed(?:\s+up)?|secure(?:d|s)?|landed)\b"
|
|
3033
|
+
r"(?=.{0,180}\b(?:brand|brands?|company|companies|organization|"
|
|
3034
|
+
r"organisations?|sponsor(?:ship|s)?|endorse(?:ment|d|s)?|deal|deals?|"
|
|
3035
|
+
r"gear|shoe|shoes|apparel|equipment)\b)|"
|
|
3036
|
+
r"\bin\s+talks?\s+with\b"
|
|
3037
|
+
r"(?=.{0,180}\b(?:sponsor(?:ship|s)?|endorse(?:ment|d|s)?|"
|
|
3038
|
+
r"partner(?:ship|ed|s)?|deal|deals?)\b)|"
|
|
3039
|
+
r"\b(?:deal|deals?|sponsor(?:ship|s)?|endorse(?:ment|d|s)?|"
|
|
3040
|
+
r"partner(?:ship|s)?)\b"
|
|
3041
|
+
r"(?=.{0,140}\b(?:signed(?:\s+up)?|secure(?:d|s)?|landed|"
|
|
3042
|
+
r"in\s+talks?\s+with|stoked|working\s+with)\b)",
|
|
3043
|
+
re.IGNORECASE | re.DOTALL,
|
|
3044
|
+
)
|
|
3045
|
+
|
|
3046
|
+
|
|
3047
|
+
def _charity_brand_sponsorship_answer_content_rank(text: str) -> int:
|
|
3048
|
+
slot = _charity_brand_sponsorship_answer_slot(text)
|
|
3049
|
+
if slot == "brand_sponsorship_deal":
|
|
3050
|
+
return 0 if _CHARITY_BRAND_CONCRETE_DEAL_RE.search(text) else 1
|
|
3051
|
+
if slot == "partner_affinity_fit":
|
|
3052
|
+
return 0
|
|
3053
|
+
if slot in {"charity_org_fit", "charity_intent"}:
|
|
3054
|
+
return 1
|
|
3055
|
+
if slot == "sports_brand_generic":
|
|
3056
|
+
return 2
|
|
3057
|
+
return 3
|
|
3058
|
+
|
|
3059
|
+
|
|
3060
|
+
def _activity_answer_content_rank(text: str) -> int:
|
|
3061
|
+
if _ACTIVITY_DIRECT_PARTICIPATION_RE.search(text) is not None:
|
|
3062
|
+
return 0
|
|
3063
|
+
if _general_activity_answer_slot_for_text(text.casefold()):
|
|
3064
|
+
return 1
|
|
3065
|
+
if _ACTIVITY_CONTEXT_RE.search(text) is not None:
|
|
3066
|
+
return 2
|
|
3067
|
+
return 4
|
|
3068
|
+
|
|
3069
|
+
|
|
3070
|
+
def _friend_place_shelter_answer_content_rank(text: str) -> int:
|
|
3071
|
+
if _INVENTORY_FRIEND_PLACE_DIRECT_RE.search(text):
|
|
3072
|
+
return 0
|
|
3073
|
+
if _INVENTORY_FRIEND_PLACE_SHELTER_ACTIVITY_REPEAT_RE.search(text):
|
|
3074
|
+
return 2
|
|
3075
|
+
if _INVENTORY_FRIEND_PLACE_SHELTER_ANCHOR_RE.search(text):
|
|
3076
|
+
return 0
|
|
3077
|
+
if _INVENTORY_SHELTER_SLOT_RE.search(text):
|
|
3078
|
+
return 1
|
|
3079
|
+
return 3
|
|
3080
|
+
|
|
3081
|
+
|
|
3082
|
+
def _animal_care_instruction_content_rank(text: str) -> int:
|
|
3083
|
+
if _ANIMAL_CARE_DIRECT_INSTRUCTION_RE.search(text):
|
|
3084
|
+
return 0
|
|
3085
|
+
if _ANIMAL_CARE_GENERIC_HABITAT_RE.search(text):
|
|
3086
|
+
return 3
|
|
3087
|
+
if re.search(r"\b(?:care|clean|feed|light|habitat|routine)\b", text, re.IGNORECASE):
|
|
3088
|
+
return 1
|
|
3089
|
+
return 2
|
|
3090
|
+
|
|
3091
|
+
|
|
3092
|
+
def _pottery_type_answer_content_rank(text: str) -> int:
|
|
3093
|
+
if _POTTERY_TYPE_DIRECT_MADE_OBJECT_RE.search(text):
|
|
3094
|
+
return 0
|
|
3095
|
+
if _POTTERY_TYPE_FRIENDSHIP_COMPANION_RE.search(text):
|
|
3096
|
+
return 1
|
|
3097
|
+
if _POTTERY_TYPE_PROJECT_COMPANION_RE.search(text):
|
|
3098
|
+
return 2
|
|
3099
|
+
if _POTTERY_TYPE_GENERIC_ANSWER_OBJECT_RE.search(text):
|
|
3100
|
+
return 3
|
|
3101
|
+
return 4
|