<commit_before>// Class for the Link properties tab that appears when link settings are clicked.

var LinkInspector = Backbone.View.extend({

    className: 'link-inspec',

    template: [
        '<label id="title">Constant Relationship</label>',
        '<br>',
        '<select id="constant-links" class="link-type">',
            '<option value="no">No Relationship</option>',
            '<option value="and">And-Decomposition</option>',
            '<option value="or">Or-Decomposition</option>',
            '<option value="++">++</option>',
            '<option value="--">--</option>',
            '<option value="+">+</option>',
            '<option value="-">-</option>',
            '<option value="+S">+S</option>',
            '<option value="++S">++S</option>',
            '<option value="-S">-S</option>',
            '<option value="--S">--S</option>',
            '<option value="+D">+D</option>',
            '<option value="++D">++D</option>',
            '<option value="-D">-D</option>',
            '<option value="--D">--D</option>',
            '<option value="NBT">Not Both (None)</option>',
            '<option value="NBD">Not Both (Denied)</option>',
        '</select>',
        '<h5 id="repeat-error" class="inspector-error"></h5>',
            '<button id="switch-link-type" class="inspector-btn small-btn blue-btn">Evolving Relationships</button>',
        '<br>'
    ].join(''),

    evolvingtemplate : [
            '<label id="title">Evolving Relationship</label>',
            '<br>',
            '<h5 id="repeat-error" class="inspector-error"></h5>',
            '<select id="link-type-begin" class="repeat-select">',
            '</select>',
            '<select id="link-type-end" class="repeat-select">',
            '</select>',
            '<button id="switch-link-type" class="inspector-btn small-btn blue-btn">Constant Relationships</button>',
            '<br>'
    ].join(''),

    actortemplate: [
            '<label> Link Type </label> <br>',
            '<select id="actor-link" class="link-type">',
                '<option value="is-a">is-a</option>',
                '<option value="plays">plays</option>',
                '<option value="is-part-of">is-part-of</option>',
            '</select><br>'].join(''),

    events: {
            'click #switch-link-type': 'switchMode',
            'change #constant-links': 'updateConstantRelationship',
            'change #actor-link': 'updateActorLink',
            'change #link-type-begin': 'updateBeginEvolRelations',
            'change #link-type-end': 'updateEndEvolRelations',
    },

    //Method to create the Link Inspector using the template.
    render: function(cellView) {
        this._cellView = cellView;
        var cell = this._cellView.model;
        var type = cellView.model.attributes.labels[0].attrs.text.text;
        var values = type.split("|");

        // Selecting which template to render ACTOR-LINK or INTENTIONS-LINK
        if (cell.prop('linktype')) {
            this.$el.html(_.template(this.actortemplate)());
            $('#actor-link').val(cell.prop("link-type"));
        } else {
            // If there is more than one value for a link, it must be an 
            // evolving relationship. Display the evolving relationship template
            if ((values.length > 1)) {
                this.evolvingRelations = true;
                this.$el.html(_.template(this.evolvingtemplate)());
                this.setSelectValues('#link-type-begin', 'Evolving');
                $('#link-type-begin').val(values[0]).change();
                this.updateBeginEvolRelations();
                $('#link-type-end').val(values[1]);

            // Else, display the constant relationship template
            } else {
                this.evolvingRelations = false;
                this.$el.html(_.template(this.template)());
                // this.setSelectValues('#constant-links', 'Constant');
                $('#constant-links').val(values[0]);
            }
        }

        cell.on('remove', function() {
            this.$el.html('');
        }, this);

    },

    /**
     * Switches from Constant Relationship to Evolving Relationship
     * and vice-versa.
     *
     * This function is called on click for #switch-link-type
     */
    switchMode: function() {
        var cell = this._cellView.model;
        var type = cell.attributes.labels[0].attrs.text.text;

        // array of link values
        var values = type.split("|");

        this.evolvingRelations = !this.evolvingRelations;

        if (this.evolvingRelations) {
            this.$el.html(_.template(this.evolvingtemplate)());
            if(values.length > 1) {
                this.setSelectValues('#link-type-begin', 'Evolving');
                $('#link-type-begin').val(values[0].trim()).change();
                this.updateBeginEvolRelations();
                $('#link-type-end').val(values[1].trim());
            } else {
                $("#link-type-end").prop('disabled', true);
                $("#link-type-end").css("background-color", "grey");
                this.setSelectValues('#link-type-begin', 'Evolving');
            }
        } else {
            this.$el.html(_.template(this.template)());
            this.setSelectValues('#constant-links', 'Constant');
            $('#constant-links').val(values[0].trim());
            this.evolvingRelations = false;
        }
    },

    /**
     * Saves the new constant relationship value to the link model.
     * This function is called on change for #constant-links.
     */
    updateConstantRelationship: function() {
        var link = this._cellView.model;
        var source = link.getSourceElement();
        var target = link.getTargetElement();

        var relationshipVal = $('.link-type option:selected').val();
        var relationshipText = $('.link-type option:selected').text();

        // store the new value into the link
        link.prop("link-type", relationshipVal);

        // store the new text into the link
        if (link.prop("link-type") == 'NBT' || link.prop("link-type") == 'NBD') {
            link.label(0 ,{position: 0.5, attrs: {text: {text: relationshipVal}}});
        } else {
            link.label(0 ,{position: 0.5, attrs: {text: {text: $('.link-type option:selected').text()}}});
        }

        // Adding or removing tags from node depending on type of link
        if (link.prop("link-type") == 'NBT' || link.prop("link-type") == 'NBD' || link.prop("link-type") == 'and' link.prop("link-type") == 'or') {
            source.attr(".funcvalue/text", "NB");
            source.attr(".satvalue/text", "");
            source.attr(".satvalue/value", "");
            target.attr(".funcvalue/text", "NB");
            target.attr(".satvalue/text", "");
            target.attr(".satvalue/value", "");

        } else {
            //Verify if it is possible to remove the NB tag from source and target
            if (!this.hasNBLink(source, link) && this.hasNBTag(source)){<commit_msg>Fixed a bug due to refactoring<commit_after>// Class for the Link properties tab that appears when link settings are clicked.

var LinkInspector = Backbone.View.extend({

    className: 'link-inspec',

    template: [
        '<label id="title">Constant Relationship</label>',
        '<br>',
        '<select id="constant-links" class="link-type">',
            '<option value="no">No Relationship</option>',
            '<option value="and">And-Decomposition</option>',
            '<option value="or">Or-Decomposition</option>',
            '<option value="++">++</option>',
            '<option value="--">--</option>',
            '<option value="+">+</option>',
            '<option value="-">-</option>',
            '<option value="+S">+S</option>',
            '<option value="++S">++S</option>',
            '<option value="-S">-S</option>',
            '<option value="--S">--S</option>',
            '<option value="+D">+D</option>',
            '<option value="++D">++D</option>',
            '<option value="-D">-D</option>',
            '<option value="--D">--D</option>',
            '<option value="NBT">Not Both (None)</option>',
            '<option value="NBD">Not Both (Denied)</option>',
        '</select>',
        '<h5 id="repeat-error" class="inspector-error"></h5>',
            '<button id="switch-link-type" class="inspector-btn small-btn blue-btn">Evolving Relationships</button>',
        '<br>'
    ].join(''),

    evolvingtemplate : [
            '<label id="title">Evolving Relationship</label>',
            '<br>',
            '<h5 id="repeat-error" class="inspector-error"></h5>',
            '<select id="link-type-begin" class="repeat-select">',
            '</select>',
            '<select id="link-type-end" class="repeat-select">',
            '</select>',
            '<button id="switch-link-type" class="inspector-btn small-btn blue-btn">Constant Relationships</button>',
            '<br>'
    ].join(''),

    actortemplate: [
            '<label> Link Type </label> <br>',
            '<select id="actor-link" class="link-type">',
                '<option value="is-a">is-a</option>',
                '<option value="plays">plays</option>',
                '<option value="is-part-of">is-part-of</option>',
            '</select><br>'].join(''),

    events: {
            'click #switch-link-type': 'switchMode',
            'change #constant-links': 'updateConstantRelationship',
            'change #actor-link': 'updateActorLink',
            'change #link-type-begin': 'updateBeginEvolRelations',
            'change #link-type-end': 'updateEndEvolRelations',
    },

    //Method to create the Link Inspector using the template.
    render: function(cellView) {
        this._cellView = cellView;
        var cell = this._cellView.model;
        var type = cellView.model.attributes.labels[0].attrs.text.text;
        var values = type.split("|");

        // Selecting which template to render ACTOR-LINK or INTENTIONS-LINK
        if (cell.prop('linktype')) {
            this.$el.html(_.template(this.actortemplate)());
            $('#actor-link').val(cell.prop("link-type"));
        } else {
            // If there is more than one value for a link, it must be an 
            // evolving relationship. Display the evolving relationship template
            if ((values.length > 1)) {
                this.evolvingRelations = true;
                this.$el.html(_.template(this.evolvingtemplate)());
                this.setSelectValues('#link-type-begin', 'Evolving');
                $('#link-type-begin').val(values[0]).change();
                this.updateBeginEvolRelations();
                $('#link-type-end').val(values[1]);

            // Else, display the constant relationship template
            } else {
                this.evolvingRelations = false;
                this.$el.html(_.template(this.template)());
                // this.setSelectValues('#constant-links', 'Constant');
                $('#constant-links').val(values[0]);
            }
        }

        cell.on('remove', function() {
            this.$el.html('');
        }, this);

    },

    /**
     * Switches from Constant Relationship to Evolving Relationship
     * and vice-versa.
     *
     * This function is called on click for #switch-link-type
     */
    switchMode: function() {
        var cell = this._cellView.model;
        var type = cell.attributes.labels[0].attrs.text.text;

        // array of link values
        var values = type.split("|");

        this.evolvingRelations = !this.evolvingRelations;

        if (this.evolvingRelations) {
            this.$el.html(_.template(this.evolvingtemplate)());
            if(values.length > 1) {
                this.setSelectValues('#link-type-begin', 'Evolving');
                $('#link-type-begin').val(values[0].trim()).change();
                this.updateBeginEvolRelations();
                $('#link-type-end').val(values[1].trim());
            } else {
                $("#link-type-end").prop('disabled', true);
                $("#link-type-end").css("background-color", "grey");
                this.setSelectValues('#link-type-begin', 'Evolving');
            }
        } else {
            this.$el.html(_.template(this.template)());
            this.setSelectValues('#constant-links', 'Constant');
            $('#constant-links').val(values[0].trim());
            this.evolvingRelations = false;
        }
    },

    /**
     * Saves the new constant relationship value to the link model.
     * This function is called on change for #constant-links.
     */
    updateConstantRelationship: function() {
        var link = this._cellView.model;
        var source = link.getSourceElement();
        var target = link.getTargetElement();

        var relationshipVal = $('.link-type option:selected').val();
        var relationshipText = $('.link-type option:selected').text();

        // store the new value into the link
        link.prop("link-type", relationshipVal);

        // store the new text into the link
        if (link.prop("link-type") == 'NBT' || link.prop("link-type") == 'NBD') {
            link.label(0 ,{position: 0.5, attrs: {text: {text: relationshipVal}}});
        } else {
            link.label(0 ,{position: 0.5, attrs: {text: {text: $('.link-type option:selected').text()}}});
        }

        // Adding or removing tags from node depending on type of link
        if (link.prop("link-type") == 'NBT' || link.prop("link-type") == 'NBD' || link.prop("link-type") == 'and' || link.prop("link-type") == 'or') {
            source.attr(".funcvalue/text", "NB");
            source.attr(".satvalue/text", "");
            source.attr(".satvalue/value", "");
            target.attr(".funcvalue/text", "NB");
            target.attr(".satvalue/text", "");
            target.attr(".satvalue/value", "");

        } else {
            //Verify if it is possible to remove the NB tag from source and target
            if (!this.hasNBLink(source, link) && this.hasNBTag(source)){
{'fraction_non_alphanumeric': 0.17984077338640886, 'fraction_numerical': 0.0028433323855558716, 'mean_word_length': 2.10642525943917, 'pattern_counts': {'":': 0, '<': 139, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1072573', 'n_tokens_mistral': 3941, 'n_tokens_neox': 3956, 'n_words': 798}