throw new Exception("entity_id or annot_id missing"); } $result['id'] = try_copy_ne_entity((int) $_POST['entity_id'], (int) $_POST['annot_id']); $result = array_merge($result, get_ne_entity_info($result['id'])); break; case 'copyAllEntities': if (empty($_POST['annot_from']) or empty($_POST['annot_to'])) { throw new Exception("one of annot ids missing"); } copy_all_entities($_POST['annot_from'], $_POST['annot_to']); break; case 'copyMention': if (empty($_POST['mention_id']) or empty($_POST['annot_id'])) { throw new Exception("mention_id or annot_id missing"); } $result['id'] = copy_ne_mention((int) $_POST['mention_id'], (int) $_POST['annot_id']); break; case 'copyAll': // copy mentions and entities not in mentions if (empty($_POST['annot_from']) or empty($_POST['annot_to'])) { throw new Exception("one of annot ids missing"); } copy_all_mentions_and_entities($_POST['annot_from'], $_POST['annot_to']); break; case 'createObject': if (empty($_POST['mentions']) || !is_array($_POST['mentions'])) { throw new UnexpectedValueException(); } $id = create_object_from_mentions($_POST['mentions']); $result['object_id'] = $id; $result['mentions'] = get_mentions_text_by_objects(array($id))[$id];
function copy_all_mentions_and_entities($annot_from, $annot_to) { sql_begin(); // copy mentions $res = sql_pe("\n SELECT DISTINCT mention_id\n FROM ne_entities_mentions\n LEFT JOIN ne_entities USING (entity_id)\n WHERE annot_id = ?\n ", array($annot_from)); foreach ($res as $m) { copy_ne_mention($m['mention_id'], $annot_to); } // copy entities not linked to mentions $res = sql_pe("\n SELECT entity_id\n FROM ne_entities\n WHERE annot_id = ?\n AND entity_id NOT IN (\n SELECT entity_id\n FROM ne_entities_mentions\n LEFT JOIN ne_entities USING (entity_id)\n WHERE annot_id = ?\n )\n ", array($annot_from, $annot_from)); foreach ($res as $e) { try_copy_ne_entity($e['entity_id'], $annot_to); } sql_commit(); }