$paragraph['mine'] = true; } if (in_array($paragraph['id'], $paragraphs_status['done_by_user'])) { $paragraph['done_by_me'] = true; } // если текущий пользователь - модератор, забираем разметку других пользователей if (!$is_book_moderator) { continue; } $annotators = get_paragraph_annotators($paragraph['id'], $tagset_id); $paragraph['all_annotations'] = array(); foreach ($annotators as $user_id) { $paragraph['all_annotations'][$user_id] = array(); $PAR =& $paragraph['all_annotations'][$user_id]; $ne = get_ne_by_paragraph($paragraph['id'], $user_id, $tagset_id); $mentions = get_ne_by_paragraph($paragraph['id'], $user_id, $tagset_id, TRUE); $PAR['named_entities'] = isset($ne['entities']) ? $ne['entities'] : array(); $PAR['mentions'] = isset($mentions['entities']) ? $mentions['entities'] : array(); $PAR['user_shown_name'] = get_user_shown_name($user_id); $PAR['annotation_id'] = isset($ne['annot_id']) ? $ne['annot_id'] : 0; $PAR['ne_by_token'] = get_ne_tokens_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id); $PAR['comments'] = get_comments_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id); } } if ($is_book_moderator) { $spans = get_ne_entities_by_book($book_id, $_SESSION['user_id'], $tagset_id); $spans = array_unique(array_map(function ($span) { $tokens = ''; foreach ($span['tokens'] as $t) { $tokens .= $t[1] . ' '; }
function get_all_ne_by_paragraph($par_id, $tagset_id, $group_by_mention = false) { $users = sql_pe("SELECT user_id FROM ne_paragraphs WHERE is_moderator = 0 AND par_id = ? AND tagset_id = ? AND status = ?", array($par_id, $tagset_id, NE_STATUS_FINISHED)); $data = []; foreach ($users as $user) { $user_id = $user["user_id"]; $data[$user_id] = get_ne_by_paragraph($par_id, $user_id, $tagset_id, $group_by_mention); } return $data; }
$smarty->assign('book', $book); $smarty->assign('token_groups', $groups); $smarty->display('syntax/book.tpl'); } else { throw new UnexpectedValueException(); } } elseif ($action == 'ner') { //check_permission(PERM_SYNTAX); check_logged(); if (isset($_GET['book_id']) && ($book_id = $_GET['book_id'])) { $tagset_id = get_current_tagset(); $book = get_book_page($book_id, TRUE); $paragraphs_status = get_ne_paragraph_status($book_id, $_SESSION['user_id'], $tagset_id); foreach ($book['paragraphs'] as &$paragraph) { $ne = get_ne_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id); $mentions = get_ne_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id, TRUE); $paragraph['named_entities'] = isset($ne['entities']) ? $ne['entities'] : array(); $paragraph['mentions'] = isset($mentions['entities']) ? $mentions['entities'] : array(); $paragraph['annotation_id'] = isset($ne['annot_id']) ? $ne['annot_id'] : array(); $paragraph['ne_by_token'] = get_ne_tokens_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id); $paragraph['comments'] = get_comments_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id); $paragraph['mine'] = false; if (in_array($paragraph['id'], $paragraphs_status['unavailable']) or in_array($paragraph['id'], $paragraphs_status['done_by_user'])) { $paragraph['disabled'] = true; } elseif (in_array($paragraph['id'], $paragraphs_status['started_by_user'])) { $paragraph['mine'] = true; } } $smarty->assign('book', $book); $smarty->assign('use_fast_mode', OPTION(OPT_NE_QUICK)); $smarty->assign('possible_guidelines', array(1 => "Default (2014)", 2 => "Dialogue Eval (2016)"));
function get_ne_tokens_by_paragraph($par_id, $user_id, $tagset_id) { $annot = get_ne_by_paragraph($par_id, $user_id, $tagset_id); $tokens = array(); $res = sql_pe("\n SELECT tf_id\n FROM tokens\n JOIN sentences USING (sent_id)\n WHERE par_id = ?\n ", array($par_id)); foreach ($res as $r) { $tokens[$r['tf_id']] = array(); } if (empty($annot['entities'])) { return $tokens; } foreach ($annot['entities'] as $e) { foreach ($e['tokens'] as $token) { $ne = array('tags' => $e['tags'], 'entity_id' => $e['id']); $tokens[$token[0]][] = $ne; } } return $tokens; }