<commit_before>/** @format */
import "./sidebar.scss"
export const sidebarName = "sidebar"
import statemachine from "../statemachine"

let html = String.raw
export const sidebarComponent = {
    template: html`
        <div class="sticky top-10 border border-gray-500 p-2 rounded-sm" ng-show="$ctrl.corpusObj">
            <div>
                <h4>{{'corpus' | loc:$root.lang}}</h4>
                <div>{{$ctrl.corpusObj.title}}</div>
            </div>
            <div
                class="openReadingMode"
                ng-show="!$ctrl.inReadingMode && $ctrl.corpusObj.readingMode"
            >
                <span ng-click="$ctrl.openReadingMode()" class="link">
                    {{'read_in_korp' | loc:$root.lang}}
                </span>
            </div>
            <div id="selected_sentence" />
            <div id="selected_word" />

            <div
                ng-show="$ctrl.corpusObj.attributes.deprel"
                ng-click="$ctrl.renderGraph()"
                class="link show_deptree"
            >
                {{'show_deptree' | loc:$root.lang}}
            </div>
        </div>
    `,
    bindings: {
        onShow: "&",
        onHide: "&",
    },
    controller: [
        "$element",
        "utils",
        "$rootScope",
        "$compile",
        "$controller",
        function ($element, utils, $rootScope, $compile, $controller) {
            let $ctrl = this

            statemachine.listen("select_word", function (data) {
                safeApply($rootScope, () => {
                    if (data == null) {
                        $ctrl.onHide()
                    } else {
                        $ctrl.onShow()
                        $ctrl.updateContent(data)
                    }
                })
            })

            Object.assign($ctrl, {
                openReadingMode() {
                    $rootScope.textTabs.push({
                        corpus: $ctrl.corpusObj.id,
                        sentenceId: $ctrl.sentenceData.sentence_id,
                    })
                },
                updateContent({ sentenceData, wordData, corpus, tokens, inReadingMode }) {
                    $("#selected_sentence").add("#selected_word").empty()
                    // TODO: this is pretty broken
                    const corpusObj = settings.corpora[corpus] || settings.corpusListing.get(corpus)
                    $ctrl.corpusObj = corpusObj
                    $ctrl.sentenceData = sentenceData
                    $ctrl.inReadingMode = inReadingMode

                    const customData = { pos: [], struct: [] }
                    if (!$.isEmptyObject(corpusObj.customAttributes)) {
                        const [word, sentence] = this.renderCustomContent(
                            wordData,
                            sentenceData,
                            corpusObj.customAttributes,
                            tokens
                        )
                        customData.pos = word
                        customData.struct = sentence
                    }

                    let posData = []
                    if (!$.isEmptyObject(corpusObj.attributes)) {
                        posData = this.renderCorpusContent(
                            "pos",
                            wordData,
                            sentenceData,
                            corpusObj.attributes,
                            tokens,
                            corpusObj.customAttributes || {},
                            customData.pos<commit_msg>fixed broken deptree for new sidebar component.<commit_after>/** @format */
import "./sidebar.scss"
export const sidebarName = "sidebar"
import statemachine from "../statemachine"

let html = String.raw
export const sidebarComponent = {
    template: html`
        <div class="sticky top-10 border border-gray-500 p-2 rounded-sm" ng-show="$ctrl.corpusObj">
            <div>
                <h4>{{'corpus' | loc:$root.lang}}</h4>
                <div>{{$ctrl.corpusObj.title}}</div>
            </div>
            <div
                class="openReadingMode"
                ng-show="!$ctrl.inReadingMode && $ctrl.corpusObj.readingMode"
            >
                <span ng-click="$ctrl.openReadingMode()" class="link">
                    {{'read_in_korp' | loc:$root.lang}}
                </span>
            </div>
            <div id="selected_sentence" />
            <div id="selected_word" />

            <div
                ng-show="$ctrl.corpusObj.attributes.deprel"
                ng-click="$ctrl.renderGraph()"
                class="link show_deptree"
            >
                {{'show_deptree' | loc:$root.lang}}
            </div>
        </div>
    `,
    bindings: {
        onShow: "&",
        onHide: "&",
    },
    controller: [
        "$element",
        "utils",
        "$rootScope",
        "$compile",
        "$controller",
        function ($element, utils, $rootScope, $compile, $controller) {
            let $ctrl = this

            statemachine.listen("select_word", function (data) {
                safeApply($rootScope, () => {
                    if (data == null) {
                        $ctrl.onHide()
                    } else {
                        $ctrl.onShow()
                        $ctrl.updateContent(data)
                    }
                })
            })

            Object.assign($ctrl, {
                openReadingMode() {
                    $rootScope.textTabs.push({
                        corpus: $ctrl.corpusObj.id,
                        sentenceId: $ctrl.sentenceData.sentence_id,
                    })
                },
                updateContent({ sentenceData, wordData, corpus, tokens, inReadingMode }) {
                    $("#selected_sentence").add("#selected_word").empty()
                    // TODO: this is pretty broken
                    const corpusObj = settings.corpora[corpus] || settings.corpusListing.get(corpus)
                    $ctrl.corpusObj = corpusObj
                    $ctrl.sentenceData = sentenceData
                    $ctrl.inReadingMode = inReadingMode
                    $ctrl.tokens = tokens
                    const customData = { pos: [], struct: [] }
                    if (!$.isEmptyObject(corpusObj.customAttributes)) {
                        const [word, sentence] = this.renderCustomContent(
                            wordData,
                            sentenceData,
                            corpusObj.customAttributes,
                            tokens
                        )
                        customData.pos = word
                        customData.struct = sentence
                    }

                    let posData = []
                    if (!$.isEmptyObject(corpusObj.attributes)) {
                        posData = this.renderCorpusContent(
                            "pos",
                            wordData,
                            sentenceData,
                            corpusObj.attributes,
                            tokens,
                            corpusObj.customAttributes || {},
                            customData.pos
{'fraction_non_alphanumeric': 0.11183935294937944, 'fraction_numerical': 0.0022312090363965976, 'mean_word_length': 1.1112746541065646, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, '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': '7299070', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1682, 'n_words': 299}