示例#1
0
void TWebTxtBsSrv::AddHitSetChA(
 const PTxtBsRes& TxtBsRes, const TStr& RqContTypeStr,
 const int& HitSetN, const int& HitSetDocs, const int& StrHitSets,
 const PUrlEnv& UrlEnv, TChA& OutChA){
  // get hit-set data
  TStr PrevUrlStr; TStrPrV NmUrlStrPrV; TStr NextUrlStr;
  TxtBsRes->GetHitSet(
   HitSetN, HitSetDocs, StrHitSets, HitSetUrlFldNm, UrlEnv,
   PrevUrlStr, NmUrlStrPrV, NextUrlStr);
  // hit-set header
  TStr HitSetHdTpl=GetTplVal(RqContTypeStr, "HitSetHd");
  OutChA+=HitSetHdTpl;
  // hit-set 'previous'
  if (!PrevUrlStr.Empty()){
    TStr HitSetPrevTpl=GetTplVal(RqContTypeStr, "HitSetPrev");
    HitSetPrevTpl.ChangeStrAll(UrlMacro, PrevUrlStr);
    OutChA+=HitSetPrevTpl;
  }
  // hit-set records
  for (int NmN=0; NmN<NmUrlStrPrV.Len(); NmN++){
    TStr Nm=NmUrlStrPrV[NmN].Val1;
    TStr UrlStr=NmUrlStrPrV[NmN].Val2;
    if (UrlStr.Empty()){
      // hit-set record with name
      TStr HitSetRecTpl=GetTplVal(RqContTypeStr, "HitSetRecNm");
      HitSetRecTpl.ChangeStrAll(NmMacro, Nm);
      OutChA+=HitSetRecTpl;
    } else {
      // hit-set record with linked name
      TStr HitSetRecTpl=GetTplVal(RqContTypeStr, "HitSetRecLinkedNm");
      HitSetRecTpl.ChangeStrAll(NmMacro, Nm);
      HitSetRecTpl.ChangeStrAll(UrlMacro, UrlStr);
      OutChA+=HitSetRecTpl;
    }
  }
  // hit-set 'next'
  if (!NextUrlStr.Empty()){
    TStr HitSetNextTpl=GetTplVal(RqContTypeStr, "HitSetNext");
    HitSetNextTpl.ChangeStrAll(UrlMacro, NextUrlStr);
    OutChA+=HitSetNextTpl;
  }
  // hit-set footer
  TStr HitSetFtTpl=GetTplVal(RqContTypeStr, "HitSetFt");
  OutChA+=HitSetFtTpl;
}
示例#2
0
/////////////////////////////////////////////////
// Best-Paths
void GetBestPaths(
 const TStr& SrcNmObjStr, const TStr& DstNmObjStr, const PNmObjBs& NmObjBs){
  int SrcNmObjId=NmObjBs->GetNmObjId(SrcNmObjStr);
  int DstNmObjId=NmObjBs->GetNmObjId(DstNmObjStr);
  int NmObjs=NmObjBs->GetNmObjs();
  TIntPrV ParLevPrV(NmObjs); TIntPrV DstParLevPrV;
  ParLevPrV.PutAll(TIntPr(-1, -1));
  int CurLev=0;
  ParLevPrV[SrcNmObjId]=TIntPr(SrcNmObjId, CurLev);
  forever{
    CurLev++; int NewEdges=0;
    for (int NmObjId1=0; NmObjId1<NmObjs; NmObjId1++){
      if (ParLevPrV[NmObjId1].Val2==CurLev-1){
        TIntV DocIdV1; NmObjBs->GetNmObjDocIdV(NmObjId1, DocIdV1);
        for (int NmObjId2=0; NmObjId2<NmObjs; NmObjId2++){
          if ((NmObjId2==DstNmObjId)||(ParLevPrV[NmObjId2].Val2==-1)){
            TIntV DocIdV2; NmObjBs->GetNmObjDocIdV(NmObjId2, DocIdV2);
            TIntV IntrsDocIdV; DocIdV1.Intrs(DocIdV2, IntrsDocIdV);
            if (!IntrsDocIdV.Empty()){
              ParLevPrV[NmObjId2]=TIntPr(NmObjId1, CurLev); NewEdges++;
              if (NmObjId2==DstNmObjId){
                DstParLevPrV.Add(TIntPr(NmObjId1, CurLev));
              }
            }
          }
        }
      }
    }
    if ((NewEdges==0)||(ParLevPrV[DstNmObjId].Val2!=-1)){
      break;
    }
  }
  // prepare graph
  THash<TStr, PVrtx> VrtxNmToVrtxH; TStrPrV VrtxNmPrV;
  VrtxNmToVrtxH.AddKey(SrcNmObjStr);
  VrtxNmToVrtxH.AddKey(DstNmObjStr);
  // write path
  ContexterF->NmObjLinkageREd->Clear();
  for (int DstParLevPrN=0; DstParLevPrN<DstParLevPrV.Len(); DstParLevPrN++){
    ParLevPrV[DstNmObjId]=DstParLevPrV[DstParLevPrN];
    int DstParLev=ParLevPrV[DstNmObjId].Val2;
    TStr DstNmObjStr=NmObjBs->GetNmObjStr(DstNmObjId);
    ContexterF->NmObjLinkageREd->Lines->Add(DstNmObjStr.CStr());
    int ParNmObjId=DstNmObjId;
    TStr PrevNmObjStr=DstNmObjStr;
    forever {
      if (ParNmObjId==SrcNmObjId){break;}
      ParNmObjId=ParLevPrV[ParNmObjId].Val1;
      int ParLev=ParLevPrV[ParNmObjId].Val2;
      TStr CurNmObjStr=NmObjBs->GetNmObjStr(ParNmObjId);
      TStr ParNmObjStr=TStr::GetSpaceStr((DstParLev-ParLev)*4)+CurNmObjStr;
      ContexterF->NmObjLinkageREd->Lines->Add(ParNmObjStr.CStr());
      // create vertex & edge
      VrtxNmToVrtxH.AddKey(CurNmObjStr);
      if (!PrevNmObjStr.Empty()){
        if (PrevNmObjStr<CurNmObjStr){
          VrtxNmPrV.AddUnique(TStrPr(PrevNmObjStr, CurNmObjStr));
        } else
        if (PrevNmObjStr>CurNmObjStr){
          VrtxNmPrV.AddUnique(TStrPr(CurNmObjStr, PrevNmObjStr));
        }
      }
      // save curent named-object
      PrevNmObjStr=CurNmObjStr;
    }
  }
  // generate graph
  // create graph
  PGraph Graph=TGGraph::New();
  // create vertices
  for (int VrtxN=0; VrtxN<VrtxNmToVrtxH.Len(); VrtxN++){
    TStr VrtxNm=VrtxNmToVrtxH.GetKey(VrtxN);
    PVrtx Vrtx=TGVrtx::New(VrtxNm);
    VrtxNmToVrtxH.GetDat(VrtxNm)=Vrtx;
    Graph->AddVrtx(Vrtx);
  }
  // create edges
  for (int EdgeN=0; EdgeN<VrtxNmPrV.Len(); EdgeN++){
    PVrtx Vrtx1=VrtxNmToVrtxH.GetDat(VrtxNmPrV[EdgeN].Val1);
    PVrtx Vrtx2=VrtxNmToVrtxH.GetDat(VrtxNmPrV[EdgeN].Val2);
    PEdge Edge=new TGEdge(Vrtx1, Vrtx2, TStr::Fmt("_%d", EdgeN), false);
    Graph->AddEdge(Edge);
  }
  // place graph
  ContexterF->State->ElGraph=Graph;
  TRnd Rnd(1);
  ContexterF->State->ElGraph->PlaceSimAnnXY(Rnd, ContexterF->State->ElGks);
  // draw graph
  ContexterF->State->ElGks->Clr();
  ContexterF->ElPbPaint(NULL);
}