function convertUthamniQueryToSimple($query)
{
    $queryWords = explode(" ", $query);
    $newQueryArr = array();
    foreach ($queryWords as $index => $word) {
        if (empty($word)) {
            continue;
        }
        $simpleWord = getItemFromUthmaniToSimpleMappingTable($word);
        if (empty($simpleWord)) {
            $simpleWord = shallowUthmaniToSimpleConversion($word);
        }
        $newQueryArr[] = $simpleWord;
    }
    return implode(" ", $newQueryArr);
}
/** Returns words from QAC by PoS tags - grouped by lemma **/
function getWordsByPos(&$finalTerms, $POS)
{
    global $LEMMA_TO_SIMPLE_WORD_MAP;
    $qacPosEntryArr = getModelEntryFromMemory("AR", "MODEL_QAC", "QAC_POS", $POS);
    $QURAN_TEXT = getModelEntryFromMemory("AR", "MODEL_CORE", "QURAN_TEXT", "");
    $TOTALS = getModelEntryFromMemory("AR", "MODEL_CORE", "TOTALS", "");
    $PAUSEMARKS = $TOTALS['PAUSEMARKS'];
    $WORDS_FREQUENCY = getModelEntryFromMemory("AR", "MODEL_CORE", "WORDS_FREQUENCY", "");
    // Get all segment in QAC for that PoS
    foreach ($qacPosEntryArr as $location => $segmentId) {
        $qacMasterTableEntry = getModelEntryFromMemory("AR", "MODEL_QAC", "QAC_MASTERTABLE", $location);
        // get Word, Lema and root
        $segmentWord = $qacMasterTableEntry[$segmentId - 1]['FORM_AR'];
        $segmentWordLema = $qacMasterTableEntry[$segmentId - 1]['FEATURES']['LEM'];
        $segmentWordRoot = $qacMasterTableEntry[$segmentId - 1]['FEATURES']['ROOT'];
        $verseLocation = substr($location, 0, strlen($location) - 2);
        //$segmentWord = removeTashkeel($segmentWord);
        // get word index in verse
        $wordIndex = getWordIndexFromQACLocation($location);
        //$segmentFormARimla2y = $UTHMANI_TO_SIMPLE_WORD_MAP_AND_VS[$segmentWord];
        // get simple version of the word index
        $imla2yWordIndex = getImla2yWordIndexByUthmaniLocation($location);
        // get verse text
        $verseText = getVerseByQACLocation($QURAN_TEXT, $location);
        //echoN("|$segmentWord|$imla2yWord");
        $segmentWordNoTashkeel = removeTashkeel($segmentWordLema);
        $superscriptAlef = json_decode('"\\u0670"');
        $alefWasla = "ٱ";
        //U+0671
        //$imla2yWord = $LEMMA_TO_SIMPLE_WORD_MAP[$segmentWordLema];
        // this block is important since $LEMMA_TO_SIMPLE_WORD_MAP is not good for  non $superscriptAlef words
        // ex زيت lemma is converted to زيتها which spoiled the ontology concept list results
        if (mb_strpos($segmentWordLema, $superscriptAlef) !== false || mb_strpos($segmentWordLema, $alefWasla) !== false) {
            $imla2yWord = getItemFromUthmaniToSimpleMappingTable($segmentWordLema);
            if (empty($imla2yWord)) {
                $imla2yWord = $LEMMA_TO_SIMPLE_WORD_MAP[$segmentWordLema];
            }
        } else {
            $imla2yWord = getItemFromUthmaniToSimpleMappingTable($segmentWordLema);
            if (empty($imla2yWord)) {
                $imla2yWord = shallowUthmaniToSimpleConversion($segmentWordLema);
                //$segmentWordNoTashkeel;
            }
        }
        /// in case the word was not found after removing tashkeel, try the lema mappign table
        $termWeightArr = $MODEL_CORE['WORDS_FREQUENCY']['WORDS_TFIDF'][$imla2yWord];
        // NOT WORKING BECAUSE LEMMAS WILL NOT BE IN SIMPLE WORDS LIST و الصابيئن =>صَّٰبِـِٔين
        // if the word after removing tashkeel is not found in quran simple words list, then try lemma table
        /*if (!isset($MODEL_CORE['WORDS_FREQUENCY']['WORDS'][$imla2yWord]) )
        		 {
        		 $imla2yWord = $LEMMA_TO_SIMPLE_WORD_MAP[$segmentWordLema];
        
        		 if ( empty($imla2yWord) )
        		 {
        		 echoN($segmentWordLema);
        		 echoN($imla2yWord);
        		 preprint_r($LEMMA_TO_SIMPLE_WORD_MAP);
        		 preprint_r($MODEL_CORE['WORDS_FREQUENCY']['WORDS']);
        		 exit;
        		 }
        		 }*/
        if (empty($termWeightArr)) {
            //only for weight since the lema table decrease qurana matching
            $imla2yWordForWeight = $LEMMA_TO_SIMPLE_WORD_MAP[$segmentWordLema];
            $termWeightArr = $WORDS_FREQUENCY['WORDS_TFIDF'][$imla2yWordForWeight];
        }
        $termWeight = $termWeightArr['TFIDF'];
        ////////////////////////////////////////////
        $termWord = $segmentWordLema;
        //$imla2yWord;//"|$segmentWord| ".$imla2yWord ." - $location:$segmentId - $wordIndex=$imla2yWordIndex";
        if (!isset($finalTerms[$termWord])) {
            $finalTerms[$termWord] = generateEmptyConceptMetadata();
            $finalTerms[$termWord]['LEM'] = $segmentWordLema;
            $finalTerms[$termWord]['POS'] = $POS;
            $finalTerms[$termWord]['SIMPLE_WORD'] = $imla2yWord;
            $finalTerms[$termWord]['ROOT'] = $segmentWordRoot;
            $finalTerms[$termWord]['WEIGHT'] = $termWeight;
        }
        $finalTerms[$termWord]["FREQ"] = $finalTerms[$termWord]["FREQ"] + 1;
        if (!isset($finalTerms[$termWord]["SEG"][$segmentWord])) {
            $finalTerms[$termWord]["SEG"][$segmentWord] = $imla2yWord;
        }
        if (!isset($finalTerms[$termWord]["POSES"][$POS])) {
            $finalTerms[$termWord]["POSES"][$POS] = 1;
        }
    }
    return $finalTerms;
}
    echoN("MATCHING QURANA 1-word Concepts={$quranaConceptsMatch}");
    preprint_r($commonConceptsWithQurana);
}
if ($GENERATE_ADJECTIVE_CONCEPTS) {
    $counter = 0;
    foreach ($finalTerms as $lemaUthmani => $termArr) {
        $pos = $termArr['POS'];
        if ($pos == "ADJ") {
            if ($counter++ > 100) {
                break;
            }
            $simpleWord = getModelEntryFromMemory("AR", "OTHERS", "UTHMANI_TO_SIMPLE_WORD_MAP", $lemaUthmani);
            if (!empty($simpleWord)) {
                $mergedWord = $simpleWord;
            } else {
                $uthmaniWordNoTashkeel = shallowUthmaniToSimpleConversion($lemaUthmani);
                $mergedWord = $uthmaniWordNoTashkeel;
            }
            echoN("{$lemaUthmani}|{$simpleWord}|{$uthmaniWordNoTashkeel}");
            if (!isset($finalConcepts[$mergedWord])) {
                // try to get translation from uthmani translation table
                $engTranslation = $WORDS_TRANSLATIONS_AR_EN[$lemaUthmani];
                addNewConcept($finalConcepts, $mergedWord, "A-BOX", "ADJECTIVE", $termArr['FREQ'], $engTranslation);
                $finalConcepts[$mergedWord]['EXTRA'] = $termArr;
            }
        }
    }
}
if ($GENERATE_FINAL_CONCEPTS) {
    $quranaConceptsListArr = $MODEL_QURANA['QURANA_CONCEPTS'];
    // "Thing" Concept