{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/scripts\/pipeline\/analyzers\/entity_extractor.py",
"offset": 380,
"limit": 60
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/scripts\/pipeline\/analyzers\/entity_extractor.py",
"content": " (entity[\"name\"], entity[\"type\"], description, canonical),\n )\n db.commit()\n entity_id = cursor.lastrowid\n cursor.close()\n\n db.log_provenance(\n artifact_type=\"entity\",\n artifact_id=entity_id,\n source_type=\"extraction\",\n source_id=document_id,\n pipeline_step=\"entity_extract\",\n )\n\n # Link entity to document via document_entities\n try:\n cursor = db.execute(\n \"\"\"INSERT IGNORE INTO document_entities (document_id, entity_id, relevance, created_at)\n VALUES (%s, %s, 0.8, NOW())\"\"\",\n (document_id, entity_id),\n )\n db.commit()\n cursor.close()\n except Exception as link_err:\n db.log(\"WARNING\", f\"Failed to link entity {entity_id} to document {document_id}: {link_err}\")\n\n stored += 1\n\n except Exception as e:\n db.log(\"WARNING\", f\"Failed to store entity: {e}\")\n\n return stored\n\n\ndef find_entity_by_name(name: str) -> dict | None:\n \"\"\"Find entity by name or canonical_name.\"\"\"\n name_lower = name.lower().strip()\n canonical = normalize_name(name)\n\n cursor = db.execute(\n \"SELECT id, name, canonical_name FROM entities WHERE canonical_name = %s LIMIT 1\",\n (canonical,),\n )\n result = cursor.fetchone()\n cursor.close()\n if result:\n return result\n\n cursor = db.execute(\n \"SELECT id, name, canonical_name FROM entities WHERE LOWER(name) = %s LIMIT 1\",\n (name_lower,),\n )\n result = cursor.fetchone()\n cursor.close()\n if result:\n return result\n\n cursor = db.execute(\n \"SELECT id, name, canonical_name FROM entities WHERE canonical_name LIKE %s LIMIT 1\",\n (f\"%{canonical}%\",),",
"numLines": 60,
"startLine": 380,
"totalLines": 444
}
}
}