Logo Search packages:      
Sourcecode: apertium version File versions  Download package

int LexTor::estimate_winner_lch_votingtl ( deque< LexTorWord > &  window,
int  word_index,
double  weigth_exponent 
) [private]

!!!! Para hacer que no tenga en cuenta las !!!! polisemicas del contexto

translation_weighs[j]=0; !!!! !!!!

Definition at line 863 of file lextor.cc.

References LexTorData::get_lexchoice_sum(), LexTorData::get_wordcount(), LexTorData::reduce(), and LexTorData::vote_from_word().

                                                                                                      {
  if (tlmodel==NULL) {
    wcerr<<L"Error in LexTor::estimate_winner_lch_votingtl: you must call LexTor::set_tlmodel first.\n";
    exit(EXIT_FAILURE);
  }  

  double lexchoices_count[window[word_index].n_lexical_choices()];
  vector<wstring> translation_window[window.size()];
  wstring reduced_window[window.size()];

  for (unsigned i=0; i<window.size(); i++) 
    reduced_window[i]=lextor_data->reduce(window[i].get_word_string());       
  
  if(debug) {
    wcerr<<L"WINDOW: ";
    for (unsigned i=0; i<window.size(); i++) {
      if(i==(unsigned)word_index)
      wcerr<<L"[>>>>"<<reduced_window[i]<<L"<<<<] ";
      else
      wcerr<<L"["<<reduced_window[i]<<L"] ";
    }
    wcerr<<L"\n";
    wcerr<<L"TRANSLATED: ";
  }

  //We translate each word in the context
  //Note: Words in the context can also be ambiguous (with more than one lexical choice)
  for (unsigned i=0; i<window.size(); i++) {
    wstring str_translations=L"";
    for(int j=0; j<window[i].n_lexical_choices(); j++) {
      wstring tr=tlmodel->reduce(window[i].translate(*fstpbil,j));
      translation_window[i].push_back(tr);
      str_translations+=tr+L"/";
    }
    if (debug) {
      if (i==(unsigned)word_index)
      wcerr<<L"[>>>>"<<str_translations<<L"<<<<] ";
      else
      wcerr<<L"["<<str_translations<<L"] ";
    }
  }

  if(debug)
    wcerr<<L"\n";

  //For each lexical choice the counts from the TL are collected
  for(unsigned i=0; i<(unsigned)window[word_index].n_lexical_choices(); i++) {
    lexchoices_count[i]=0;

    for (unsigned k=0; k<window.size(); k++) {
      if ((k!=(unsigned)word_index)&&(reduced_window[k]!=reduced_window[word_index])) {
      COUNT_DATA_TYPE target_vote=0;

      //If the SL word is ambiguous it will have more than one
      //translation into TL, so we need to normalize using the
      //frequency of words in the TL
      double translation_weighs[translation_window[k].size()];
      double sum=0.0;
      if (translation_window[k].size()>1) {
        for(unsigned j=0; j<translation_window[k].size(); j++) {
          translation_weighs[j]=tlmodel->get_lexchoice_sum(translation_window[k][j]);
          sum+=translation_weighs[j];

          //!!!!! Para hacer que no tenga en cuenta las
          //!!!!! polisemicas del contexto
          ///////translation_weighs[j]=0;
          //!!!!!
          //!!!!!

          if (debug) {
            wcerr<<L"Frequency of translation ["<<translation_window[k][j]<<L"] ="
              <<translation_weighs[j]<<L"\n";
          }
        }
      } else {
        translation_weighs[0]=1;
        sum=1;
      }

      for(unsigned j=0; j<translation_window[k].size(); j++) {
        translation_weighs[j]=translation_weighs[j]/sum;
        if (debug) {
          wcerr<<L"Weight of translation ["<<translation_window[k][j]<<L"] ="
            <<translation_weighs[j]<<L"\n";
        }
      }

      for(unsigned j=0; j<translation_window[k].size(); j++) {
        double aux_vote=0;
        //aux_vote=tlwordmodel.vote_from_word(lexchoice_translation[*itlch], 
        //                        translation_buffer[i][j])*translation_weighs[j];
        if(debug) 
          wcerr<<translation_window[word_index][i]<<L" "<<translation_window[k][j]<<L" "
            <<tlmodel->vote_from_word(translation_window[word_index][i],translation_window[k][j])<<L" "
            <<tlmodel->get_wordcount(translation_window[k][j])<<L" "<<translation_weighs[j]<<L"\n";
      
        if (tlmodel->get_wordcount(translation_window[k][j])>0) {
          aux_vote=(tlmodel->vote_from_word(translation_window[word_index][i],translation_window[k][j])/
                  tlmodel->get_wordcount(translation_window[k][j]))*translation_weighs[j];
        } 
        target_vote+=aux_vote;

        if(debug) {
          wcerr<<L"Target vote for ["<<translation_window[word_index][i]
            <<L"] from ["<<translation_window[k][j]<<L"] = "<<aux_vote<<L"\n";
        }
      }

      lexchoices_count[i]+=target_vote;
      }
    }
  }


  if(debug) {
    for(int i=0; i<window[word_index].n_lexical_choices(); i++) 
      wcerr<<L"lexchoicecount["<<i<<L"] = "<<lexchoices_count[i]<<L"\n";
    //getchar();
  }

  //Now the winner is calculated
  int winner=-1; //This will make the default one to be used if unchanged
  COUNT_DATA_TYPE winner_vote=-100000000;
  for(int i=0; i<window[word_index].n_lexical_choices(); i++) {
    if ((lexchoices_count[i]>0) && (lexchoices_count[i]>winner_vote)) {
      winner_vote=lexchoices_count[i];
      winner=i;
    } 
  }

  if (debug) 
    wcerr<<L"WINNER: "<<winner<<L" "<<window[word_index].get_lexical_choice(winner)<<L"\n";

  return winner;
}


Generated by  Doxygen 1.6.0   Back to index