From f1ab2f022fdc780aca0944d90e9a0e844a0820d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:12:17 +0200 Subject: =?UTF-8?q?2024-02-19:=20popravljen=20(prej=C5=A1nji=20commit=20je?= =?UTF-8?q?=20napa=C4=8Den)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/survey/script/LanguageTechnology_old.js | 841 -------------------------- 1 file changed, 841 deletions(-) delete mode 100644 admin/survey/script/LanguageTechnology_old.js (limited to 'admin/survey/script/LanguageTechnology_old.js') diff --git a/admin/survey/script/LanguageTechnology_old.js b/admin/survey/script/LanguageTechnology_old.js deleted file mode 100644 index a5302ff..0000000 --- a/admin/survey/script/LanguageTechnology_old.js +++ /dev/null @@ -1,841 +0,0 @@ -//var languageTechnology = []; -var var_timeout = 60000; -// test -var languageTechnologyResponse = {}; -var languageTechnology = {}; -var languageTechnologySettings = {}; -var languageTechnologyWordCache = {}; -var languageTechnologyWordCustom = {}; - -function cleanLanguageTechnology() { - //languageTechnology = []; - $('div#branching').find('.spremenljivka_content').each(function(){ - var spremenljivka = $(this).attr('spr_id'); - var $divContainer = $('li#branching_'+spremenljivka); - - $('#lt_'+spremenljivka).remove(); - $divContainer.find('span.highlight').tagRemover(); - - $divContainer.fadeTo(500, 1); - - }); -} -function runLanguageTechnology() { - - $('div#branching').find('.spremenljivka_content').each(function(){ - - var spremenljivka = $(this).attr('spr_id'); - var request = { - spremenljivka: spremenljivka, - anketa: srv_meta_anketa_id, - lt_language: $("#lt_language").val(), - lt_min_FWD: $("#lt_min_FWD").val(), - lt_min_nNoM: $("#lt_min_nNoM").val(), - lt_min_vNoM: $("#lt_min_vNoM").val() - }; - // nardimo ajax klic - $.ajax({ - cache: false, - timeout: var_timeout, - xhrFields: { withCredentials: true }, - url: 'ajax.php?a=runLanguageTechnology', - type: 'post', - //dataType: 'json', - data: request, - spremenljivka: spremenljivka, - container: $('li#branching_'+spremenljivka), - beforeSend: function() { - // odstranimo morebitne predhodne higlighte - cleanLanguageTechnology() - this.container.fadeTo(500, 0.4); - }, - success: function (response) { - - if (response['error'] != undefined) { - if (response['error']['hasError'] == true) { - alert(response['error']['msg']); - - // cleanUpAndReturn(); - return false; - } - delete response['error']; - } - if (response['setting'] != undefined) { - languageTechnologySettings = response['setting']; - delete response['setting']; - } - - // shranimo celoten response spremenljivke da potem lovimo shranjene podatke - languageTechnologyResponse[this.spremenljivka] = response; - - displayProblematicWords(this.spremenljivka); - - - return true; - }, - error: function(x, t, m) { - if(t==="timeout") { - alert("got timeout"); - } else { - alert('Prišlo je do neznane napake.'); - } - }, - complete: function() { - this.container.fadeTo(500, 1); - } - }); - - - }); -} - -function displayProblematicWords(spremenljivka) { - var $divContainer = $('li#branching_'+spremenljivka); - // pobrišemo obstoječe dive - $('#lt_'+spremenljivka).remove(); - - // narišemo vse nove potrebne dive - $divContainer.after( - $("
", { - id: 'lt_'+spremenljivka, - class: 'lt_div' - }) - .append( - $("
", {class: 'lt_word_data'}) - .append( - $("
", { - id: 'lt_words_'+spremenljivka, - class: 'lt_words', - }) - .on('click', 'ul li', function() { - wordIndex = $(this).index(); - displayProblematicWord(spremenljivka, wordIndex) - }) - .append( $('
', { - text: lang['srv_language_technology_flagged_wordings'], - class: 'lt_header' - })) - .append( - $("
    ", { - id: 'lt_words_ul_' + spremenljivka, - class: 'lt_word_list', - }) - ) - ) - ).append( $("
    ", { class: 'clr' })) // clear; - .append( $("
    ", { class: 'lt_word_synonym' })) - ); - - // dodamo seznam vseh besed - var words = languageTechnologyResponse[spremenljivka]; - $.each(words, function(wi, $wordData) { - - var $word = $wordData.word.toLowerCase(); - - // obarvamo besedo - $divContainer.find("*").highlight($word); - - $LTWord = $("
  • ") - - .append($('', {class: 'sprites'})) -// .append($('', {type: 'radio'})) - .append($('', {text: $word})) - .appendTo($("#lt_words_ul_" + spremenljivka)); - - }); - -} - -function displayProblematicWord(spremenljivka, wordIndex) { - // odstranimo podatke o besedi - $("#lt_word_hypernym_div_"+spremenljivka).remove(); - $("#lt_word_detail_div_"+spremenljivka).remove(); - - // holder ul = - $ul = $("#lt_words_ul_"+spremenljivka); - - // deaktiviramo ostale checkboxe in liste - $ul.find('li').removeClass('active'); - $ul.find('li span:first-child').removeClass('arrow_small2_r'); - - // aktiviramo izbran list in checkbox - $ul.find('li').eq(wordIndex).addClass('active'); - $ul.find('li').eq(wordIndex).find('span:first-child').addClass('arrow_small2_r'); - //$ul.find('li').eq(wordIndex).addClass('active'); - /* - wordHasSynonim = wordHasSynonims(spremenljivka, wordIndex); - if (wordHasSynonim) { - } else { - $ul.find('li').eq(wordIndex).removeClass('active'); - } - */ - // prikažemo podatke besede - var word = languageTechnologyResponse[spremenljivka][wordIndex]['word']; - var fwd = languageTechnologyResponse[spremenljivka][wordIndex]['FWD']; - var nom = languageTechnologyResponse[spremenljivka][wordIndex]['NoM']; - var tag = languageTechnologyResponse[spremenljivka][wordIndex]['Tag']; - var tag_lang = ""; - switch(tag) { - case 'n': - tag_lang = lang['srv_language_technology_noun']; - break; - case 'v': - tag_lang = lang['srv_language_technology_verb']; - break; - case 'a': - tag_lang = lang['srv_language_technology_adjective']; - break; - case 'ad': - tag_lang = lang['srv_language_technology_adverb']; - break; - case 'e': - tag_lang = lang['srv_language_technology_existential']; - break; - } - - - $LTWordDetailDiv = $("
    ", { - id: 'lt_word_detail_div_'+spremenljivka, - class: 'lt_word_detail_div', - - }) - .append( $('
    ', { - text: lang['srv_language_technology_wording_properites'], - class: 'lt_header no_padding'} - ) - ) - .append($("
    ").append($('', { text: 'Beseda: ' })).append($('', { text: word, class: 'strong' }))) - .append($("
    ").append($('', { text: 'FWD: ' })).append($('', { text: fwd }))) - .append($("
    ").append($('', { text: 'Tag: ' })).append( - // dodamo dropdown - $('').append($("', {type: 'checkbox'}))) - .append($('', {text: $synset.synonyms,})) - .appendTo($SynsetUl); - if (isSet) { - $SynsetLi.find('input').prop('checked', true); - } - - }); - index++; - } - - //if (!synsets.length) { - - isSet = isSetSynonim(spremenljivka, wordIndex, index); - selectedClass = ''; - if (isSet) { - selectedClass = 'selectedWord'; - } - $SynsetLi = $("
  • ", {class: selectedClass}) - .append($('').append($('', {type: 'checkbox'}))) - .append($('').append( - $('', {type:'text', value:getCustomWording(spremenljivka, wordIndex)}) - .on('change', function() { - words = $(this).val(); - addCustomWording(spremenljivka, wordIndex, words); - }) - )) - .appendTo($SynsetUl) - - if (isSet) { - $SynsetLi.find('input').prop('checked', true); - } - - // no wording - //$("#lt_words_synonyms_" + spremenljivka).html('

    ' + lang['srv_language_technology_no_alternative'] + '

    '); - //} - displayWordHypernym(spremenljivka, wordIndex); -} - -function displaySynonimHypernim(spremenljivka, wordIndex, synonymIndex) { - changeWordHypernym(spremenljivka, wordIndex, synonymIndex, checked); - - displayWordHypernym(spremenljivka, wordIndex); -} - -function displayWordHypernym(spremenljivka, wordIndex) { - // odstranimo stare podatke - $("#lt_word_hypernym_div_"+spremenljivka).remove(); - - // div za hypernime - $LTWordHypernymDiv = $("
    ", { - id: 'lt_word_hypernym_div_'+spremenljivka, - class: 'lt_word_hypernym_div', - }); - // polovimo vse hypernyme - hypernyms = getWordHypernyms(spremenljivka, wordIndex); - - if (!$.isEmptyObject(hypernyms)) { - $LTWordHypernymDiv - .empty() - .append( - $("
    ", {class: 'hypernym_header'}) - .append($('', { text: lang['srv_language_technology_alternative_wordings'] })) - .append($('', { text: 'WF*'})) - .append($('', { text: 'NoM'})) - ); - - $.each(hypernyms, function(i, Synset) { - $LTWordHypernymDiv.append($("
    ", {class: 'hypernym_details'}) - .append($('', { text: Synset['word'] })) - .append($('', { text: Synset['freq']})) - .append($('', { text: Synset['nom']})) - ); - }); - - - } else { - // ni hyperninov - $LTWordHypernymDiv - .empty() - .append( - $("
    ", {class:'lt_padding', text: lang['srv_language_technology_no_alternative_selected']}) - ); - - } - - $("#lt_words_synonyms_"+spremenljivka).after($LTWordHypernymDiv); - - return true; - - - - // odstranimo stare podatke - $("#lt_word_hypernym_div_"+spremenljivka).remove(); - - // div za hypernime - $LTWordHypernymDiv = $("
    ", { - id: 'lt_word_hypernym_div_'+spremenljivka, - class: 'lt_word_hypernym_div', - }) - .empty() - .append( - $("
    ", {class: 'hypernym_header'}) - .append($('', { text: lang['srv_language_technology_alternative_wordings'] })) - .append($('', { text: 'WF*'})) - .append($('', { text: 'NoM'})) - ); - $("#lt_words_synonyms_"+spremenljivka).after($LTWordHypernymDiv); -} - -function changeWordHypernym(spremenljivka, wordIndex, synonymIndex, checked) { - - if (checked) { - setSynonim(spremenljivka, wordIndex, synonymIndex); - } else { - unsetSynonim(spremenljivka, wordIndex, synonymIndex); - } - // holder ul = - $ul = $("#lt_words_synonyms_"+spremenljivka+" ul"); - isSet = isSetSynonim(spremenljivka, wordIndex, synonymIndex); - if (isSet) { - $ul.find('li').eq(synonymIndex).addClass('selectedWord'); - } else { - $ul.find('li').eq(synonymIndex).removeClass('selectedWord'); - } - - changeWordSynonym(spremenljivka, wordIndex); -} - -function changeWordSynonym(spremenljivka, wordIndex){ - wordHasSynonim = wordHasSynonims(spremenljivka, wordIndex); - if (wordHasSynonim ) { - $("#lt_words_ul_" + spremenljivka).find("li").eq(wordIndex).addClass('selectedWord'); - } else { - $("#lt_words_ul_" + spremenljivka).find("li").eq(wordIndex).removeClass('selectedWord'); - } -} - -function parseHypernyms(synsetsText, language) { - synsetWords = []; - // angleščina - if (language.toLowerCase() == 'eng') { - synsetArray = synsetsText.split(";"); - $.each(synsetArray, function(i, synsetText) { - if (synsetText.trim() != '' && synsetText != undefined) { - // linguistic: FW = 2457, NoM = 2; lingual: FW <800 , NoM = 2; - tmp = synsetText.split(':'); - word = tmp[0].trim(); - tmp = tmp[1].trim().split(','); - freq = tmp[0].replace('FW','').replace('= ', '').replace(';', '').trim(); - nom = tmp[1].replace('NoM','').replace('= ', '').replace(';', '').trim(); - synsetWords.push({word:word, nom:nom, freq:freq}); - } - }); - // slovenščina - } else { - synsetArray = synsetsText.split(";"); - $.each(synsetArray, function(i, synsetText) { - if (synsetText.trim() != '' && synsetText != undefined) { - tmp = synsetText.split(':'); - word = tmp[0].trim(); - tmp = tmp[1].trim().split(','); - freq = tmp[0].replace('FW','').replace('= ', '').replace(';', '').trim(); - nom = tmp[1].replace('NoM','').replace('= ', '').replace(';', '').trim(); - synsetWords.push({word:word, nom:nom, freq:freq}); - } - - }); - - } - - return synsetWords; -} - -function getCustomWording(spremenljivka, wordIndex) { - result = ''; - if (languageTechnologyWordCustom['sp_'+spremenljivka] != undefined) { - if (languageTechnologyWordCustom['sp_'+spremenljivka]['wi_'+wordIndex] != undefined) { - result = languageTechnologyWordCustom['sp_'+spremenljivka]['wi_'+wordIndex]; - } - } - //if (languageTechnologyWordCustom[spremenljivka+'_'+wordIndex] != undefined) { - // result = languageTechnologyWordCustom[spremenljivka+'_'+wordIndex]; - //} - return result; -} - -function addCustomWording(spremenljivka, wordIndex, words) { - if (languageTechnologyWordCustom['sp_'+spremenljivka] == undefined) { - languageTechnologyWordCustom['sp_'+spremenljivka] = {}; - } - if (languageTechnologyWordCustom['sp_'+spremenljivka]['wi_'+wordIndex] == undefined) { - languageTechnologyWordCustom['sp_'+spremenljivka]['wi_'+wordIndex] = words; - } - - - //languageTechnologyWordCustom[spremenljivka+'_'+wordIndex] = words; -} - - - -function setSynonim(spremenljivka, wordIndex, synonymIndex) { - if (languageTechnology['sp_'+spremenljivka] == undefined) { - languageTechnology['sp_'+spremenljivka] = {}; - } - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex] == undefined) { - languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex] = {}; - } - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]['si_'+synonymIndex] == undefined) { - languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]['si_'+synonymIndex] = '1'; - } - - enableDisableExcelExport(); -} - -function unsetSynonim(spremenljivka, wordIndex, synonymIndex) { - if (languageTechnology['sp_'+spremenljivka] != undefined) { - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex] != undefined) { - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]['si_'+synonymIndex] != undefined ) { - delete languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]['si_'+synonymIndex]; - } - if ($.isEmptyObject(languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex])) { - delete languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]; - } - } - if ($.isEmptyObject(languageTechnology['sp_'+spremenljivka])) { - delete languageTechnology['sp_'+spremenljivka]; - } - } - enableDisableExcelExport(); -} -function resetWordSynonyms(spremenljivka, wordIndex) { - if (languageTechnology['sp_'+spremenljivka] != undefined) { - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex] != undefined) { - wordHasSynonim = $.isEmptyObject(languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]) == false; - if (wordHasSynonim) { - $.each(languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex], function(si, synonymIndex) { - unsetSynonim(spremenljivka, wordIndex, si.replace('si_','')) - }); - } - } - } -} - -function isSetSynonim(spremenljivka, wordIndex, synonymIndex) { - isSet = false; - if (languageTechnology['sp_'+spremenljivka] != undefined) { - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex] != undefined) { - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]['si_'+synonymIndex] != undefined) { - isSet = true; - } - } - } - return isSet; -} - -function wordHasSynonims(spremenljivka, wordIndex) { - wordHasSynonim = false; - if (languageTechnology['sp_'+spremenljivka] != undefined) { - if (languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex] != undefined) { - wordHasSynonim = $.isEmptyObject(languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]) == false; - } - } - return wordHasSynonim; -} - - -function getWordHypernyms(spremenljivka, wordIndex) { - result = {}; - var synsetArray = languageTechnologyResponse[spremenljivka][wordIndex]['Synset']; - - izbrani = []; - if (wordHasSynonims(spremenljivka, wordIndex)) { - izbrani = languageTechnology['sp_'+spremenljivka]['wi_'+wordIndex]; - } - // jezik - if (languageTechnologySettings['lt_language'] != undefined) { - var language = languageTechnologySettings['lt_language']; - } else { - var language = $("#lt_language").val() - } - - - - $.each(synsetArray, function(i, synsetText) { - - if (izbrani['si_'+i] != undefined) { - hypernyms = parseHypernyms(synsetText['FWDNoM'], language); - $.each (hypernyms, function (i, hypernym) { - word = hypernym['word']; - if (result[word] == undefined) { - result[word] = hypernym; - } - }) - - //hypernyms.push(); - } - }); - return result; -} - -function enableDisableExcelExport() { - // preverimo ali imamp kak synonym - var has = false; - $.each(languageTechnology, function(spremenljvkaKey, spremenljivkaData) { - $.each(spremenljivkaData, function(wordKey, wordData) { - $.each(wordData, function(synsetKey, synsetData) { - has = true; - return false; // break - }); - if (has) { - return false; // break - } - }) - if (has) { - return false; // break - } - }); - if (has) { - $("#lt_export_excel span").removeClass("xls_grey_16 xls_16").addClass("xls_16"); - } else { - $("#lt_export_excel span").removeClass("xls_grey_16 xls_16").addClass("xls_grey_16"); - } - return has; -} - -function prepareExcelData() { - result = []; - izbrani = languageTechnology; - // naredimo kopijo mustang responsa, drugače so težave z referencami - var response = jQuery.extend(true, {}, languageTechnologyResponse); - - $.each(izbrani, function(spremenljvkaKey, spremenljivkaData) { - spremenljivka = spremenljvkaKey.replace('sp_',''); - $.each(spremenljivkaData, function(wordKey, wordData) { - word = wordKey.replace('wi_',''); - var wordSynonyms = []; - $.each(wordData, function(synsetKey, synsetData) { - sysnset = synsetKey.replace('si_',''); - wordSynonyms.push(response[spremenljivka][word]['Synset'][sysnset]); - }); - - var wd = jQuery.extend(true, {}, response[spremenljivka][word]); - delete wd['Synset']; - wd['synonyms'] = wordSynonyms; - - result.push({spremenljivka:spremenljivka, data:wd}); - }) - }); - return result; -} -function lt_export_excel() { - if (!enableDisableExcelExport()) { -// return false; - } - - var request = { - anketa: srv_meta_anketa_id, - mustangData: prepareExcelData(), - language: $("#lt_language").val() - }; - $.ajax({ - timeout: var_timeout, - cache: false, - xhrFields: { withCredentials: true }, - url: 'ajax.php?a=exportLanguageTechnology', - type: 'post', - data: request, - success: function (response) { - if (response['error'] == true) { - alert(response['msg']); - return false; - } - window.open(response['url']); - }, - error: function(x, t, m) { - if(t==="timeout") { - alert("got timeout"); - } else { - alert('Prišlo je do neznane napake.'); - } - }, - complete: function() { - } - }); -} - - -function changeWordType(spremenljivka, wordIndex, word, wordType) { - var wkey = spremenljivka +'_'+ wordIndex+'_' + word + '_' + wordType; - // preverimo cachež - - if (languageTechnologyWordCache[wkey] == undefined) { - console.log('2'); - // nardimo request - var request = { - spremenljivka: spremenljivka, - anketa: srv_meta_anketa_id, - lt_word: word, - lt_tag: wordType, - lt_language: $("#lt_language").val(), - lt_min_FWD: $("#lt_min_FWD").val(), - lt_min_nNoM: $("#lt_min_nNoM").val(), - lt_min_vNoM: $("#lt_min_vNoM").val() - }; - // nardimo ajax klic - $.ajax({ - cache: false, - timeout: var_timeout, - xhrFields: { withCredentials: true }, - url: 'ajax.php?a=runLanguageTechnologyWord', - type: 'post', - //dataType: 'json', - data: request, - spremenljivka: spremenljivka, - wordIndex: wordIndex, - container: $('li#branching_'+spremenljivka), - beforeSend: function() { - }, - success: function (response) { - - if (response['error'] != undefined) { - if (response['error']['hasError'] == true) { - alert(response['error']['msg']); - - // cleanUpAndReturn(); - return false; - } - delete response['error']; - } - if (response['setting'] != undefined) { - languageTechnologySettings = response['setting']; - delete response['setting']; - } - // zamenjamo besedo v responsu - languageTechnologyResponse[this.spremenljivka][this.wordIndex] = response[0]; - // TODO počistimo morebitne izbrane indexe za to besedo - resetWordSynonyms(spremenljivka, wordIndex); - // prikažemo na novo - changeWordSynonym(this.spremenljivka, this.wordIndex); - displayWordSynonyms(this.spremenljivka, this.wordIndex); - - - - return true; - }, - error: function(x, t, m) { - if(t==="timeout") { - alert("got timeout"); - } else { - alert('Prišlo je do neznane napake.'); - } - }, - complete: function() { - } - }); - } -} - -function stripAccents(str) { - var rExps=[ - {re:/[\xC0-\xC6]/g, ch:'A'}, - {re:/[\xE0-\xE6]/g, ch:'a'}, - {re:/[\xC8-\xCB]/g, ch:'E'}, - {re:/[\xE8-\xEB]/g, ch:'e'}, - {re:/[\xCC-\xCF]/g, ch:'I'}, - {re:/[\xEC-\xEF]/g, ch:'i'}, - {re:/[\xD2-\xD6]/g, ch:'O'}, - {re:/[\xF2-\xF6]/g, ch:'o'}, - {re:/[\xD9-\xDC]/g, ch:'U'}, - {re:/[\xF9-\xFC]/g, ch:'u'}, - {re:/[\xD1]/g, ch:'N'}, - {re:/[\xF1]/g, ch:'n'} ]; - for(var i=0, len=rExps.length; i