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

void HMM::apply_rules (  )

It applies the forbid and enforce rules found in tagger specification. To do so the transition matrix is modified by introducing null probabilities in the involved transitions.

Definition at line 376 of file hmm.cc.

{
  vector<TForbidRule> &forbid_rules = td->getForbidRules();
  vector<TEnforceAfterRule> &enforce_rules = td->getEnforceRules();
  int N = td->getN();
  int i, j, j2;
  bool found;
   
  for(i=0; i<(int) forbid_rules.size(); i++) {
    (td->getA())[forbid_rules[i].tagi][forbid_rules[i].tagj] = ZERO;
  }

  for(i=0; i<(int) enforce_rules.size(); i++) {
    for(j=0; j<N; j++) {
      found = false;
      for (j2=0; j2<(int) enforce_rules[i].tagsj.size(); j2++) {
      if (enforce_rules[i].tagsj[j2]==j) {
        found = true;
        break;
      }       
      }
      if (!found)
        (td->getA())[enforce_rules[i].tagi][j] = ZERO;
    }
  }
    
  // Normalize probabilities
  for(i=0; i<N; i++) {
    double sum=0;
    for(j=0; j<N; j++) 
      sum += (td->getA())[i][j];
    for(j=0; j<N; j++) {
      if (sum>0)
      (td->getA())[i][j] = (td->getA())[i][j]/sum;
      else
      (td->getA())[i][j] = 0;
    }
  }
}

Generated by  Doxygen 1.6.0   Back to index