Beispiel #1
0
     $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];
     break;
 case 'linkMentionToObject':
     if (empty($_POST['mention_id']) || empty($_POST['object_id'])) {
         throw new UnexpectedValueException();
     }
     link_mention_to_object($_POST['mention_id'], $_POST['object_id']);
     break;
 case 'deleteMentionFromObject':
     if (empty($_POST['mention_id'])) {
         throw new UnexpectedValueException();
     }
     link_mention_to_object($_POST['mention_id'], 0);
     break;
 case 'updateObjectProperty':
     if (empty($_POST['val_id']) || empty($_POST['prop_value'])) {
Beispiel #2
0
function get_book_objects($book_id)
{
    $obj_res = sql_pe("SELECT object_id FROM ne_objects WHERE book_id = ? ORDER BY object_id", array($book_id));
    $object_ids = array();
    $objects = array();
    foreach ($obj_res as $r) {
        $id = $r["object_id"];
        $object_ids[] = $id;
        $objects[$id] = array("object_id" => $id, "properties" => array(), "mentions" => array());
    }
    if (!empty($object_ids)) {
        // get properties
        $prop_res = sql_query("SELECT object_id, val_id, prop_id, prop_key, prop_val FROM ne_object_prop_vals LEFT JOIN ne_object_props USING (prop_id) WHERE object_id IN (" . implode(",", $object_ids) . ") ORDER BY object_id, prop_id");
        while ($rp = sql_fetch_array($prop_res)) {
            $objects[$rp["object_id"]]["properties"][$rp["val_id"]] = array($rp["prop_id"], $rp["prop_key"], $rp["prop_val"]);
        }
        // get mentions
        $mentions = get_mentions_text_by_objects($object_ids);
        foreach ($mentions as $oid => $arr) {
            $objects[$oid]["mentions"] = $arr;
        }
    }
    return $objects;
}