nssavoir/Nsfilgd.cpp
int
NSFilGuide::pathDistance(string* psTarget, string* psSource, bool bWithSemantic, DBITBLNAME sensCle)
{
	// Trivial cases
	//
	if (!psSource || !psTarget)
    return pathDistanceInfinite;

  if (*psSource == *psTarget)
    return pathDistanceExact;

  if ((*psSource == string("")) || (*psTarget == string("")))
    return pathDistanceInfinite;

  // More complex cases
  //

  bool bJokerInTarget = false;

  // Not to waste time : if no joker and no semantics, leave now
  //
  if ((psTarget->find(string("*")) != string::npos) ||
      (psTarget->find(string("?")) != string::npos))
    bJokerInTarget = true;

  if (!bWithSemantic && !bJokerInTarget)
    return pathDistanceInfinite;

  // Target parsing
  //
  VecteurString VectItemTarget;
  DecomposeChaine(psTarget, &VectItemTarget);
  // Should never occur; just by security
  if (VectItemTarget.empty())
    return pathDistanceInfinite;

  // Source semantic parsing
  //
  VecteurString VectItemSource;
  DecomposeChaine(psSource, &VectItemSource);
  // Should never occur; just by security
  if (VectItemSource.empty())
    return pathDistanceInfinite;

  VecteurItem SourceVecEquivalentItem;

  // First, if there are jokers in the target, we try a pure generic approach
  // in order not to waste time in the semantic network
  //
  if (bJokerInTarget)
  {
  	// Building the vector with only the generic concepts of source path elements
  	for (EquiItemIter iterSource = VectItemSource.begin(); iterSource != VectItemSource.end(); iterSource++)
  	{
        VecteurString* pEquivalentItem = new VecteurString();

      pEquivalentItem->push_back(new string(*(*iterSource)));
      pEquivalentItem->push_back(new ItemGenerique );
      pEquivalentItem->push_back(new SousChemin );
      pEquivalentItem->push_back(new SousCheminNonVide );

        sort(pEquivalentItem->begin(), pEquivalentItem->end(), inferieure);
        SourceVecEquivalentItem.push_back(pEquivalentItem);
  	}

    int iPureGenericDistance = specificPathDistance(&VectItemTarget, &SourceVecEquivalentItem, &VectItemSource);
    if (iPureGenericDistance < pathDistanceInfinite)
        return pathDistanceGeneric + iPureGenericDistance;

    SourceVecEquivalentItem.vider();
  }

  if (!bWithSemantic)
    return pathDistanceInfinite;

  // Building the vector with all the semantic related concepts of source path elements
  //
  for (EquiItemIter iterSource = VectItemSource.begin(); iterSource != VectItemSource.end(); iterSource++)
  {
    VecteurString* pEquivalentItem = new VecteurString();

    chercheEquivalent(*(*iterSource), pEquivalentItem, string("ES"), sensCle);
    sort(pEquivalentItem->begin(), pEquivalentItem->end(), inferieure);

    SourceVecEquivalentItem.push_back(pEquivalentItem);
  }

  // If can we find jokers in the target, it means generic + semantic
  //
  if (bJokerInTarget)
  {
        int iGenericSemantic = specificPathDistance(&VectItemTarget, &SourceVecEquivalentItem, &VectItemSource);
    if (iGenericSemantic < pathDistanceInfinite)
        return pathDistanceSemanticGeneric + iGenericSemantic;
    else
        return pathDistanceInfinite;
  }

  int iPureSemantic = specificPathDistance(&VectItemTarget, &SourceVecEquivalentItem, &VectItemSource);
  if (iPureSemantic < pathDistanceInfinite)
    return pathDistanceSemantic + iPureSemantic;
  else
    return pathDistanceInfinite;
}
// Distance between a genuine source path (without jokers) and
// a "generic" target path
//
Distance between a genuine source path (without jokers) and
a "generic" target path
Distance between a genuine source path ( without jokers ) and a " generic " target path
int
NSFilGuide::pathDistance(string* psTarget, string* psSource, bool bWithSemantic, DBITBLNAME sensCle)
{
	if (!psSource || !psTarget)
    return pathDistanceInfinite;
  if (*psSource == *psTarget)
    return pathDistanceExact;
  if ((*psSource == string("")) || (*psTarget == string("")))
    return pathDistanceInfinite;
   More complex cases
  bool bJokerInTarget = false;
   Not to waste time : if no joker and no semantics, leave now
  if ((psTarget->find(string("*")) != string::npos) ||
      (psTarget->find(string("?")) != string::npos))
    bJokerInTarget = true;
  if (!bWithSemantic && !bJokerInTarget)
    return pathDistanceInfinite;
   Target parsing
  VecteurString VectItemTarget;
  DecomposeChaine(psTarget, &VectItemTarget);
   Should never occur; just by security
  if (VectItemTarget.empty())
    return pathDistanceInfinite;
   Source semantic parsing
  VecteurString VectItemSource;
  DecomposeChaine(psSource, &VectItemSource);
   Should never occur; just by security
  if (VectItemSource.empty())
    return pathDistanceInfinite;
  VecteurItem SourceVecEquivalentItem;
   First, if there are jokers in the target, we try a pure generic approach
   in order not to waste time in the semantic network
  if (bJokerInTarget)
  {
  	 Building the vector with only the generic concepts of source path elements
  	for (EquiItemIter iterSource = VectItemSource.begin(); iterSource != VectItemSource.end(); iterSource++)
  	{
        VecteurString* pEquivalentItem = new VecteurString();
      pEquivalentItem->push_back(new string(*(*iterSource)));
      pEquivalentItem->push_back(new ItemGenerique );
      pEquivalentItem->push_back(new SousChemin );
      pEquivalentItem->push_back(new SousCheminNonVide );
        sort(pEquivalentItem->begin(), pEquivalentItem->end(), inferieure);
        SourceVecEquivalentItem.push_back(pEquivalentItem);
  	}
    int iPureGenericDistance = specificPathDistance(&VectItemTarget, &SourceVecEquivalentItem, &VectItemSource);
    if (iPureGenericDistance < pathDistanceInfinite)
        return pathDistanceGeneric + iPureGenericDistance;
    SourceVecEquivalentItem.vider();
  }
  if (!bWithSemantic)
    return pathDistanceInfinite;
   Building the vector with all the semantic related concepts of source path elements
  for (EquiItemIter iterSource = VectItemSource.begin(); iterSource != VectItemSource.end(); iterSource++)
  {
    VecteurString* pEquivalentItem = new VecteurString();
    chercheEquivalent(*(*iterSource), pEquivalentItem, string("ES"), sensCle);
    sort(pEquivalentItem->begin(), pEquivalentItem->end(), inferieure);
    SourceVecEquivalentItem.push_back(pEquivalentItem);
  }
   If can we find jokers in the target, it means generic + semantic
  if (bJokerInTarget)
  {
        int iGenericSemantic = specificPathDistance(&VectItemTarget, &SourceVecEquivalentItem, &VectItemSource);
    if (iGenericSemantic < pathDistanceInfinite)
        return pathDistanceSemanticGeneric + iGenericSemantic;
    else
        return pathDistanceInfinite;
  }
  int iPureSemantic = specificPathDistance(&VectItemTarget, &SourceVecEquivalentItem, &VectItemSource);
  if (iPureSemantic < pathDistanceInfinite)
    return pathDistanceSemantic + iPureSemantic;
  else
    return pathDistanceInfinite;
}
int NSFilGuide :: pathDistance ( string * psTarget , string * psSource , bool bWithSemantic , DBITBLNAME sensCle ) { if ( ! psSource || ! psTarget ) return pathDistanceInfinite ; if ( * psSource == * psTarget ) return pathDistanceExact ; if ( ( * psSource == string ( " " ) ) || ( * psTarget == string ( " " ) ) ) return pathDistanceInfinite ; bool bJokerInTarget = false ; if ( ( psTarget -> find ( string ( " " ) ) != string :: npos ) || ( psTarget -> find ( string ( " " ) ) != string :: npos ) ) bJokerInTarget = true ; if ( ! bWithSemantic && ! bJokerInTarget ) return pathDistanceInfinite ; VecteurString VectItemTarget ; DecomposeChaine ( psTarget , & VectItemTarget ) ; if ( VectItemTarget . empty ( ) ) return pathDistanceInfinite ; VecteurString VectItemSource ; DecomposeChaine ( psSource , & VectItemSource ) ; if ( VectItemSource . empty ( ) ) return pathDistanceInfinite ; VecteurItem SourceVecEquivalentItem ; if ( bJokerInTarget ) { for ( EquiItemIter iterSource = VectItemSource . begin ( ) ; iterSource != VectItemSource . end ( ) ; iterSource ++ ) { VecteurString * pEquivalentItem = new VecteurString ( ) ; pEquivalentItem -> push_back ( new string ( * ( * iterSource ) ) ) ; pEquivalentItem -> push_back ( new ItemGenerique ) ; pEquivalentItem -> push_back ( new SousChemin ) ; pEquivalentItem -> push_back ( new SousCheminNonVide ) ; sort ( pEquivalentItem -> begin ( ) , pEquivalentItem -> end ( ) , inferieure ) ; SourceVecEquivalentItem . push_back ( pEquivalentItem ) ; } int iPureGenericDistance = specificPathDistance ( & VectItemTarget , & SourceVecEquivalentItem , & VectItemSource ) ; if ( iPureGenericDistance < pathDistanceInfinite ) return pathDistanceGeneric + iPureGenericDistance ; SourceVecEquivalentItem . vider ( ) ; } if ( ! bWithSemantic ) return pathDistanceInfinite ; for ( EquiItemIter iterSource = VectItemSource . begin ( ) ; iterSource != VectItemSource . end ( ) ; iterSource ++ ) { VecteurString * pEquivalentItem = new VecteurString ( ) ; chercheEquivalent ( * ( * iterSource ) , pEquivalentItem , string ( " " ) , sensCle ) ; sort ( pEquivalentItem -> begin ( ) , pEquivalentItem -> end ( ) , inferieure ) ; SourceVecEquivalentItem . push_back ( pEquivalentItem ) ; } if ( bJokerInTarget ) { int iGenericSemantic = specificPathDistance ( & VectItemTarget , & SourceVecEquivalentItem , & VectItemSource ) ; if ( iGenericSemantic < pathDistanceInfinite ) return pathDistanceSemanticGeneric + iGenericSemantic ; else return pathDistanceInfinite ; } int iPureSemantic = specificPathDistance ( & VectItemTarget , & SourceVecEquivalentItem , & VectItemSource ) ; if ( iPureSemantic < pathDistanceInfinite ) return pathDistanceSemantic + iPureSemantic ; else return pathDistanceInfinite ; }
Distance between a genuine source path (without jokers) and
a "generic" target path
Distance between a genuine source path ( without jokers ) and a " generic " target path
// Trivial cases // // More complex cases // // Not to waste time : if no joker and no semantics, leave now // // Target parsing // // Should never occur; just by security // Source semantic parsing // // Should never occur; just by security // First, if there are jokers in the target, we try a pure generic approach // in order not to waste time in the semantic network // // Building the vector with only the generic concepts of source path elements // Building the vector with all the semantic related concepts of source path elements // // If can we find jokers in the target, it means generic + semantic //