コード例 #1
0
ファイル: ontolight.cpp プロジェクト: Accio/snap
PLwOnto TLwOnto::LoadVoc(const TStr& FNm) {
  // create ontology
  PLwOnto LwOnto = TLwOnto::New();
  // create language object
  int EnLangId = LwOnto->GetLangBs()->AddLang("EN", "English");
  // create term-types
  PLwTermType TermType = TLwTermType::New(0, "Term", EnLangId);
  LwOnto->GetTermTypeBs()->AddTermType(TermType);
  // create terms
  {printf("Creating terms ...\n");
  // load terms from file
  TStr VocFileStr = TStr::LoadTxt(FNm); 
  VocFileStr.DelChAll('\r');
  TStrV TermNmV; VocFileStr.SplitOnAllCh('\n', TermNmV);
  // add terms to base
  const int Terms = TermNmV.Len();
  for (int TermId = 0; TermId<Terms; TermId++){
    if (TermId%1000==0){printf("%d/%d\r", TermId, Terms);}
    TStr TermNm = TermNmV[TermId];
    // create term
    PLwTerm Term=TLwTerm::New(TermId, TermNm, EnLangId, TermType->GetTermTypeId());
    LwOnto->GetTermBs()->AddTerm(Term);
  }
  printf("Done. (%d)\n", LwOnto->GetTermBs()->GetTerms());}
  // return ontology
  return LwOnto;
}
コード例 #2
0
ファイル: stopword.cpp プロジェクト: edgeflip/dmoz
void TSwSet::LoadFromFile(const TStr& FNm) {
    TStr FileStr = TStr::LoadTxt(FNm);
    FileStr.DelChAll('\r');
    TStrV WordV; FileStr.SplitOnAllCh('\n', WordV);
    for (int WordN = 0; WordN < WordV.Len(); WordN++) {
        const TStr& WordStr = WordV[WordN];
        if (!IsIn(WordStr)) { AddWord(WordStr); }
    }
}
コード例 #3
0
ファイル: test-TStr.cpp プロジェクト: gitter-badger/qminer
TEST(TStr, Del) {
	TStr Str = "aabbaabb";
	TStr Empty = "";
	
	TStr Test = Str;
	Test.DelChAll('a');
	EXPECT_EQ(Test, "bbbb");
	Test.DelChAll('c');
	EXPECT_EQ(Test, "bbbb");
	
	Test = Str;
	Test.DelSubStr(2, 3);
	EXPECT_EQ(Test, "aaaabb");
	
	Test.DelSubStr(0, 1);
	EXPECT_EQ(Test, "aabb");
	Test.DelSubStr(2, 3);
	EXPECT_EQ(Test, "aa");
	
	EXPECT_ANY_THROW(Test.DelSubStr(-1, 5));
	
	Test.DelSubStr(0, 1);
	EXPECT_EQ(Test, "");
	Test = Str;
	Test.DelSubStr(0, 0);
	EXPECT_EQ(Test, "abbaabb");
	

	Test = Str;
	EXPECT_TRUE(Test.DelStr("ab"));
	EXPECT_EQ(Test, "abaabb");
	EXPECT_FALSE(Test.DelStr("fs"));
	EXPECT_EQ(Test, "abaabb");

	Test = Str;
	EXPECT_EQ(2, Test.DelStrAll("ab"));
	EXPECT_EQ(Test, "abab");
}
コード例 #4
0
/////////////////////////////////////////////////
// EuPartner
TStr TCordisEuPart::ExtrCountry(const TStr& AddrStr){
  TStr CountryStr;
  TStrV LnV; AddrStr.SplitOnStr("<br>", LnV);
  if (LnV.Len()>0){
    CountryStr=LnV.Last();
    if (CountryStr.Empty()&&(LnV.Len()>1)){
      CountryStr=LnV[LnV.Len()-2];}
    CountryStr.DelChAll('\r');
    CountryStr.DelChAll('\n');
  }
  if (CountryStr.Empty()){
    printf("Country Field Not Found!\n");}
  return CountryStr;
}
コード例 #5
0
void TVizMapContext::PaintMgGlass(PGks Gks, const int& KeyWdFontSize) {
    // drawing the dark circle
    TFltRect ZoomRect = GetZoomRect();
    int SizeX = TFlt::Round((MgGlassSize/ZoomRect.GetXLen()) * Gks->GetWidth());
    int SizeY = TFlt::Round((MgGlassSize/ZoomRect.GetYLen()) * Gks->GetHeight());
    Gks->SetBrush(TGksBrush::New(ColorMgGlass));
    Gks->FillEllipse(ScreenX-SizeX, ScreenY-SizeY, ScreenX+SizeX, ScreenY+SizeY);
    // drawing the keywords
    if (MgGlassKeyWdV.Len() > 0) {
        // prepare the string
        Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize, TGksColor::GetBlack(), TFSet()|gfsBold));
        TStr KeyWdStr = Gks->BreakTxt(MgGlassKeyWdV, ", ", ",", MgGlassWindowWidth);       
        TStr NearPointStr;
        if (NearPointN != -1) {
            PVizMapPoint NearPoint = VizMapFrame->GetPoint(NearPointN);
            if (NearPoint->IsPointNm()) {
                TStr NearPointNm = NearPoint->GetPointNm();
                if (NearPointNm.IsStrIn("[[")) {
                    const int StartPos = NearPointNm.SearchStr("[[");
                    NearPointNm = NearPointNm.Left(StartPos - 1);
                }
                NearPointStr = Gks->BreakTxt(NearPointNm, 
                    " ", "", MgGlassWindowWidth, 1);
                NearPointStr.DelChAll('\n');
                NearPointStr += "\n";
            }
        }
        TStr DocCountStr = "#documents = " + MgGlassPoints.GetStr() + "\n";
        // compose the final message
        KeyWdStr = NearPointStr + DocCountStr + KeyWdStr;
        // find position of the window
        int WndWidth = Gks->GetTxtWidth(KeyWdStr) + 6;
        int WndHeight = Gks->GetTxtHeight(KeyWdStr) + 6;
        int PosX = ScreenX + 20, PosY = ScreenY + 20;
        if (PosX + WndWidth > Gks->GetWidth()) {
            PosX = ScreenX - 20 - WndWidth; }
        if (PosY + WndHeight > Gks->GetHeight()) {
            PosY = ScreenY - 20 - WndHeight; }
        // draw the keyword string
        Gks->SetBrush(TGksBrush::New(ColorMgGlassWndShadow));
        Gks->FillRect(PosX + 5, PosY + 5, 
            PosX + WndWidth + 5, PosY + WndHeight + 5);
        Gks->SetBrush(TGksBrush::New(ColorMgGlassWnd));
        Gks->SetPen(TGksPen::New(ColorMgGlassWndFrm));
        Gks->Rectangle(PosX, PosY, 
            PosX + WndWidth, PosY + WndHeight);
        Gks->PutTxt(KeyWdStr, PosX+3, PosY+3);
    }
}