Example #1
0
     list($par_id, $token_ids, $tags) = array($_POST['paragraph'], $_POST['tokens'], $_POST['types']);
     $id = add_ne_entity($par_id, $token_ids, $tags);
     $result['id'] = $id;
     break;
 case 'deleteEntity':
     if (empty($_POST['entity'])) {
         throw new Exception();
     }
     delete_ne_entity($_POST['entity']);
     break;
 case 'setTypes':
     if (empty($_POST['entity']) or empty($_POST['types'])) {
         throw new Exception();
     }
     list($entity_id, $tags) = array($_POST['entity'], $_POST['types']);
     set_ne_tags($entity_id, $tags);
     break;
 case 'newMention':
     if (empty($_POST['entities']) || empty($_POST['object_type'])) {
         throw new UnexpectedValueException();
     }
     $result['id'] = add_mention($_POST['entities'], $_POST['object_type']);
     break;
 case 'deleteMention':
     if (empty($_POST['mention'])) {
         throw new UnexpectedValueException();
     }
     delete_mention($_POST['mention']);
     break;
 case 'deleteEntityFromMention':
     if (empty($_POST['entity'])) {
Example #2
0
function add_ne_entity($annot_id, $token_ids, $tags)
{
    // TODO check that tokens follow each other within the same sentence
    // for now presume that $token_ids[0] is the starting token
    if (!check_ne_paragraph_status($annot_id, $_SESSION['user_id'])) {
        throw new Exception();
    }
    sql_begin();
    sql_pe("\n        INSERT INTO ne_entities\n        (annot_id, start_token, length, updated_ts)\n        VALUES (?, ?, ?, ?)\n    ", array($annot_id, $token_ids[0], sizeof($token_ids), time()));
    $entity_id = sql_insert_id();
    set_ne_tags($entity_id, $tags, $annot_id);
    sql_commit();
    return $entity_id;
}