function handleNewConceptFromRelation(&$finalConcepts, $subjectOrObject, $conceptLocationInRelation, &$notInCounceptsCounter, &$statsUniqueSubjects) { global $WORDS_TRANSLATIONS_AR_EN; $subjectOrObjectFlag = null; // SUBJECT NOT IN MASTER CONCEPTS LIST if (!isset($finalConcepts[$subject])) { if ($conceptLocationInRelation == "SUBJECT") { echoN("NOT IN CONCEPTS:S:{$subjectOrObject}"); } else { echoN("NOT IN CONCEPTS:O:{$subjectOrObject}"); } $notInCounceptsCounter++; $statsUniqueSubjects[$subjectOrObject] = 1; } $termsArr = getTermArrBySimpleWord($finalTerms, $subjectOrObject); $freq = $termsArr['FREQ']; $isQuranaPhraseConcept = false; //echoN("^&&*:".(strpos($subjectOrObject," ")!==false)); if (isMultiWordStr($subjectOrObject)) { $quranaConceptArr = getQuranaConceptEntryByARWord($subjectOrObject); $engTranslation = ucfirst($quranaConceptArr['EN']); echoN("^^{$subjectOrObject}"); $isQuranaPhraseConcept = true; } else { $uthmaniWord = getItemFromUthmaniToSimpleMappingTable($subjectOrObject); $engTranslation = ucfirst(cleanEnglishTranslation($WORDS_TRANSLATIONS_AR_EN[$uthmaniWord])); } addNewConcept($finalConcepts, $subjectOrObject, "A-BOX", "POPULATION_FROM_RELATIONS", $freq, $engTranslation); $finalConcepts[$subjectOrObject]['EXTRA']['POS'] = $subjectOrObjectFlag; $finalConcepts[$subjectOrObject]['EXTRA']['WEIGHT'] = $termsArr['WEIGHT']; if ($isQuranaPhraseConcept) { echoN($isQuranaPhraseConcept . "||||{$subjectOrObject}"); $finalConcepts[$subjectOrObject]['EXTRA']['IS_QURANA_NGRAM_CONCEPT'] = true; } }
function runPendingProcess() { global $conn; $pid_query = "select * from process JOIN setprocess ON ( process.idSetProcess = setprocess.idSetProcess ) WHERE (idProcessStatus = 2 OR idProcessStatus = 3) AND (idProcessNumMaster <> idProcessNum OR idProcessNumMaster is null)"; $rswrk = $conn->Execute($pid_query); $num_process_running = $rswrk->RecordCount(); spool_video_all_folders(); spool_document(); downloadPendingImages(); checkFinishedTraining(); addNewConcept(); $log = ""; if ($num_process_running) { ///PARTE DI CONTROLLO SE I PROCESSI ATTIVI SONO ANCORA IN ESECUZIONE O IN TIMEOUT - INIZIO echo "{$num_process_running} Processes running. <br>"; while (!$rswrk->EOF) { //PsExec("ls /var/www/octo/"); echo "Stampa controllo esecuzione processo <br>"; $pid = $rswrk->fields("OSProcessId"); //verifica timeout $to_time = time(); $from_time = strtotime($rswrk->fields("start")); $second_in_execution = round(abs($to_time - $from_time)); echo "Controllo timeout. Processo in esecuzione da " . $rswrk->fields("start") . " -> {$second_in_execution} secondi.<br>"; switch ($rswrk->fields('idProcessType')) { case "1": //caso di un eseguibile $timeout_limit = 60 * 60; //60 minuti break; case "2": //caso di un web service http $timeout_limit = 2 * 60; //2 minuti break; case "3": //caso di un JSONRPC $timeout_limit = 60 * 60; //60 minuti break; } if ($second_in_execution > $timeout_limit) { echo "Processo andato in timeout (più di {$timeout_limit} secondi). Fermato."; //setProcessEnd($rswrk->fields("processId")); setProcessStatus($rswrk->fields("processId"), 6); } else { switch ($rswrk->fields('idProcessType')) { case "1": //caso di un eseguibile echo "Controllo esecuzione eseguibile<br>"; //eseguo la chiamata per verificare se il processo è ancora in esecuzione $exeCall = "ps --pid " . $pid; $result = exec($exeCall); //echo "primo <pre>".$result."</pre>"; if ($result == " PID TTY TIME CMD") { //il processo non è più attivo. lo blocco dal gestionale $log_terminate = "Il processo non è più " . $pid . " attivo "; add_log('runPendingProcess:finishing', $log_terminate); setProcessEnd($rswrk->fields("processId")); } else { echo "il processo " . $pid . " attivo<br>"; } break; case "2": //caso di un web service http echo "Controllo esecuzione web service http<br>"; $to_time = time(); $from_time = strtotime($rswrk->fields("start")); $second_in_execution = round(abs($to_time - $from_time)); echo "Controllo timeout. Processo in esecuzione da " . $rswrk->fields("start") . " -> {$second_in_execution} secondi.<br>"; if ($second_in_execution > 120) { echo "Processo andato in timeout (più di 120 secondi). Fermato."; //setProcessEnd($rswrk->fields("processId")); setProcessStatus($rswrk->fields("processId"), 6); } break; case "3": //caso di un JSONRPC echo "Controllo esecuzione web service JSON-RPC (con getResults)<br>"; $processId = (int) $rswrk->fields("processId"); $target = EW_VIDEODROME_SERVER_URL; $request = Tivoka::createRequest(56, 'getResults', array('processId' => $processId)); Tivoka::connect($target)->send($request); if ($request->isError()) { // an error occured var_dump($request->error); var_dump($request->errorMessage); var_dump($request->response); } else { echo "<br>Stato processo: " . $request->result['status'] . "<br> log: "; var_dump($request->result); } switch (strtolower($request->result['status'])) { case "completed": echo "<br>PROCESSO COMPLETATO "; echo "Output:<pre>"; var_dump($request->result['output']); echo "</pre>"; setProcessOutput($rswrk->fields("processId"), $request->result['output']); setProcessEnd($rswrk->fields("processId")); break; case 'not found': echo "<br>PROCESSO NON TROVATO (FERMATO) "; setProcessEnd($processId); break; default: echo "Process running"; } break; } } $rswrk->MoveNext(); } } ///PARTE DI CONTROLLO SE I PROCESSI ATTIVI SONO ANCORA IN ESECUZIONE O IN TIMEOUT - FINE echo "terminato controllo processi in esecuzione"; echo "limite processi in parallelo: " . EW_MAX_PROCESS_IN_EXECUTION; if ($num_process_running < EW_MAX_PROCESS_IN_EXECUTION) { // caso di nessun processo in esecuzione->quindi cerco se ce n'è qualcuno da eseguire $select_query = "SELECT * FROM process JOIN setprocess ON ( process.idSetProcess = setprocess.idSetProcess ) WHERE idProcessStatus =1 OR idProcessStatus =8 ORDER BY process.priority,idProcessNum"; $rswrk = $conn->Execute($select_query); while (!$rswrk->EOF) { // esiste un processo da eseguire //controllo se il processo non è un sotto processo di una coda già in esecuzione $pending_previous = ew_ExecuteScalar("SELECT count(*) FROM process WHERE idProcessNumMaster = '" . $rswrk->fields('idProcessNumMaster') . "' AND (idProcessStatus = 2 OR idProcessStatus = 3) AND (idProcessNumMaster <> idProcessNum)"); if ($pending_previous) { $rswrk->MoveNext(); continue; } //metto il servizio su starting $query_update_status = "UPDATE process set idProcessStatus = 2, start = now() WHERE idProcessNum = " . $rswrk->fields("idProcessNum"); $conn->Execute($query_update_status); add_log('runPendingProcess:starting process', "INIZIALIZZATO PROCESSO " . $rswrk->fields("idProcessNum")); //aumento il numero di processi in esecuzione $num_process_running++; //caso del processo master di un multiprocess if ($rswrk->fields('idProcessNumMaster') == $rswrk->fields('idProcessNum')) { echo "Pipeline id " . $rswrk->fields("idProcessNum") . " running"; runPendingProcess(); return; } switch ($rswrk->fields('idProcessType')) { case "1": //caso di un eseguibile $command_to_append = "lynx -dump http://" . EW_ABS_HOST . "/eutv-tools/process/service/lib/setProcessEnd.php?processId=" . $rswrk->fields("processId"); $command_complete = "( " . $rswrk->fields("command") . " ; " . $command_to_append . " )"; $log .= "<br>Report IdProcess: " . $rswrk->fields("idProcessNum") . " <br><br>The command executed is: " . $command_complete . " on server " . $rswrk->fields("server") . "<br><br>."; $result = PsExec($command_complete); //aggiorno l'OSProcessId eseguito $query_update_status = "UPDATE process set OSProcessId ='" . $result . "' WHERE idProcessNum = " . $rswrk->fields("idProcessNum"); $conn->Execute($query_update_status); break; case "2": //caso di un web service http add_log('runPendingProcess:startingwebservice', "URL executed:" . $rswrk->fields("command")); $runCall = "" . $rswrk->fields("command"); $log .= "\n<br><br>Report IdProcess: " . $rswrk->fields("idProcessNum") . " <br><br>The command (service) executed is: " . $rswrk->fields("command") . " of service " . $rswrk->fields("service") . "."; $runCall = str_replace(" ", "%20", $runCall); $log .= "Calling service: " . $runCall; //$result = ""; $result = file_get_contents($runCall); $log .= $result; break; case "3": //caso di un JSONRPC add_log('runPendingProcess:startingwebserviceJSONRPC', "URL executed:" . $rswrk->fields("server")); $method = ""; //caricamento parametri processo $sSqlWrk = "SELECT * from processparams as pp JOIN processparamsvalue as ppv ON (pp.idProcessParams = ppv.idProcessParams) WHERE idProcessNum = " . $rswrk->fields("idProcessNum") . ""; $rswrk_params = $conn->Execute($sSqlWrk); while (!$rswrk_params->EOF) { //recupero il valore della variabile $value = $rswrk_params->fields('value'); //recupero il nome della variabile $var_name = $rswrk_params->fields('code'); if ($var_name == "method") { $method = $value; } else { echo "ANALISI parametro {$var_name} con valore {$value}<br><br>"; //faccio alcuni controlli if ($value == "true") { echo "Parametro {$var_name} di tipologia true<br>"; $value = true; } elseif ($value == "false") { echo "Parametro {$var_name} di tipologia false<br>"; $value = false; } elseif (is_numeric($value)) { echo "Parametro {$var_name} di tipologia int<br>"; $value = (int) $value; } elseif ($value == 'MEDIA_NAME_DB') { echo "<br>Entrato valore speciale MEDIA_NAME_DB"; $id_media = ew_ExecuteScalar("SELECT value FROM processparams as pp JOIN processparamsvalue as ppv ON (pp.idProcessParams = ppv.idProcessParams) WHERE idProcessNum = " . $rswrk->fields("idProcessNum") . " AND code = 'id_media'"); echo "<br>Recuperato id_media{$id_media} "; $conn->Execute("SET SESSION group_concat_max_len = 1000000;"); $list_image = ew_ExecuteScalar("SELECT GROUP_CONCAT(distinct thumbnail) FROM " . EW_CONN_DB_MEDIA . ".annotations WHERE id_media = '{$id_media}'"); //echo "<br>Recuperata lista immagini <em>$list_image</em>"; if ($list_image != "") { $array_images = explode(',', $list_image); } else { $array_images = array(); } echo "<br><br>Array immagini:<br><em>" . serialize($array_images) . "</em><br><br><br>"; $value = $array_images; } } echo "<br><br>Inserisco il parametro {$var_name} con valore:<br><em>" . serialize($value) . "</em><br><br><br>"; $params_input[$var_name] = $value; $rswrk_params->MoveNext(); } //eseguo l'analisi $params_input['processId'] = (int) $rswrk->fields("processId"); $target = EW_VIDEODROME_SERVER_URL; echo "<br>Method: {$method}<br>Params: <pre>"; var_dump($params_input); echo "</pre>"; $request = Tivoka::createRequest(1, $method, $params_input); start_crono('analysis'); add_log('analyzeBowImage:analysis', "Analysis started. Method: {$method} - Params input: " . serialize($params_input)); Tivoka::connect($target)->send($request); if ($request->isError()) { // an error occured var_dump($request->error); var_dump($request->errorMessage); var_dump($request->response); } else { if ($debug) { var_dump($request->result); } } // the result ?> </pre><br /><br /> <?php break; default: } echo $log; add_log('runPendingProcess:starting REPORT', $log); //se sono al numero massimo di processi in esecuzione contemporanea non ne eseguo più if ($num_process_running >= EW_MAX_PROCESS_IN_EXECUTION) { echo "Numero di processi massimi in esecuzione"; break; } //ho eseguito il primo programma in esecuzione $rswrk->MoveNext(); } if ($rswrk->RecordCount() == 0) { echo "<br><br>No process pending."; //sendTweet(date(DATE_RFC822)." - No process pending"); syncroNewConcept(); } /*$log_activity = "INSERT INTO logs (type,text) VALUES ('runPendingProcess:test_cron','test call');"; $conn->Execute($log_activity); */ } //fine caso di esecuzione processo }
if (isFoundInTranslationTable($englishConceptName)) { $customTranslationEntry = getTranlationEntryByEntryKeyword($englishConceptName); $finalConceptName = $customTranslationEntry['AR_TEXT']; echoN("FOUND:{$finalConceptName}"); } else { $tentitaveTranslation = translateText($englishConceptName); addTranslationEntry($englishConceptName, "CONCEPT", $tentitaveTranslation); $finalConceptName = $tentitaveTranslation; } echoN("finalConceptName:{$finalConceptName}"); // DIDN'T FIND NEITHER ARABIC OR ENGLISH CONCEPTS IN FINAL CONCEPTS LIST if (!isset($finalConcepts[$finalConceptName])) { $exPhase = "ENRICHMENT_WORDNET"; //$parentConceptEN = ucfirst($parentConceptEN); $conceptType = "T-BOX"; $res = addNewConcept($enrichedFinalConcepts, $finalConceptName, $conceptType, $exPhase, 1, $englishConceptName); if ($res == true) { $newConceptsAdded++; $newConceptsAddedArr[$finalConceptName] = 1; } $enrichedFinalConcepts[$finalConceptName]['EXTRA']['MEANING_EN']['WORDNET'] = $glossary; if (isFoundInTranslationTable($glossary, "DESC")) { $customTranslationEntry = getTranlationEntryByEntryKeyword($glossary); $glossaryAR = $customTranslationEntry['AR_TEXT']; } else { $tentitaveTranslation = translateText($glossary); /* echoN($glossary); echoN("==".("(plural) any group of human beings (men or women or children) collectively"==$glossary)); //showHiddenChars(removeUnacceptedChars(cleanAndTrim("(plural) any group of human beings (men or women or children) collectively")),"EN"); //showHiddenChars("someone who leads you to believe something that is not true","EN"); isFoundInTranslationTable($glossary,"DESC");