{
"event": "PreToolUse",
"tool_name": "Bash",
"tool_input": {
"command": ".\/venv\/bin\/python -c \"\nfrom analyzers.relation_extractor import extract_relations\nfrom analyzers.entity_extractor import find_entity_by_name\nfrom db import db\n\ndb.connect()\n\n# Get full text\ncursor = db.execute('SELECT GROUP_CONCAT(content SEPARATOR \\\" \\\") as text FROM chunks WHERE document_id = 1')\ndoc = cursor.fetchone()\ncursor.close()\ntext = doc['text'][:8000]\n\n# Get ALL entities\ncursor = db.execute('SELECT name, type FROM entities')\nentities = [{'name': e['name'], 'type': e['type']} for e in cursor.fetchall()]\ncursor.close()\n\n# Extract relations\nrelations = extract_relations(text, entities[:30])\n\n# Store ALL relations\nstored = 0\nfor rel in relations:\n source = find_entity_by_name(rel['source'])\n target = find_entity_by_name(rel['target'])\n \n if source and target:\n cursor = db.execute(\n '''INSERT IGNORE INTO entity_relations \n (source_entity_id, target_entity_id, relation_type, created_at)\n VALUES (%s, %s, %s, NOW())''',\n (source['id'], target['id'], rel['relation'])\n )\n db.commit()\n cursor.close()\n stored += 1\n\n# Verify\ncursor = db.execute('SELECT COUNT(*) as cnt FROM entity_relations')\ncnt = cursor.fetchone()['cnt']\ncursor.close()\nprint(f'Stored: {stored}, Total in DB: {cnt}')\n\n# Show relations\ncursor = db.execute('''\n SELECT e1.name as source, er.relation_type, e2.name as target\n FROM entity_relations er\n JOIN entities e1 ON er.source_entity_id = e1.id\n JOIN entities e2 ON er.target_entity_id = e2.id\n''')\nfor r in cursor.fetchall():\n print(f' {r[\\\"source\\\"]} --[{r[\\\"relation_type\\\"]}]--> {r[\\\"target\\\"]}')\ncursor.close()\n\ndb.disconnect()\n\"",
"timeout": 120000,
"description": "Store all relations"
}
}
{
"tool_response": {
"stdout": "Stored: 0, Total in DB: 1\n Abwandlungen --[RELATED_TO]--> spielerische Kreativität",
"stderr": "",
"interrupted": false,
"isImage": false
}
}