{% macro tidy(name) -%}
  {{ name.replace('_', ' ')}}
{%- endmacro %}

===Task===
Extract entities and knowledge triplets from the given statement.

{% if language == "zh" %}
**重要：请使用中文生成实体名称（name）、描述（description）和示例（example）。**
{% else %}
**Important: Please generate entity names, descriptions and examples in English. If the original text is in Chinese, translate entity names to English.**
{% endif %}

===Inputs===
**Chunk Content:** "{{ chunk_content }}"
**Statement:** "{{ statement }}"

{% if ontology_types %}
===Ontology Type Guidance===

**CRITICAL RULE: You MUST ONLY use the predefined ontology type names listed below for the entity "type" field. Do NOT use any other type names, even if they seem reasonable.**

**If no predefined type fits an entity, use the CLOSEST matching predefined type. NEVER invent new type names.**

**Type Priority (from highest to lowest):**
1. **[场景类型] Scene Types** - Domain-specific types, ALWAYS prefer these first
2. **[通用类型] General Types** - Common types from standard ontologies (DBpedia)
3. **[通用父类] Parent Types** - Provide type hierarchy context

**Type Matching Rules:**
- Entity type MUST exactly match one of the predefined type names below
- Do NOT use types like "Equipment", "Component", "Concept", "Action", "Condition", "Data", "Duration" unless they appear in the predefined list
- Do NOT modify, translate, abbreviate, or create variations of type names
- Prefer scene types (marked [场景类型]) over general types when both could apply
- If uncertain, check the type description to find the best match

**Predefined Ontology Types:**
{{ ontology_types }}

{% if type_hierarchy_hints %}
**Type Hierarchy Reference:**
The following shows type inheritance relationships (Child → Parent → Grandparent):
{% for hint in type_hierarchy_hints %}
- {{ hint }}
{% endfor %}
{% endif %}

**ALLOWED Type Names (use EXACTLY one of these, no exceptions):**
{{ ontology_type_names | join(', ') }}

{% endif %}
===Guidelines===

**Entity Extraction:**
- Extract entities with their types, context-independent descriptions, **concise examples**, aliases, and semantic memory classification
{% if language == "zh" %}
- **实体名称（name）必须使用中文**
- **实体描述（description）必须使用中文**
- **示例（example）必须使用中文**
{% else %}
- **Entity names must be in English** (translate if the original is in another language)
- **Entity descriptions must be in English**
- **Examples must be in English**
{% endif %}
- **Semantic Memory Classification (is_explicit_memory):**
  * Set to `true` if the entity represents **explicit/semantic memory**:
    - **Concepts:** "Machine Learning", "Photosynthesis", "Democracy"
    - **Knowledge:** "Python Programming Language", "Theory of Relativity"
    - **Definitions:** "API (Application Programming Interface)", "REST API"
    - **Principles:** "SOLID Principles", "First Law of Thermodynamics"
    - **Theories:** "Evolution Theory", "Quantum Mechanics"
    - **Methods/Techniques:** "Agile Development", "Machine Learning Algorithm"
    - **Technical Terms:** "Neural Network", "Database"
  * Set to `false` for:
    - **People:** "John Smith", "Dr. Wang"
    - **Organizations:** "Microsoft", "Harvard University"
    - **Locations:** "Beijing", "Central Park"
    - **Events:** "2024 Conference", "Project Meeting"
    - **Specific objects:** "iPhone 15", "Building A"
- **Example Generation (IMPORTANT for semantic memory entities):**
  * For entities where `is_explicit_memory=true`, generate a **concise example (around 20 characters)** to help understand the concept
  * The example should be:
    - **Specific and concrete**: Use real-world scenarios or applications
    - **Brief**: Around 20 characters (can be slightly longer if needed for clarity)
{% if language == "zh" %}
    - **使用中文**
{% else %}
    - **In English**
{% endif %}
  * For non-semantic entities (`is_explicit_memory=false`), the example field can be empty
- **Aliases Extraction:**
{% if language == "zh" %}
  * 别名使用中文
{% else %}
  * Aliases should be in English
{% endif %}
  * Include common alternative names, abbreviations and full names
  * If no aliases exist, use empty array: []
- Exclude lengthy quotes, calendar dates, temporal ranges, and temporal expressions
- For numeric values: extract as separate entities (instance_of: 'Numeric', name: units, numeric_value: value)
  Example: £30 → name: 'GBP', numeric_value: 30, instance_of: 'Numeric'

**Triplet Extraction:**
- Extract (subject, predicate, object) triplets where:
  - Subject: main entity performing the action or being described
  - Predicate: relationship between entities (e.g., 'is', 'works at', 'believes')
  - Object: entity, value, or concept affected by the predicate
{% if language == "zh" %}
- subject_name 和 object_name 必须使用中文
{% else %}
- subject_name and object_name must be in English (translate if original is in another language)
{% endif %}
- Exclude all temporal expressions from every field
- Use ONLY the predicates listed in "Predicate Instructions" (uppercase English tokens)
- Do NOT translate predicate tokens
- Do NOT include `statement_id` field (assigned automatically)

**When NOT to extract triplets:**
- Non-propositional utterances (emotions, fillers, onomatopoeia)
- No clear predicate from the given definitions applies
- Standalone noun phrases or checklist items → extract as entities only
- Do NOT invent generic predicates (e.g., "IS_DOING", "FEELS", "MENTIONS")

**If no valid triplet exists:** Return triplets: [], extract entities if present, otherwise both arrays empty.
{%- if predicate_instructions -%}

**Predicate Instructions:**
Use ONLY these predicates. If none fits, set triplets to [].
{%- for pred, instruction in predicate_instructions.items() %}
- {{ pred }}: {{ instruction }}
{%- endfor -%}
{%- endif -%}


===Examples===
{% if language == "en" %}
**Example 1 (English output):** "I plan to travel to Paris next week and visit the Louvre."
Output:
{
  "triplets": [
    {"subject_name": "I", "subject_id": 0, "predicate": "PLANS_TO_VISIT", "object_name": "Paris", "object_id": 1, "value": null},
    {"subject_name": "I", "subject_id": 0, "predicate": "PLANS_TO_VISIT", "object_name": "Louvre", "object_id": 2, "value": null}
  ],
  "entities": [
    {"entity_idx": 0, "name": "I", "type": "Person", "description": "The user", "example": "", "aliases": [], "is_explicit_memory": false},
    {"entity_idx": 1, "name": "Paris", "type": "Location", "description": "Capital city of France", "example": "", "aliases": [], "is_explicit_memory": false},
    {"entity_idx": 2, "name": "Louvre", "type": "Location", "description": "World-famous museum located in Paris", "example": "", "aliases": ["Louvre Museum"], "is_explicit_memory": false}
  ]
}

**Example 2 (Chinese input → English output - IMPORTANT: translate entity names):** "张明在腾讯工作，负责AI产品开发。"
Output:
{
  "triplets": [
    {"subject_name": "Zhang Ming", "subject_id": 0, "predicate": "WORKS_AT", "object_name": "Tencent", "object_id": 1, "value": null},
    {"subject_name": "Zhang Ming", "subject_id": 0, "predicate": "RESPONSIBLE_FOR", "object_name": "AI product development", "object_id": 2, "value": null}
  ],
  "entities": [
    {"entity_idx": 0, "name": "Zhang Ming", "type": "Person", "description": "Individual person name", "example": "", "aliases": [], "is_explicit_memory": false},
    {"entity_idx": 1, "name": "Tencent", "type": "Organization", "description": "Chinese technology company", "example": "", "aliases": ["Tencent Holdings"], "is_explicit_memory": false},
    {"entity_idx": 2, "name": "AI product development", "type": "Concept", "description": "Artificial intelligence product development work", "example": "e.g., developing chatbots", "aliases": [], "is_explicit_memory": true}
  ]
}

**Example 3 (Chinese input → English output):** "三脚架"
Output:
{
  "triplets": [],
  "entities": [
    {"entity_idx": 0, "name": "Tripod", "type": "Equipment", "description": "Photography equipment accessory", "example": "", "aliases": ["Camera Tripod"], "is_explicit_memory": false}
  ]
}
{% else %}
**Example 1 (English input → Chinese output):** "I plan to travel to Paris next week and visit the Louvre."
Output:
{
  "triplets": [
    {"subject_name": "我", "subject_id": 0, "predicate": "PLANS_TO_VISIT", "object_name": "巴黎", "object_id": 1, "value": null},
    {"subject_name": "我", "subject_id": 0, "predicate": "PLANS_TO_VISIT", "object_name": "卢浮宫", "object_id": 2, "value": null}
  ],
  "entities": [
    {"entity_idx": 0, "name": "我", "type": "Person", "description": "用户本人", "example": "", "aliases": [], "is_explicit_memory": false},
    {"entity_idx": 1, "name": "巴黎", "type": "Location", "description": "法国首都城市", "example": "", "aliases": [], "is_explicit_memory": false},
    {"entity_idx": 2, "name": "卢浮宫", "type": "Location", "description": "位于巴黎的世界著名博物馆", "example": "", "aliases": [], "is_explicit_memory": false}
  ]
}

**Example 2 (Chinese input → Chinese output):** "张明在腾讯工作，负责AI产品开发。"
Output:
{
  "triplets": [
    {"subject_name": "张明", "subject_id": 0, "predicate": "WORKS_AT", "object_name": "腾讯", "object_id": 1, "value": null},
    {"subject_name": "张明", "subject_id": 0, "predicate": "RESPONSIBLE_FOR", "object_name": "AI产品开发", "object_id": 2, "value": null}
  ],
  "entities": [
    {"entity_idx": 0, "name": "张明", "type": "Person", "description": "个人姓名", "example": "", "aliases": [], "is_explicit_memory": false},
    {"entity_idx": 1, "name": "腾讯", "type": "Organization", "description": "中国科技公司", "example": "", "aliases": ["腾讯控股", "腾讯公司"], "is_explicit_memory": false},
    {"entity_idx": 2, "name": "AI产品开发", "type": "Concept", "description": "人工智能产品研发工作", "example": "如：开发智能客服机器人", "aliases": [], "is_explicit_memory": true}
  ]
}

**Example 3 (Entity Only - Chinese):** "三脚架"
Output:
{
  "triplets": [],
  "entities": [
    {"entity_idx": 0, "name": "三脚架", "type": "Equipment", "description": "摄影器材配件", "example": "", "aliases": ["相机三脚架"], "is_explicit_memory": false}
  ]
}
{% endif %}
===End of Examples===

{% if ontology_types %}
**⚠️ REMINDER: The examples above use generic type names for illustration only. You MUST use ONLY the predefined ontology type names from the "ALLOWED Type Names" list above. For example, use "PredictiveMaintenance" instead of "Concept", use "ProductionLine" instead of "Equipment", etc. Map each entity to the closest matching predefined type.**
{% endif %}

===Output Format===

**JSON Requirements:**
- Use only ASCII double quotes (") for JSON structure
- Never use Chinese quotation marks ("") or Unicode quotes
- Escape quotation marks in text with backslashes (\")
- Ensure proper string closure and comma separation
- No line breaks within JSON string values
{% if language == "zh" %}
- **语言要求：实体名称（name）、描述（description）、示例（example）、subject_name、object_name 必须使用中文**
{% else %}
- **Language Requirement: Entity names, descriptions, examples, subject_name, object_name must be in English**
- **If the original text is in Chinese, translate all names to English**
{% endif %}

{{ json_schema }}
