Example #1
0
void OrthographicAlternatives::createAlternative(
  Token* srcToken,
  MorphoSyntacticData* tokenData,
  LimaString& str,
  AnalysisDict::AbstractAnalysisDictionary* dictionary,
  StringsPool& sp)
{
  MORPHOLOGINIT;
  LDEBUG << "OrthographicAlternatives::createAlternative" << str;
  DictionaryEntry* dicoEntry = new DictionaryEntry(dictionary->getEntry(str));
  if (!dicoEntry->isEmpty())
  {
    // add orthographic alternative to Token;
    StringsPoolIndex infl=sp[str];
    Token* altToken=new Token(infl,str,srcToken->position(),srcToken->length(),new TStatus(*(srcToken->status())));
    altToken->setDictionaryEntry(dicoEntry);
    srcToken->addOrthographicAlternative(altToken);
  
    tokenData->appendLingInfo(infl,dicoEntry,ORTHOGRAPHIC_ALTERNATIVE,sp);

    // if entry has other accented forms,
    // keep them ("PARIS" -> "paris" -> "Paris")
    if (dicoEntry->hasAccented())
    {
      dicoEntry->reset();
      Lima::LimaString alternativeStr = dicoEntry->nextAccented();
      while (alternativeStr.size() != 0)
      {
        // give it its simple word entry into dictionary
        DictionaryEntry* altDicoEntry = new DictionaryEntry(dictionary->getEntry(alternativeStr));
        StringsPoolIndex infl2=sp[alternativeStr];
        tokenData->appendLingInfo(infl2,altDicoEntry,ORTHOGRAPHIC_ALTERNATIVE,sp);
        
        // add orthographic alternative to Token
        Token* altToken2=new Token(infl2,alternativeStr,srcToken->position(),srcToken->length(),new TStatus(*(srcToken->status())));
        altToken2->setDictionaryEntry(altDicoEntry);
        srcToken->addOrthographicAlternative(altToken2);
        
        alternativeStr = dicoEntry->nextAccented();
      }
    }
  } else {
    delete dicoEntry;
  }
}