Exemplo n.º 1
0
 public function adjFitsSlot($word, $keyslot)
 {
     $CI =& get_instance();
     $CI->load->library('Mymatching');
     $matching = new Mymatching();
     $numclasses = count($word->classes);
     $matchscore = 1000;
     $matchindexclass = -1;
     $output = 0;
     for ($i = 0; $i < $numclasses; $i++) {
         // comprovem que la classe d'adjectiu existeixi i que el type de l'slot accepti adjectius
         if ($matching->isSetKeyAdj($word->classes[$i]) && $matching->isSetKeyAdjSmall($this->type)) {
             $tipusx = $matching->adjFitKeys[$this->type];
             // agafem l'index del tipus de l'slot
             $tipusy = $matching->adjFitKeys[$word->classes[$i]];
             if ($matching->adjFit[$tipusx][$tipusy] < $matchscore) {
                 $matchscore = $matching->adjFit[$tipusx][$tipusy];
                 $matchindexclass = $i;
             }
         }
     }
     // mirar si l'adjectiu pot fer de complement de nom del nom que estigui fent fill a l'slot
     if ($this->full && $this->paraulafinal->tipus == "name") {
         // HO MIREM SEMPRE, JA QUE una paraula POT SER AL LLISTAT PROV DE L'SLOT I al llistat DE NC D'UN ALTRE NOM
         // POT FER EL MATCH I ES POSA A LA LLISTA DE COMPLEMENTS ADJ PROVISIONAL EN UN NOU SLOT
         $numcomplements = count($this->cmpAdjs);
         $newslot = new Myslot();
         $newslot->category = $this->category . " ADJ";
         $newslot->grade = "opt";
         $newslot->full = true;
         $newslot->paraulafinal = $word;
         $newslot->level = $this->level + 1;
         $newslot->parent = $keyslot;
         $word->slotstemps[] = $keyslot . " ADJ " . $numcomplements;
         $scoreadjcmp = 1000;
         $indexclassadj = 0;
         $numclassesnom = count($this->paraulafinal->classes);
         for ($i = 0; $i < $numclasses; $i++) {
             $classeadjaux = $word->classes[$i];
             for ($j = 0; $j < $numclassesnom; $j++) {
                 $classenomaux = $this->paraulafinal->classes[$j];
                 if ($matching->isSetKeyAdjNoun($classeadjaux) && $matching->isSetKeyNoun($classenomaux)) {
                     $tipusx = $matching->adjNounFitKeys[$classeadjaux];
                     $tipusy = $matching->nounsFitKeys[$classenomaux];
                     if ($matching->adjNounFit[$tipusx][$tipusy] < $scoreadjcmp) {
                         $scoreadjcmp = $matching->adjNounFit[$tipusx][$tipusy];
                         $indexclassadj = $i;
                     }
                 }
             }
         }
         // nom - adjectiu
         $distance = $this->paraulafinal->inputorder - $word->inputorder;
         // com més lluny i com menys fit facin, pitjor
         $newslot->puntsfinal = 7 - $scoreadjcmp - abs($distance);
         if ($distance == -1) {
             $newslot->puntsfinal += 1;
         }
         // Si l'adjectiu va just darrere el nom és la millor opció
         $aux = array();
         $aux[0] = $keyslot . " ADJ " . $numcomplements;
         // la clau de l'slot on pot fer de complement
         $aux[1] = $newslot->puntsfinal;
         // els punts d'aquest slot: és per desambiguar si un adj pot complementar a dues paraules, per escollir la millor
         $word->slotstempsext[] = $aux;
         // key de l'slot on e'adj fa de complement [0] i punts [1]
         $newslot->indexclassfinalword = $indexclassadj;
         $this->cmpAdjs[$keyslot . " ADJ " . $numcomplements] = $newslot;
         $output = 1;
     }
     // si havia fet fit d'un slot (no de complement)
     if ($matchscore != 1000) {
         // POSEM LA PARAULA AL LLISTAT DE FILL TEMPORAL
         $this->fillSlotTemp($word, $matchscore, $matchindexclass, $keyslot);
         $output = 1;
     }
     return $output;
 }