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 --- .../classes/class.SurveyLanguageTechnology.php | 809 --------------------- 1 file changed, 809 deletions(-) delete mode 100644 admin/survey/classes/class.SurveyLanguageTechnology.php (limited to 'admin/survey/classes/class.SurveyLanguageTechnology.php') diff --git a/admin/survey/classes/class.SurveyLanguageTechnology.php b/admin/survey/classes/class.SurveyLanguageTechnology.php deleted file mode 100644 index 40fcea1..0000000 --- a/admin/survey/classes/class.SurveyLanguageTechnology.php +++ /dev/null @@ -1,809 +0,0 @@ - 'Slo', - 'lt_min_FWD' => 5000, - 'lt_min_nNoM' => 9999, - 'lt_min_vNoM'=> 9999, - 'lt_special_setting'=> false - ); - - public function __construct($anketa) { - global $lang; - $this->anketa = $anketa; - $this->lang = $lang; - } - - public function setup( array $settings) { - if (isset($settings['lt_language']) && is_string($settings['lt_language']) && in_array(strtolower($settings['lt_language']), array('slo','eng'))) { - $this->settings['lt_language'] = $settings['lt_language']; - } - if (isset($settings['lt_min_FWD']) && is_numeric($settings['lt_min_FWD'])) { - $this->settings['lt_min_FWD'] = $settings['lt_min_FWD']; - } - if (isset($settings['lt_min_nNoM']) && is_numeric($settings['lt_min_nNoM'])) { - $this->settings['lt_min_nNoM'] = $settings['lt_min_nNoM']; - } - if (isset($settings['lt_min_vNoM']) && is_numeric($settings['lt_min_vNoM'])) { - $this->settings['lt_min_vNoM'] = $settings['lt_min_vNoM']; - } - return $this->settings; - } - - public function display() { - global $lang; - global $site_url; - global $admin_type; - global $global_user_id; - - echo '
'; - $this->dispalySettings(); -#$r = $this->sendJson('Na kolokvij se prijavljam kot'); -#print_r("
");
-#print_r($r);
-#print_r("
"); - - echo '
'; - ?>anketa); - $b->displayKomentarji(false); - $b->branching = ''; - $b->locked = true; - - $sql = sisplet_query("SELECT s.id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->anketa' ORDER BY g.vrstni_red ASC, s.vrstni_red ASC"); - if (mysqli_num_rows($sql) > 0 ) { - while ($row = mysqli_fetch_array($sql)) { - - echo '
  • '; - ob_start(); - $b->vprasanje($row['id']); - $out1 = ob_get_contents(); - ob_end_clean(); - echo $out1; - echo '
  • '; - echo '
    '; -# print_r("
    ");
    -#					print_r(strip_tags($out1));
    -#					print_r("
    ");
    -			}
    -		} 
    -		echo '
    '; // branching - echo '
    '; - $this->displayVprasanjeFloatEditing(); - echo '
    '; - echo '
    '; // placeholder - - } - private function dispalySettings() { - - - #echo '
    '; - echo '
    '; - echo '
    '; - echo ''; - echo ''; - echo ''; - echo ''; - //echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - #echo ''; - #echo ''; - echo '
    ' . $this->lang['srv_language_technology_language'] . '' . $this->lang['srv_language_technology_flag_words'] . '
    ' . $this->lang['srv_language_technology_wf_under'] . '  
    ' . $this->lang['srv_language_technology_verbs_above'] . 'Verbs
    '; - echo '
    '; - echo '
    '; - } - - private function getMustangResult($sentence, $wordType = null) { - if (empty($sentence) || trim($sentence) == "") { - return null; - } - - //$d = '[{"language": "Eng","sentence": "Sometimes it work.","min_FWD": 5000,"min_nNoM": 1,"min_vNoM": 3}]'; - //$d = '[{"language": "Slo","sentence": "S šumniki so težave","min_FWD": 5000,"min_nNoM": 1,"min_vNoM": 3}]'; - #$d = '[{"language": "Slo","sentence": "Na kolokvij se prijavljam kot","min_FWD": 5000,"min_nNoM": 1,"min_vNoM": 3}]'; - //$d = '[{"language": "Slo","sentence": "'.$sentence.'","min_FWD": 5000,"min_nNoM": 0,"min_vNoM": 3}]'; - $d .= '"language": "' . $this->settings['lt_language'] . '",'; - if ($wordType == null) { - $mustangWordSentance = 'sentence?json='; - $d .= '"sentence": "' . $sentence . '",'; - } else { - $mustangWordSentance = 'word?json='; - $d .= '"word": "' . $sentence . '",'; - $d .= '"Tag": "' . $wordType . '",'; - } - $d .= '"min_FWD": ' . $this->settings['lt_min_FWD'] . ','; - $d .= '"min_nNoM": ' . $this->settings['lt_min_nNoM'] . ','; - $d .= '"min_vNoM": ' . $this->settings['lt_min_vNoM'] ; - $d = trim($d); - - if (false) { - $d = '[{' . urlencode($d) . '}]'; - } else { - $d = urlencode('[{' . $d . '}]'); - } - - $result = $this->makeMustangRequest($this->settings['lt_language'], $mustangWordSentance . $d); - - return $result; - } - - private function makeMustangRequest($language, $mustangString) { - - if ( strtolower($language) == 'eng') { - $url = 'http://mustang.ijs.si:5111/synonym/' . $mustangString ; - } else { - $url = 'http://mustang.ijs.si:5112/synonym/' . $mustangString; - } - - try { - //$r = $this->get_url_contents($url); // na testu ne deluje curl ??? - - $ctx = stream_context_create(array('http'=> - array( - 'timeout' => 20, // 20 Seconds - ) - )); - - $r = (file_get_contents($url, false, $ctx)); - $r = str_replace(array("\r\n", "\n"), "", $r); - $r = json_decode($r, true); - - - if (is_array($r) && count($r) == 1) { - $r = $r[0]; - } - - } catch(Exception $e) { - - $r = null; - } - return $r; - } - - private function parseMustangResult($spremenljivka_mustang, $onlyProblematic = true) { - $result = array(); - - //$spremenljivka_mustang = $spremenljivka_mustang['sentence']; - if (is_array($spremenljivka_mustang) && count($spremenljivka_mustang) > 0) { - - foreach ($spremenljivka_mustang['sentence'] AS $mustangWordArray) { - $mw = new MustangWord($mustangWordArray); - if (($onlyProblematic== true && $mw->isProblematic()) || $onlyProblematic == false) - { - $result[] = $mw->getJson(); - } - } - } - return $result; - } - - public function parseSpremenljivka($spremenljivka) { - // polovimo tekste vprašanja - - $spremenljivka_naslov = $this->sanityze($this->getNaslovSpremenljivka($spremenljivka)); - $spremenljivka_mustang = $this->getMustangResult($spremenljivka_naslov); - $spremenljivkaResult = $this->parseMustangResult($spremenljivka_mustang); - return array('data' => $spremenljivkaResult ); - /* - $this->response['mustang']['naslov'] = $spremenljivka_mustang; - - //$this->addWords($spremenljivka_naslov); - $vrednosti = ($this->getVrednostiSpremenljivka($spremenljivka)); - foreach ($vrednosti AS $vrednost) { - $this->response['mustang']['vrednosti'][] = $this->sendJson($spremenljivka_naslov); - //$this->response['vrednosti'][] = $this->sanityze($vrednost); - //$this->addWords($this->sanityze($vrednost)); - } - - //echo strip_tags($spremenljivka_naslov); - #echo 'ank:'.$this->anketa; - #echo 'spr:'.$spremenljivka; - - return $this->response['mustang']['naslov'][0]; - */ - } - - /** funkcija počisti string neveljavnih zankov - * - * @param unknown_type $string - */ - private function sanityze($string) { - // odstranimo html tage - $string = strip_tags($string); - - // odstanimo dvojne narekovaje - $string = str_replace(array('"', "\n\r", "\n", "/", "-", "\\"), " ", $string); - $string = preg_replace('!\s+!', ' ', $string); - - // odstranimo nepotrebne spejse - $string = trim($string); - return $string; - } - - private function addWords($sentance) { - $words = explode(" ", $sentance); - if (!empty($words)) { - foreach ($words AS $word) { - $word = str_replace(array('"', "\n\r", "\n", "."), "", $word); - $this->response['words'][$word] = $word; - } - } - } - - protected function getNaslovSpremenljivka($spremenljivka) { - $result = Cache::srv_spremenljivka($spremenljivka,'naslov'); - return $result; - } - - protected function getVrednostiSpremenljivka($spremenljivka) { - $result = array(); - $sql1 = sisplet_query("SELECT naslov FROM srv_vrednost WHERE spr_id='$spremenljivka'"); - while ($row1 = mysqli_fetch_assoc($sql1)) { - $result[] = $row1['naslov']; - } - return $result; - } - - private function get_url_contents($url) { - $curl = curl_init(); - $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'; - - //The contents of the "User-Agent: " header to be used in a HTTP request. - curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); - curl_setopt($curl, CURLOPT_URL, $url); - //To fail silently if the HTTP code returned is greater than or equal to 400. - curl_setopt($curl, CURLOPT_FAILONERROR, TRUE); - // Removes the headers from the output - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); - // Return the output instead of displaying it directly - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); - //To follow any "Location: " header that the server sends as part of the HTTP header. - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); - //To automatically set the Referer: field in requests where it follows a Location: redirect. - curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); - //The maximum number of seconds to allow cURL functions to execute. - curl_setopt($curl, CURLOPT_TIMEOUT, 10); - - $ret = curl_exec($curl); - curl_close($curl); - return $ret; - } - - public function exportLanguageTechnology($lt_data, $language) { - require_once("./excel/PHPExcel.php"); - require_once("./excel/PHPExcel/IOFactory.php"); - - $data = $this->prepareExcelData($lt_data, $language); - - $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized; - PHPExcel_Settings::setCacheStorageMethod($cacheMethod); - - // Create new PHPExcel object - $objPHPExcel = new PHPExcel(); - // Create a first sheet, representing sales data - $objPHPExcel->setActiveSheetIndex(0); - $aSheet = $objPHPExcel->getActiveSheet(); - // Rename sheet - $aSheet->setTitle('Relevant meaning'); - $aSheet->getColumnDimension('A')->setWidth(8); - $aSheet->getColumnDimension('B')->setWidth(20); - $aSheet->getColumnDimension('C')->setWidth(12); - $aSheet->getColumnDimension('D')->setWidth(12); - // first lines - $aSheet->setCellValue('A1', 'Question'); - $aSheet->setCellValue('B1', 'Original word'); - $aSheet->setCellValue('C1', 'WF'); - $aSheet->setCellValue('D1', 'NoM'); - - $line = 2; - //$response = unserialize(file_get_contents('mustangData.dat')); - // loop po spremenljivkah - - foreach ($data['words'] as $spr_id => $words) { - $spremenljivkaId = $spr_id; - $spremenljivkaVariable = Cache::srv_spremenljivka($spremenljivkaId, 'variable'); - $naslov = Cache::srv_spremenljivka($spremenljivkaId, 'naslov'); - - - $sc = 0; - foreach ($words as $w_idx => $bData) { - $word = $data['spremenljivkeData'][$spr_id][$w_idx]['word']; - $tag = $data['spremenljivkeData'][$spr_id][$w_idx]['Tag']; - $fwd = $data['spremenljivkeData'][$spr_id][$w_idx]['FWD']; - $nom = $data['spremenljivkeData'][$spr_id][$w_idx]['NoM']; - if ($sc == 0) { - $aSheet->setCellValue('A'.$line, $spremenljivkaVariable . ' - ' . strip_tags ($naslov)); - } - $sc ++; - $aSheet->setCellValue('B'.$line, $word); - $aSheet->setCellValue('C'.$line, $fwd); - $aSheet->setCellValue('D'.$line, $nom); - $line++; - } - } - - #SYNONYMS - $objPHPExcel->createSheet(); - $objPHPExcel->setActiveSheetIndex(1); - $aSheet = $objPHPExcel->getActiveSheet(); - $aSheet->setTitle('Synonyms'); - - $aSheet->getColumnDimension('A')->setWidth(8); - $aSheet->getColumnDimension('B')->setWidth(20); - $aSheet->getColumnDimension('C')->setWidth(20); - $aSheet->getColumnDimension('D')->setWidth(12); - $aSheet->getColumnDimension('E')->setWidth(12); - - $aSheet->setCellValue('A1', 'Question'); - $aSheet->setCellValue('B1', 'Original wording'); - $aSheet->setCellValue('C1', 'Alternative wording'); - $aSheet->setCellValue('D1', 'WF'); - $aSheet->setCellValue('E1', 'NoM'); - - $line = 2; - if (count($data['synsets'])) { - foreach ($data['synsets'] as $spr_id => $wordData) { - $spremenljivkaId = $spr_id; - $spremenljivkaVariable = Cache::srv_spremenljivka($spremenljivkaId, 'variable'); - $naslov = Cache::srv_spremenljivka($spremenljivkaId, 'naslov'); - - $sc = 0; - foreach ($wordData AS $w_idx => $synsetsData) { - $wc = 0; - $word = $data['spremenljivkeData'][$spr_id][$w_idx]['word']; - foreach ($synsetsData AS $syns_word => $syns_data) { - if ($sc == 0) { - $aSheet->setCellValue('A'.$line, $spr_id); - $aSheet->setCellValue('A'.$line, $spremenljivkaVariable . ' - ' . strip_tags ($naslov)); - } - $sc++; - if ($wc == 0) { - $aSheet->setCellValue('B'.$line, $word); - } - $wc++; - $aSheet->setCellValue('C'.$line, $syns_word); - $aSheet->setCellValue('D'.$line, $syns_data['freq']); - $aSheet->setCellValue('E'.$line, $syns_data['nom']); - $line++; - } - } - } - } - - # HYPERNYMS - $objPHPExcel->createSheet(); - $objPHPExcel->setActiveSheetIndex(2); - $aSheet = $objPHPExcel->getActiveSheet(); - // Rename 2nd sheet - $aSheet->setTitle('Hypernyms'); - - $aSheet->getColumnDimension('A')->setWidth(8); - $aSheet->getColumnDimension('B')->setWidth(20); - $aSheet->getColumnDimension('C')->setWidth(20); - - $aSheet->setCellValue('A1', 'Question'); - $aSheet->setCellValue('B1', 'Original wording'); - $aSheet->setCellValue('C1', 'Hypernym'); - - $line = 2; - if (count($data['hypernyms'])) { - foreach ($data['hypernyms'] as $spr_id => $wordData) { - $spremenljivkaId = $spr_id; - $spremenljivkaVariable = Cache::srv_spremenljivka($spremenljivkaId, 'variable'); - $naslov = Cache::srv_spremenljivka($spremenljivkaId, 'naslov'); - - $sc = 0; - foreach ($wordData AS $w_idx => $hypersData) { - $wc = 0; - $word = $data['spremenljivkeData'][$spr_id][$w_idx]['word']; - foreach ($hypersData AS $syns_word => $hyper_data) { - if ($sc == 0) { - $aSheet->setCellValue('A'.$line, $spr_id); - $aSheet->setCellValue('A'.$line, $spremenljivkaVariable . ' - ' . strip_tags ($naslov)); - } - $sc++; - if ($wc == 0) { - $aSheet->setCellValue('B'.$line, $word); - } - $wc++; - $aSheet->setCellValue('C'.$line, $hyper_data); - $line++; - } - } - } - } - # HYPONYMS - $objPHPExcel->createSheet(); - $objPHPExcel->setActiveSheetIndex(3); - $aSheet = $objPHPExcel->getActiveSheet(); - // Rename 2nd sheet - $aSheet->setTitle('Hyponyms'); - - $aSheet->getColumnDimension('A')->setWidth(8); - $aSheet->getColumnDimension('B')->setWidth(20); - $aSheet->getColumnDimension('C')->setWidth(20); - - $aSheet->setCellValue('A1', 'Question'); - $aSheet->setCellValue('B1', 'Original wording'); - $aSheet->setCellValue('C1', 'Hyponym'); - - $line = 2; - if (count($data['hyponyms'])) { - foreach ($data['hyponyms'] as $spr_id => $wordData) { - $sc = 0; - foreach ($wordData AS $w_idx => $hypersData) { - $wc = 0; - $word = $data['spremenljivkeData'][$spr_id][$w_idx]['word']; - foreach ($hypersData AS $syns_word => $hyper_data) { - if ($sc == 0) { - $aSheet->setCellValue('A'.$line, $spr_id); - } - $sc++; - if ($wc == 0) { - $aSheet->setCellValue('B'.$line, $word); - } - $wc++; - $aSheet->setCellValue('C'.$line, $hyper_data); - $line++; - } - } - } - } - - global $site_path; - $folder = $site_path . EXPORT_FOLDER.'/'; - - // izberemo random hash, ki se ni v bazi (to more bit, ker je index na fieldu cookie) - $filename = null; - $rand = null; - $x = 0; - do { - $rand = md5(mt_rand(1, mt_getrandmax()).'@'.$_SERVER['REMOTE_ADDR']); - $filename = $folder . "lt_" . $rand . '.xlsx'; - $x++; - } while (file_exists($filename) === true && $x < 99999); // backup loop - - if ($filename != null) { - $objPHPExcel->setActiveSheetIndex(0); - $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); - $objWriter->save($filename); - return $rand; - } else { - throw new Exception("Can't create excel report!"); - } - } - - - public function parseWord($word, $wordType) { - $spremenljivkaResult = array(); - - if (in_array($wordType, array('a', 'n', 'v', 'adv', 'e'))) { - $spremenljivka_mustang = $this->getMustangResult($word, $wordType); - - - $data = array('language'=>$spremenljivka_mustang['language']); - unset($spremenljivka_mustang['language']); - $data['sentence'][] = $spremenljivka_mustang; - // ker delamo posamezne besede ni pomembno da je onlyProblematic - $spremenljivkaResult = $this->parseMustangResult($data, false); - } - return $spremenljivkaResult ; - - } - - public function getHypoHypernym($synsets) { - if (!is_array($synsets) || empty($synsets)) { - return null; - } - $hypernyms = array(); - $hyponyms = array(); - - $_synsets = array(); - - foreach ($synsets AS $synset) { - $synset = $synset['synonyms']; - - // http://mustang.ijs.si:5111/synonym/hypohypernym?json= - // [{ "language": "Eng", "": "1. spouse,partner,married person,mate,better half|n|a person's partner in marriage|"}] - - $mustangWordSentance = 'hypohypernym?json='; - $d = ''; - $d .= '"language": "' . $this->settings['lt_language'] . '", '; - $d .= '"synset": "' . ( $synset) . '"'; - $d = trim($d); - - if (false) { - $d = '[{' . urlencode($d) . '}]'; - } else { - $d = urlencode('[{' . $d . '}]'); - } - - $result = $this->makeMustangRequest($this->settings['lt_language'], $mustangWordSentance . $d); - - // nima vsaka beseda hypernymov in hyponimpov takrat mustang vrne specifičen string: - if (isset($result['hypernym'][0]['hypernym']) - && ($result['hypernym'][0]['hypernym']== 'blamaža, kiks, zagata' - || $result['hypernym'][0]['hypernym']== 'blamaža, kiks, zagata' - || $result['hypernym'][0]['hypernym']== 'happening, occurrence, occurrent, natural event')) - { - // beseda nima hypernymov in hyponymov - $result['hypernym'] = array(); - $result['hyponym'] = array(); - } - - if (isset($result['hypernym']) && is_array($result['hypernym']) && count($result['hypernym']) > 0) { - foreach ($result['hypernym'] AS $_hypernyms) { - if (isset($_hypernyms['hypernym'])) { - $__hypernyms = array_map('trim',explode(',', $_hypernyms['hypernym'])); - $hypernyms = array_merge($hypernyms, $__hypernyms); - - } - } - } - if (isset($result['hyponym']) && is_array($result['hyponym']) && count($result['hyponym']) > 0) { - foreach ($result['hyponym'] AS $_hyponyms) { - $_hyponyms = array_map('trim',explode(',', $_hyponyms)); - $hyponyms = array_merge($hyponyms, $_hyponyms); - } - } - } - $hypernyms = array_unique($hypernyms); - $hyponyms = array_unique($hyponyms); - natsort($hypernyms); - natsort($hyponyms); - if(($key = array_search('NO HYPERNYMS', $hypernyms)) !== false) { - unset($hypernyms[$key]); - } - if(($key = array_search('NO HYPONYMS', $hyponyms)) !== false) { - unset($hyponyms[$key]); - } - return array('data' => array('hypernyms' => $hypernyms, 'hyponyms' => $hyponyms), 'synsets' => $_synsets); - } - - private function displayVprasanjeFloatEditing() { - echo '

    '; - echo '

    '; - echo ''; - echo '

    '; - echo '

    '; - echo ''; - echo '

    '; - echo '

    '; - echo ''; - echo '

    '; - - - } - - private function prepareExcelData($lt_data, $language) { - - $result = array(); - - if (!isset($lt_data['response'])) { - return $result; - } - $spremenljivkeData = $lt_data['response']; - $result['spremenljivkeData'] = $spremenljivkeData; - unset($lt_data['response']); - - $spremenljivkaWords = array(); - if (isset($lt_data['wordsSynonyms'])) { - foreach ($lt_data['wordsSynonyms'] as $spr_id => $wordSynData) { - foreach ($wordSynData as $wordIdx => $synData) { - foreach ($synData AS $synIdx => $star) { - if (isset($spremenljivkeData[$spr_id][$wordIdx]['Synset'][$synIdx])) { - $wordSynsets = $this->parseExcelSynsets($spremenljivkeData[$spr_id][$wordIdx]['Synset'][$synIdx], $language); - foreach($wordSynsets AS $word => $wordData) { - if (!isset($result['words'][$spr_id][$wordIdx])) { - $result['words'][$spr_id][$wordIdx] = true; - } - if (!isset($result['synsets'][$spr_id][$wordIdx][$word])) { - $result['synsets'][$spr_id][$wordIdx][$word] = $wordData; - } - } - } - - } - } - - } - } - - if (isset($lt_data['wordsHypernyms'])) { - foreach ($lt_data['wordsHypernyms'] as $spr_id => $wordHyperData) { - foreach ($wordHyperData as $wordIdx => $synData) { - foreach ($synData AS $synIdx => $star) { - if (isset($spremenljivkeData[$spr_id][$wordIdx]['cleanhypernyms'][$synIdx])) { - if (!isset($result['words'][$spr_id][$wordIdx])) { - $result['words'][$spr_id][$wordIdx] = true; - } - - if (!isset($result['hypernyms'][$spr_id][$wordIdx][$synIdx])) { - $result['hypernyms'][$spr_id][$wordIdx][$synIdx] = $spremenljivkeData[$spr_id][$wordIdx]['cleanhypernyms'][$synIdx]; - } - } - - } - } - - } - } - - if (isset($lt_data['wordsHyponyms'])) { - foreach ($lt_data['wordsHyponyms'] as $spr_id => $wordHypoData) { - foreach ($wordHypoData as $wordIdx => $synData) { - foreach ($synData AS $synIdx => $star) { - if (isset($spremenljivkeData[$spr_id][$wordIdx]['cleanhyponyms'][$synIdx])) { - if (!isset($result['words'][$spr_id][$wordIdx])) { - $result['words'][$spr_id][$wordIdx] = true; - } - - if (!isset($result['hyponyms'][$spr_id][$wordIdx][$synIdx])) { - $result['hyponyms'][$spr_id][$wordIdx][$synIdx] = $spremenljivkeData[$spr_id][$wordIdx]['cleanhyponyms'][$synIdx]; - } - } - - } - } - - } - } - - return $result; - } - - private function parseExcelSynsets($stringWordSynsets, $language) { - $result = array(); - $synonyms = $stringWordSynsets['FWDNoM']; - - if (strtolower($language) == 'eng') { - // besede so ločene z vejico - $words = explode(';', $synonyms); - foreach ($words AS $word) { - if ($word == null || trim($word) == "") { - continue; - } - $tmp = explode(':', $word); - $tmpWord = trim($tmp[0]); - $tmp = explode(',', $tmp[1]); - $freq = trim(str_replace(array("FW","=", " "), "", trim($tmp[0]))); - $nom = trim(str_replace(array("NoM","=", " "), "", trim($tmp[1]))); - if (!isset($result[$tmpWord])) { - $result[$tmpWord] = array('freq'=>$freq, 'nom'=> $nom); - } - } - - } else { - // besede so ločene z vejico - $words = explode(';', $synonyms); - foreach ($words AS $word) { - if ($word == null || trim($word) == "") { - continue; - } - $tmp = explode(':', $word); - $tmpWord = trim($tmp[0]); - $tmp = explode(',', $tmp[1]); - $freq = trim(str_replace(array("FW","=", " "), "", trim($tmp[0]))); - $nom = trim(str_replace(array("NoM","=", " "), "", trim($tmp[1]))); - if (!isset($result[$tmpWord])) { - $result[$tmpWord] = array('freq'=>$freq, 'nom'=> $nom); - } - } - } - return $result; - } -} - -class MustangWord { - - - public $word = ""; - private $Tag = ""; // {Do, n, v, adv, - private $FWD = 0; - private $NoM = 0; - private $minFWD = false; - private $min_nNoM = false; - private $min_vNoM = false; - private $Synset = array(); - - public $problematic; - private $json; - - /** - * -{ - "word": "kot", - "Tag": "Vd", - "FWD": 467459, - "NoM": 0, - "Flag": { - "minFWD": false, - "min_nNoM": false, - "min_vNoM": false - }, - "Synset": [{ - "synonyms": "enako, kakor, ko, kot, medtem ko, prav tako, tako kot", - "FWDNoM": "enako NoM: 2 Frek: 14288, kakor NoM: 1 Frek: 37364, ko NoM: 1 Frek: 297690, kot NoM: 6 Frek: 467459, medtem ko NoM: 1 Frek: neznana, prav tako NoM: 1 Frek: neznana, tako kot NoM: 1 Frek: neznana" - }, - { - "synonyms": "kot, vogal", - "FWDNoM": "kot NoM: 6 Frek: 467459, vogal NoM: 5 Frek: 2507" - }, - { - "synonyms": "kot, vogal", - "FWDNoM": "kot NoM: 6 Frek: 467459, vogal NoM: 5 Frek: 2507" - }, - { - "synonyms": "kot", - "FWDNoM": "kot NoM: 6 Frek: 467459" - }, - { - "synonyms": "kot, vogal, vogel", - "FWDNoM": "kot NoM: 6 Frek: 467459, vogal NoM: 5 Frek: 2507, vogel NoM: 2 Frek: 269" - }, - { - "synonyms": "kot", - "FWDNoM": "kot NoM: 6 Frek: 467459" - }] -} - */ - public function __construct($mustangWordArray) { - $this->json = $mustangWordArray; - - $this->word = $mustangWordArray['word']; - $this->Tag = $mustangWordArray['Tag']; - $this->FWD = $mustangWordArray['FWD']; - $this->NoM = $mustangWordArray['NoM']; - - $this->minFWD = $mustangWordArray['Flag']['minFWD']; - $this->min_nNoM = $mustangWordArray['Flag']['min_nNoM']; - $this->min_vNoM = $mustangWordArray['Flag']['min_vNoM']; - - $this->problematic = $this->minFWD || $this->min_nNoM || $this->min_vNoM; - - - } - - public function isProblematic() { - - return $this->problematic; - } - - public function getJson() { - return $this->json; - } - - -} \ No newline at end of file -- cgit v1.2.3