<commit_before>/**************************************************************************
*          (C) Vrije Universiteit, Amsterdam (the Netherlands)            *
*                                                                         *
* This file is part of AmCAT - The Amsterdam Content Analysis Toolkit     *
*                                                                         *
* AmCAT is free software: you can redistribute it and/or modify it under  *
* the terms of the GNU Affero General Public License as published by the  *
* Free Software Foundation, either version 3 of the License, or (at your  *
* option) any later version.                                              *
*                                                                         *
* AmCAT is distributed in the hope that it will be useful, but WITHOUT    *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public     *
* License for more details.                                               *
*                                                                         *
* You should have received a copy of the GNU Affero General Public        *
* License along with AmCAT.  If not, see <http://www.gnu.org/licenses/>.  *
***************************************************************************/

(function(){

annotator.articletable = {};
annotator.articletable.MAX_STR_COLUMN_LENGTH = 35; // length of string when limiting length (in article table for headline/comment)
annotator.articletable.articleTable = null;
annotator.articletable.articleEditForm = null;



/************* Article table *************/

annotator.articletable.selectRow = function(row){
    // select a row in the article table. used by goToNextRow and goToPreviousRow functions below
    row.addClass('row_selected');
    annotator.articletable.showArticleFromRow(row);
    var scroller = $('#article-table-container table').parent(); 
    $(scroller).scrollTo(row, {offset:-50});
}

annotator.articletable.goToNextRow = function(){
    // used for articles table, by continue buttons and 'next'
    if(!annotator.confirmArticleChange()) return;
    $('#article-table-container table .row_selected').each(function(){
        var row = $(this);
        if(row.next().length == 0){
            annotator.showMessage('last article reached!');
        } else {
            row.removeClass('row_selected');
            annotator.articletable.selectRow(row.next());
        }
    });
    
    if($('#article-table-container table .row_selected').length == 0) {
        // no selected row exists, pick first row
        var firstTr = $('#article-table-container table tbody tr:first')
        firstTr.addClass('row_selected');
        annotator.articletable.showArticleFromRow(firstTr);
    }
}

annotator.articletable.goToPreviousRow = function(){
    // used for articles table, by 'previous' button
    if(!annotator.confirmArticleChange()) return;
    $('#article-table-container table .row_selected').each(function(){
        var row = $(this);
        if(row.prev().length == 0){
            annotator.showMessage('first article reached!');
        } else {
            row.removeClass('row_selected');
            annotator.articletable.selectRow(row.prev());
        }
    });
}

MAX_LABELS_HIGHLIGHT = 30;

annotator.articletable.highlight = function(){
    console.log("Highlighting all labels in article..");
    $.each(annotator.fields.ontologies, function(ont_id, ont){
        // For each ontology
        var labels = [];
        $.each(ont, function(code_id, code){
            labels.push(code.label);
        });

        if (labels.length > MAX_LABELS_HIGHLIGHT){
            console.log("Highlighting this much labels (" + labels.length + ") causes performance to degrade");
            return;
        }

        $("div.sentences").easymark("highlight", labels.join(" ")); 
    });
};

// Function to force redraw (recalculation) of element
var redraw = function(){
    var ut = $("#unitcoding-table");
    var _prev = ut.css("display");
    ut.css("display", "none");
    ut.css("display", _prev);
}
<commit_msg>Escaping label before putting it in regex<commit_after>/**************************************************************************
*          (C) Vrije Universiteit, Amsterdam (the Netherlands)            *
*                                                                         *
* This file is part of AmCAT - The Amsterdam Content Analysis Toolkit     *
*                                                                         *
* AmCAT is free software: you can redistribute it and/or modify it under  *
* the terms of the GNU Affero General Public License as published by the  *
* Free Software Foundation, either version 3 of the License, or (at your  *
* option) any later version.                                              *
*                                                                         *
* AmCAT is distributed in the hope that it will be useful, but WITHOUT    *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public     *
* License for more details.                                               *
*                                                                         *
* You should have received a copy of the GNU Affero General Public        *
* License along with AmCAT.  If not, see <http://www.gnu.org/licenses/>.  *
***************************************************************************/

(function(){

annotator.articletable = {};
annotator.articletable.MAX_STR_COLUMN_LENGTH = 35; // length of string when limiting length (in article table for headline/comment)
annotator.articletable.articleTable = null;
annotator.articletable.articleEditForm = null;



/************* Article table *************/

annotator.articletable.selectRow = function(row){
    // select a row in the article table. used by goToNextRow and goToPreviousRow functions below
    row.addClass('row_selected');
    annotator.articletable.showArticleFromRow(row);
    var scroller = $('#article-table-container table').parent(); 
    $(scroller).scrollTo(row, {offset:-50});
}

annotator.articletable.goToNextRow = function(){
    // used for articles table, by continue buttons and 'next'
    if(!annotator.confirmArticleChange()) return;
    $('#article-table-container table .row_selected').each(function(){
        var row = $(this);
        if(row.next().length == 0){
            annotator.showMessage('last article reached!');
        } else {
            row.removeClass('row_selected');
            annotator.articletable.selectRow(row.next());
        }
    });
    
    if($('#article-table-container table .row_selected').length == 0) {
        // no selected row exists, pick first row
        var firstTr = $('#article-table-container table tbody tr:first')
        firstTr.addClass('row_selected');
        annotator.articletable.showArticleFromRow(firstTr);
    }
}

annotator.articletable.goToPreviousRow = function(){
    // used for articles table, by 'previous' button
    if(!annotator.confirmArticleChange()) return;
    $('#article-table-container table .row_selected').each(function(){
        var row = $(this);
        if(row.prev().length == 0){
            annotator.showMessage('first article reached!');
        } else {
            row.removeClass('row_selected');
            annotator.articletable.selectRow(row.prev());
        }
    });
}

MAX_LABELS_HIGHLIGHT = 30;

annotator.articletable.highlight = function(){
    console.log("Highlighting all labels in article..");
    $.each(annotator.fields.ontologies, function(ont_id, ont){
        var escape_regex = function(str) {
          return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
        };

        // For each ontology
        var labels = [];
        $.each(ont, function(code_id, code){
            labels.push(escape_regex(code.label));
        });

        if (labels.length > MAX_LABELS_HIGHLIGHT){
            console.log("Highlighting this much labels (" + labels.length + ") causes performance to degrade");
            return;
        }

        $("div.sentences").easymark("highlight", labels.join(" ")); 
    });
};

// Function to force redraw (recalculation) of element
var redraw = function(){
    var ut = $("#unitcoding-table");
    var _prev = ut.css("display");
    ut.css("display", "none");
    ut.css("display", _prev);
}

{'fraction_non_alphanumeric': 0.1536750936329588, 'fraction_numerical': 0.0023408239700374533, 'mean_word_length': 2.2739463601532566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7245891', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2101, 'n_words': 589}