コード例 #1
0
ファイル: dzs.cpp プロジェクト: mkarlovc/gcentralization
void TDzsKwBs::AddHits(const PBook& Book, const TStr& FNm){
  PSOut SOut=TFOut::New(FNm);
  TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum|oloTabSep);
  int KwToSecIdVP=KwToSecIdVH.FFirstKeyId();
  while (KwToSecIdVH.FNextKeyId(KwToSecIdVP)){
    TChA QueryChA=KwToSecIdVH.GetKey(KwToSecIdVP);
    for (int QueryChN=0; QueryChN<QueryChA.Len(); QueryChN++){
      if ((' '<QueryChA[QueryChN])&&(QueryChA[QueryChN]<='~')){
        if (QueryChA[QueryChN]!='*'){
          if (!TCh::IsAlNum(QueryChA[QueryChN])){
            QueryChA.PutCh(QueryChN, ' ');}
        }
      }
    }
    TStr QueryStr=QueryChA;
    PBixRes BixRes=Book->Search(QueryStr);
    if (BixRes->IsOk()){
      Lx.PutUQStr(QueryStr); Lx.PutUQStr(TInt::GetStr(BixRes->GetHits()));
      printf("%s - %d\n", QueryStr.CStr(), BixRes->GetHits());
      int Hits=BixRes->GetHits(); // TInt::GetMn(BixRes->GetHits(), 10);
      for (int HitN=0; HitN<Hits; HitN++){
        TStr SecIdStr; TStr TitleStr; TStr SecStr; TStr CtxStr;
        BixRes->GetHitInfo(
         Book, HitN, -1, 100, SecIdStr, TitleStr, SecStr, CtxStr);
        KwToSecIdVH[KwToSecIdVP].Add(SecIdStr);
        Lx.PutUQStr(SecIdStr);
      }
      Lx.PutLn();
    } else {
      Lx.PutUQStr(QueryStr); Lx.PutUQStr("Error"); Lx.PutStr(BixRes->GetMsgStr());
      printf("%s - Error - %s\n", QueryStr.CStr(), BixRes->GetMsgStr().CStr());
      Lx.PutLn();
    }
  }
}
コード例 #2
0
ファイル: webtxtbs.cpp プロジェクト: mkarlovc/gcentralization
void TWebTxtBsTrmSrv::OnLn(const int& CltSockId, const TStr& Ln){
  TChA InNotifyChA;
  InNotifyChA+=TStr("[")+TInt::GetStr(CltSockId)+"] ";
  //InNotifyChA+=TStr("[")+GetCltPeerNm(CltSockId)+"] ";
  InNotifyChA+=TStr("[")+TSecTm::GetCurTm().GetStr()+"] ";
  InNotifyChA+=Ln;
  TNotify::OnNotify(WebTxtBs->GetNotify(), ntInfo, InNotifyChA);

  PSIn SIn=TMIn::New(Ln);
  TILx Lx(SIn, TFSet()|iloExcept);
  TChA MsgChA; bool SendMsgToClt=true;
  Lx.GetSym();
  if (Lx.Sym==syIdStr){
    try {
      ParseAndExeCmLn(CltSockId, Lx, SendMsgToClt, MsgChA);
    }
    catch (PExcept Except){
      MsgChA=TStr("Error: ")+Except->GetMsgStr()+"\r\n";
    }
  } else {
    if (Lx.Sym!=syEof){
      MsgChA="Error: No command keyword.\r\n";}
  }
  if (SendMsgToClt){
    SendTxtToClt(CltSockId, MsgChA);
    SendTxtToClt(CltSockId, ">");
  }
}
コード例 #3
0
ファイル: yahoodm.cpp プロジェクト: mkarlovc/gcentralization
void TYFSelBs::SaveTxt(
 const PSOut& SOut, const PYBs& YBs, const PYDsBs& YDsBs){
  PYWordDs NegWordDs=TYDmDs::GetNegWordDs(YNegDsType, YBs, YDsBs);
  TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum);
  for (int DocId=0; DocId<DocIdToWordIdEstVV.Len(); DocId++){
    TIntFltKdV& WordIdEstKdV=DocIdToWordIdEstVV[DocId];
    TFltIntKdV WordEstIdKdV(WordIdEstKdV.Len(), 0);
    for (int WordIdN=0; WordIdN<WordIdEstKdV.Len(); WordIdN++){
      int WordId=WordIdEstKdV[WordIdN].Key;
      double WordEst=WordIdEstKdV[WordIdN].Dat;
      WordEstIdKdV.Add(TFltIntKd(WordEst, WordId));
    }
    WordEstIdKdV.Sort(false);

    Lx.PutVarStr("UrlStr", YBs->GetDocUrlStr(DocId));
    Lx.PutVarInt("DocId", DocId);
    PYWordDs WordDs=YDsBs->GetWordDs(DocId);
    Lx.PutVar("WordIdEstKdV", true, true); 
    {for (int WordIdN=0; WordIdN<WordEstIdKdV.Len(); WordIdN++){
      double WordEst=WordEstIdKdV[WordIdN].Key;
      int WordId=WordEstIdKdV[WordIdN].Dat;
      TStr WordStr=YBs->GetWordStr(WordId);
      double PosWordPrb=WordDs->GetWordPrb(WordId);
      double NegWordPrb=NegWordDs->GetWordPrb(WordId);
      Lx.PutQStr(WordStr);
      Lx.PutTab(); Lx.PutFlt(WordEst);
      Lx.PutIndent(1); Lx.PutSym(syLBracket);
      Lx.PutFlt(PosWordPrb); Lx.PutFlt(NegWordPrb);
      Lx.PutSym(syRBracket);
      Lx.PutLn();
    }}
    Lx.PutSym(syRBracket); Lx.PutLn();
  }
}
コード例 #4
0
ファイル: webtxtbs.cpp プロジェクト: mkarlovc/gcentralization
void TWebTxtBsSrv::PrepTplSet(const TStr& FNm, const TStr& DfFNm){
  // get template input-stream (priority order: FNm, DfFNm, DfTplSetStr)
  PSIn SIn;
  bool FExists=false; SIn=TFIn::New(FNm, FExists);
  if (!FExists){SIn=TFIn::New(DfFNm, FExists);}
  if (!FExists){SIn=TStrIn::New(GetDfTplSetStr());}

  TILx Lx(SIn, TFSet()|iloRetEoln|iloSigNum|iloUniStr);
  Lx.GetStrToEolnAndCh('.');
  do {
    TStr SecNm=Lx.GetStr();
    if (SecNm=="End"){Lx.GetStrToEolnAndCh('.');}
    else if (SecNm=="Stop"){break;}
    else if (SecNm=="Template"){
      Lx.GetStr("ContentType"); Lx.GetSym(syEq); TStr ContTypeStr=Lx.GetStr();
      Lx.GetStr("Category"); Lx.GetSym(syEq); TStr CatStr=Lx.GetStr();
      Lx.GetEoln();
      TStr Tpl=Lx.GetStrToEolnAndCh('.');
      Tpl.ChangeStrAll(HostNmMacro, HostNm);
      Tpl.ChangeStrAll(PortMacro, PortNStr);
      AddTpl(ContTypeStr, CatStr, Tpl);
    } else if (SecNm=="Variable"){
      Lx.GetStr("ContentType"); Lx.GetSym(syEq); TStr ContTypeStr=Lx.GetStr();
      TStr VarNm=Lx.GetStr(); Lx.GetSym(syEq); TStr VarVal=Lx.GetStr();
      Lx.GetEoln();
      AddVar(ContTypeStr, VarNm, VarVal);
      Lx.GetStrToEolnAndCh('.');
    } else if (SecNm=="Remark"){
      Lx.GetStrToEolnAndCh('.');
    } else {
      Fail;
    }
  } while (!Lx.IsEof());
}
コード例 #5
0
void TNmObjBs::LoadNrWordBs(const PSIn& SIn){
  if (SIn.Empty()){return;}
  TILx Lx(SIn, TFSet(iloCmtAlw, iloRetEoln, iloExcept));
  // traverse lines
  Lx.GetSym(syQStr, syEoln, syEof);
  while (Lx.Sym!=syEof){
    if (Lx.Sym==syQStr){
      // get normalized word
      TStr NrWordStr=Lx.Str;
      // get inflected words
      Lx.GetSym(syColon);
      Lx.GetSym(syQStr, syEoln);
      while (Lx.Sym!=syEoln){
        // get inflected word
        TStr WordStr=Lx.Str;
        // test if inflected word already exists
        if (WordStrToNrH.IsKey(WordStr)){
          printf("Word already normalized (%s)", WordStr.CStr());}
         // add inflected word and corresponding normalized word
        WordStrToNrH.AddDat(WordStr, NrWordStr);
        //printf("'%s' ->'%s'\n", WordStr.CStr(), NrWordStr.CStr());
        Lx.GetSym(syQStr, syEoln);
      }
      Lx.GetSym(syQStr, syEoln, syEof);
    } else
    if (Lx.Sym==syEoln){
      // empty line
      Lx.GetSym(syQStr, syEoln, syEof);
    } else {
      Fail;
    }
  }
}
コード例 #6
0
ファイル: exp.cpp プロジェクト: Accio/snap
PExpVal TExp::LoadAndEvalExpL(
 const TStr& ExpLStr, bool& Ok, TStr& MsgStr, const PExpEnv& ExpEnv){
  // create final expression value
  PExpVal ExpVal;
  // transform exp. str. to input stream
  PSIn SIn=TStrIn::New(ExpLStr);
  // create lexical
  TILx Lx(SIn, TFSet()|iloCmtAlw|iloCsSens|iloExcept);
  TFSet Expect=TFSet()|sySemicolon|syEof;
  // load & evaluate expression separated by semicolon
  while (Lx.Sym!=syEof){
    // create expression
    PExp Exp; Ok=true; MsgStr="Ok";
    try {
      Lx.GetSym(ExpExpect);
      Exp=LoadTxtExp(Lx, Expect);
    }
    catch (PExcept Except){
      Ok=false; MsgStr=Except->GetMsgStr();
      Exp=PExp(new TExp(etUndef));
    }
    // evaluate expression
    if (Ok){
      ExpVal=Exp->Eval(Ok, MsgStr, ExpEnv);
      //printf("%s\n", ExpVal->GetStr().CStr());
      if (!Ok){
        return NULL;}
    } else {
      return NULL;
    }
  }
  return ExpVal;
}
コード例 #7
0
ファイル: cpdoc.cpp プロジェクト: mkarlovc/gcentralization
void TCpDoc::SaveAcmTechNewsToCpd(
 const TStr& InFPath, const TStr& OutCpdFNm, const int& MxDocs){
  // create output file
  PSOut SOut=TFOut::New(OutCpdFNm);
  // processing xml files
  TFFile FFile(TStrV()+InFPath, TStrV()+".Html"+".Htm", "", true);
  TStr FNm; int Docs=0;
  while (FFile.Next(FNm)){
    printf("Processing file '%s'\r", FNm.CStr());
    PSIn SIn=TFIn::New(FNm);
    THtmlLx Lx(SIn);
    while (Lx.GetSym()!=hsyEof){
      //printf("%d\r", Docs);
      if ((MxDocs!=-1)&&(Docs>MxDocs)){break;}
      Lx.MoveToBTagOrEof("<SPAN>");
      if (Lx.GetArg("CLASS")!="title"){continue;}
      Lx.MoveToBTagOrEof("<A>");
      TStr TitleStr=Lx.GetStrToETag("<A>", false); TitleStr="";
      Lx.MoveToETagOrEof("<SPAN>");
      Lx.MoveToBTagOrEof("<P>");
      TStr ParStr=Lx.GetStrToETag("<P>", false);
      if (!ParStr.Empty()){
        Docs++;
        PCpDoc CpDoc=TCpDoc::New(TInt::GetStr(Docs), TitleStr, ParStr);
        CpDoc->Save(*SOut);
      }
    }
  }
  printf("\n");
}
コード例 #8
0
ファイル: vpGenericFeature.cpp プロジェクト: tswang/visp
/*!

  Compute and return the interaction matrix \f$ L \f$ for the whole
  features or a part of them.

  \param select : Selection of a subset of the possible features. 
  - To compute the interaction matrix for all the features use
    vpBasicFeature::FEATURE_ALL. In that case the dimension of the interaction
    matrix is \f$ [number of features \times 6] \f$
  - To compute the interaction matrix for only one of the component
    feature you have to say which one you want to take into
    account. If it is the first one set select to
    vpBasicFeature::FEATURE_LINE[0], if it is the second one set
    select to vpBasicFeature::FEATURE_LINE[1], and so on. In that case
    the returned interaction matrix is \f$ [1 \times 6] \f$ dimension.
  - To compute the interaction matrix for only two of the component
    features you have to say which ones you want to take into
    account. If it is the first one and the second one set select to
    vpBasicFeature::FEATURE_LINE[0] | vpBasicFeature::FEATURE_LINE[1]. In
    that case the returned interaction matrix is \f$ [2 \times 6] \f$
    dimension.

  \return The interaction matrix computed from the features.

  The code below shows how to compute the interaction matrix associated to the
  first visual feature.
  \code
  // Creation of the current feature s
  vpGenericFeature s(3);
  s.set_s(0, 0, 0);

  // Here you have to compute the interaction matrix L for all the three features
  s.setInteractionMatrix(L);

  vpMatrix L_x = s.interaction( vpBasicFeature::FEATURE_LINE[0] );
  \endcode

  The code below shows how to compute the interaction matrix associated to two
  visual features over three.
  \code
  // Creation of the current feature s
  vpGenericFeature s(3);
  s.set_s(0, 0, 0);

  // Here you have to compute the interaction matrix L
  s.setInteractionMatrix(L);

  vpMatrix L_x = s.interaction( vpBasicFeature::FEATURE_LINE[0]|vpBasicFeature::FEATURE_LINE[1] );
  \endcode
*/
vpMatrix
vpGenericFeature::interaction(const unsigned int select)
{
  if (L.getRows() == 0)
  {
    std::cout << "interaction matrix " << L << std::endl ;
    vpERROR_TRACE("Interaction has not been initialized");
    std::cout << "A possible reason (may be) is that you have set" << std::endl ;
    std::cout << "the interaction matrix for s and compute a control " << std::endl ;
    std::cout << "with Ls=s* (default) or vice versa" << std::endl ;

    throw(vpFeatureException(vpFeatureException::notInitializedError,
			     "size mismatch between s* dimension "
			     "and feature dimension"));

  }

  vpMatrix Ls ;

  Ls.resize(0,6) ;

  for (unsigned int i=0 ; i < dim_s ; i++)
    if (FEATURE_LINE[i] & select )
    {
      vpMatrix Lx(1,6) ; Lx = 0;

      for (int j=0 ; j < 6 ; j++)
	Lx[0][j] = L[i][j] ;

      Ls = vpMatrix::stackMatrices(Ls,Lx) ;
    }

  return Ls ;
}
コード例 #9
0
ファイル: Renderer.cpp プロジェクト: rdavison/trayracer
Color Phong(const MatteMaterial &m, float NdotL, float RdotV) {
    Color Lx(1,1,1);
    Color I(0,0,0);
    I.r = m.Ax.r*m.Ka*m.Dx.r + m.att*Lx.r*(m.Kd*m.Dx.r*(NdotL) + m.Ks*m.Sx.r*pow(RdotV, m.n));
    I.g = m.Ax.g*m.Ka*m.Dx.g + m.att*Lx.g*(m.Kd*m.Dx.g*(NdotL) + m.Ks*m.Sx.g*pow(RdotV, m.n));
    I.b = m.Ax.b*m.Ka*m.Dx.b + m.att*Lx.b*(m.Kd*m.Dx.b*(NdotL) + m.Ks*m.Sx.b*pow(RdotV, m.n));
    return I;
}
コード例 #10
0
// for growing
void base_bin_rel::move_from (const base_bin_rel & other)
{
    POMAGMA_DEBUG("Copying base_bin_rel");

    size_t min_item_dim = min(item_dim(), other.item_dim());
    size_t min_word_dim = min(word_dim(), other.word_dim());

    m_support.move_from(other.m_support);

    if (_symmetric()) {
        POMAGMA_ASSERT(other._symmetric(), "symmetry mismatch");
        for (size_t i = 1; i <= min_item_dim; ++i) {
            memcpy(Lx(i), other.Lx(i), sizeof(Word) * min_word_dim);
        }
    } else {
        POMAGMA_ASSERT(not other._symmetric(), "symmetry mismatch");
        for (size_t i = 1; i <= min_item_dim; ++i) {
            memcpy(Lx(i), other.Lx(i), sizeof(Word) * min_word_dim);
            memcpy(Rx(i), other.Rx(i), sizeof(Word) * min_word_dim);
        }
    }
}
コード例 #11
0
ファイル: dzs.cpp プロジェクト: mkarlovc/gcentralization
/////////////////////////////////////////////////
// Dzs-Keyword-Base
TDzsKwBs::TDzsKwBs(const TStr& FNm):
  KwToSecIdVH(10000){
  PSIn SIn=TFIn::New(FNm);
  TILx Lx(SIn, TFSet()|iloTabSep);
  Lx.GetSym(syStr, syEoln, syEof);
  while (Lx.Sym!=syEof){
    if (Lx.Sym==syStr){
      KwToSecIdVH.AddDat(Lx.Str);
      while (Lx.GetSym()!=syEoln){}
    }
    Lx.GetSym(syStr, syEoln, syEof);
  }
}
コード例 #12
0
ファイル: exp.cpp プロジェクト: Accio/snap
PExp TExp::LoadTxt(
 const PSIn& SIn, bool& Ok, TStr& MsgStr, const TFSet& Expect){
  TILx Lx(SIn, TFSet()|iloCmtAlw|iloCsSens|iloExcept);
  PExp Exp; Ok=true; MsgStr="Ok";
  try {
    Lx.GetSym(ExpExpect);
    Exp=LoadTxtExp(Lx, Expect);
  }
  catch (PExcept Except){
    Ok=false; MsgStr=Except->GetMsgStr();
    Exp=PExp(new TExp(etUndef));
  }
  return Exp;
}
コード例 #13
0
ファイル: ssqldm.cpp プロジェクト: Accio/snap
/////////////////////////////////////////////////
// SqlDm-Program
PSqlDmProg TSqlDmProg::LoadTxt(PSIn& SIn){
  // create object
  PSqlDmProg Prog=TSqlDmProg::New();
  // parse object
  TSqlDmLx Lx(SIn);
  Lx.GetSym(TFSet(TSqlDmStat::StatExpect)|dsyEof);
  while (Lx.Sym!=dsyEof){
    PSqlDmStat Stat=TSqlDmStat::LoadTxt(Lx, TFSet(dsySemicolon, dsyEof));
    Prog->StatV.Add(Stat);
    Lx.GetSym(TFSet(TSqlDmStat::StatExpect)|dsyEof);
  }
  // return object
  return Prog;
}
コード例 #14
0
ファイル: yahoodm.cpp プロジェクト: mkarlovc/gcentralization
void TYInvIx::SaveTxt(const PSOut& SOut, const PYBs& YBs){
  TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum);
  int WordIdToFirstDocIdNP=WordIdToFirstDocIdNH.FFirstKeyId();
  while (WordIdToFirstDocIdNH.FNextKeyId(WordIdToFirstDocIdNP)){
    int WordId=WordIdToFirstDocIdNH.GetKey(WordIdToFirstDocIdNP);
    TStr WordStr;
    if (YBs.Empty()){WordStr=TInt::GetStr(WordId);}
    else {WordStr=YBs->GetWordStr(WordId);}
    Lx.PutStr(WordStr); Lx.PutSym(syColon); Lx.PutSym(syLBracket);
    int DocIdN=FFirstDocId(WordId); int DocId;
    while (FNextWordId(DocIdN, DocId)){
      Lx.PutInt(DocId);}
    Lx.PutSym(syRBracket); Lx.PutLn();
  }
}
コード例 #15
0
PTb TTb::LoadTxtTab(const TStr& FNm, const PTb& Tb){
  // open file
  PSIn SIn=TFIn::New(FNm);
  TILx Lx(SIn, TFSet()|iloTabSep);

  // read variable names
  Lx.GetStr();
  bool IsTupNm=(Lx.UcStr=="NAME")||(Lx.UcStr=="ID");
  if (IsTupNm){Lx.GetSym(syTab); Lx.GetStr();}
  do {
    PTbVarType VarType=PTbVarType(new TTbVarType());
    PTbVar Var=PTbVar(new TGTbVar(Lx.Str, VarType));
    Tb->AddVar(Var);
    if (Lx.GetSym(syTab, syEoln, syEof)==syTab){
      Lx.GetSym(syStr);}
  } while (Lx.Sym==syStr);

  // read tuples
  if (Lx.Sym!=syEof){
    Lx.GetSym(syStr, syEof);}
  while (Lx.Sym!=syEof){
    int TupN;
    if (IsTupNm){
      TupN=Tb->AddTup(Lx.GetSymStr());
      Lx.GetSym(syTab); Lx.GetStr();}
    else {TupN=Tb->AddTup();}
    for (int VarN=0; VarN<Tb->GetVars(); VarN++){
      if (VarN>0){Lx.GetSym(syTab); Lx.GetStr();}
      if (Lx.Str=='?'){Tb->PutVal(TupN, VarN, TTbVal(tvtUnknw));}
      else if (Lx.Str=='*'){Tb->PutVal(TupN, VarN, TTbVal(tvtUnimp));}
      else if (Lx.Str=='/'){Tb->PutVal(TupN, VarN, TTbVal(tvtUnapp));}
      else {
        double Flt;
        if (TStr(Lx.Str).IsFlt(Flt)){
          Tb->PutFlt(TupN, VarN, Flt);
        } else {
          Tb->PutDsc(TupN, VarN, Lx.Str);
        }
      }
    }
    //printf("Tups: %d\r", Tb->GetTups());
    Lx.GetSym(syEoln, syEof);
    while (Lx.Sym==syEoln){Lx.GetSym(syStr, syEoln, syEof);}
  }
  Tb->DefVarTypes();
  return Tb;
}
コード例 #16
0
void TNmObjBs::LoadNmObjTypeBs(const PSIn& SIn){
  if (SIn.Empty()){return;}
  TILx Lx(SIn, TFSet(iloCmtAlw, iloRetEoln, iloExcept));
  // traverse lines
  Lx.GetSym(syQStr, syIdStr, syEoln, syEof);
  while (Lx.Sym!=syEof){
    if ((Lx.Sym==syQStr)||(Lx.Sym==syIdStr)){
      TVec<TStrV> NmObjWordStrVV;
      TB32Set NmObjAttrSet;
      while ((Lx.Sym==syQStr)||(Lx.Sym==syIdStr)){
        if (Lx.Sym==syQStr){
          // named-object word-string
          TStr WordStrVStr=Lx.Str;
          TStrV WordStrV; WordStrVStr.SplitOnWs(WordStrV);
          NmObjWordStrVV.Add(WordStrV);
        } else
        if (Lx.Sym==syIdStr){
          // named-object attribute
          TNmObjAttr NmObjAttr=TNmObjBs::GetNmObjTypeFromStr(Lx.Str);
          NmObjAttrSet.Incl(NmObjAttr);
        } else {
          Fail;
        }
        Lx.GetSym(syQStr, syIdStr, syEoln, syEof);
      }
      // assign 'defined' attribute if 'not ignore'
      if (!NmObjAttrSet.In(noaIgnore)){
        NmObjAttrSet.Incl(noaDefined);}
      // assign attribute-sets to word-vectors
      for (int NmObjN=0; NmObjN<NmObjWordStrVV.Len(); NmObjN++){
        WordStrVToNmObjAttrSetH.AddDat(NmObjWordStrVV[NmObjN])|=NmObjAttrSet;
      }
      // assign aliases
      {for (int NmObjN=1; NmObjN<NmObjWordStrVV.Len(); NmObjN++){
        NmObjWordStrVToNrH.AddDat(NmObjWordStrVV[NmObjN], NmObjWordStrVV[0]);
      }}
      // get eoln
    } else
    if (Lx.Sym==syEoln){
      // empty line
      Lx.GetSym(syQStr, syEoln, syEof);
    } else {
      Fail;
    }
  }
}
コード例 #17
0
ファイル: wixexp.cpp プロジェクト: mkarlovc/gcentralization
TWixExp::TWixExp(const TStr& _ExpStr):
  ExpStr(_ExpStr), Ok(true), ErrMsg(), ExpItem(),
  FactExpect(), TermExpect(), ExpExpect(){
  // prepare expect sets
  FactExpect=TFSet()|wesyNot|wesyIncl|wesyExcl|wesyLParen|wesyDQuote|wesyWord;
  TermExpect=FactExpect;
  ExpExpect=TermExpect;
  // parse the expression string
  TWixExpLx Lx(ExpStr);
  try {
    Lx.GetSym(ExpExpect);
    ExpItem=ParseExp(Lx, TFSet()|wesyEof);
  }
  catch (EWixExp E){
    Ok=false; ErrMsg=E.GetErrMsg();
  }
}
コード例 #18
0
void TNmObjBs::LoadCustSwSet(const PSIn& SIn){
  if (SIn.Empty()){return;}
  TILx Lx(SIn, TFSet(iloCmtAlw, iloRetEoln, iloExcept));
  // traverse lines
  Lx.GetSym(syLn, syEof);
  while (Lx.Sym!=syEof){
    // get stop-phrase string
    TStr WordStrVStr=Lx.Str;
    // split phrase to words
    TStrV WordStrV; WordStrVStr.SplitOnWs(WordStrV);
    if (!WordStrV.Empty()){
      // define phrase as stop-word
      WordStrVToNmObjAttrSetH.AddDat(WordStrV).Incl(noaIgnore);
    }
    // get next symbol
    Lx.GetSym(syLn, syEof);
  }
}
コード例 #19
0
ファイル: webtrv.cpp プロジェクト: Accio/snap
void TWebTravelCmuPww::StartTravel(){
  PutConstrs();
  TStrV UrlStrV(1000, 0);
  PSIn SIn=PSIn(new TFIn(InFNm));
  TILx Lx(SIn, TFSet()|iloRetEoln);
  Lx.GetSym(syQStr, syEof);
  while (Lx.Sym!=syEof){
    TStr UrlStr=Lx.Str;
    if (IsUrlOk(UrlStr)){
      UrlStrV.Add(UrlStr);}
    Lx.GetStrToEoln();
    Lx.GetEoln();
    Lx.GetSym(syQStr, syEof);
  }
  for (int UrlStrN=0; UrlStrN<UrlStrV.Len(); UrlStrN++){
    Go(UrlStrV[UrlStrN]);
  }
}
コード例 #20
0
TStr TCordisEuPart::GetNrOrgNm(const TStr& Str){
  TStrV NrStrV; TChA ChA;
  PSwSet SwSet=TSwSet::GetSwSet(swstEnglish523);
  PSIn HtmlSIn=TStrIn::New(Str);
  THtmlLx Lx(HtmlSIn);
  while (Lx.Sym!=hsyEof){
    if ((Lx.Sym==hsyStr)||(Lx.Sym==hsyNum)){
      Lx.UcChA.ChangeCh('Â', 'A');
      Lx.UcChA.ChangeCh('Á', 'A');
      Lx.UcChA.ChangeCh('Ä', 'A');
      Lx.UcChA.ChangeCh('Ã', 'A');
      Lx.UcChA.ChangeCh('À', 'A');
      Lx.UcChA.ChangeCh('Ç', 'C');
      Lx.UcChA.ChangeCh('É', 'E');
      Lx.UcChA.ChangeCh('È', 'E');
      Lx.UcChA.ChangeCh('Ê', 'E');
      Lx.UcChA.ChangeCh('Í', 'I');
      Lx.UcChA.ChangeCh('Ó', 'O');
      Lx.UcChA.ChangeCh('Ö', 'O');
      Lx.UcChA.ChangeCh('Ñ', 'N');
      Lx.UcChA.ChangeCh('Ü', 'U');
      Lx.UcChA.ChangeCh('Ú', 'U');
      TStr NrStr=THtmlLx::GetAsciiStr(Lx.UcChA);
      if ((NrStr.Len()==1)||(SwSet->IsIn(NrStr))||
       (NrStr=="AG")||(NrStr=="GMBH")||(NrStr=="LTD")||(NrStr=="SRL")||
       (NrStr=="SA")||(NrStr=="EV")||(NrStr=="AS")||(NrStr=="AB")||
       (NrStr=="NV")||(NrStr=="BV")||
       (NrStr=="AKTIENGESELLSCHAFT")||(NrStr=="LIMITED")||
       (NrStr=="FUER")||(NrStr=="FUR")){
        NrStr="";}
      if (!NrStr.Empty()){NrStrV.Add(NrStr);}
    }
    Lx.GetSym();
  }
  TChA NrChA;
  for (int NrStrN=0; NrStrN<NrStrV.Len(); NrStrN++){
    if (NrStrN>0){NrChA+=' ';}
    NrChA+=NrStrV[NrStrN];
  }
  if (NrChA.Empty()){
    NrChA=Str.GetUc();
  }
  return NrChA;
}
コード例 #21
0
PTb TTb::LoadTxtCsv(const TStr& FNm, const PTb& Tb){
  // open file
  PSIn SIn=TFIn::New(FNm);
  TILx Lx(SIn, TFSet()|iloRetEoln|iloSigNum|iloUniStr);

  // read variable names
  Lx.GetStr();
  bool IsTupNm=(Lx.UcStr=="NAME")||(Lx.UcStr=="ID");
  if (IsTupNm){Lx.GetSym(syComma); Lx.GetStr();}
  do {
    PTbVarType VarType=PTbVarType(new TTbVarType());
    PTbVar Var=PTbVar(new TGTbVar(Lx.Str, VarType));
    Tb->AddVar(Var);
    if (Lx.GetSym(syComma, syEoln, syEof)==syComma){
      Lx.GetSym(syStr);}
  } while (Lx.Sym==syStr);

  // read tuples
  TFSet ValSymSet=TFSet()|syQuestion|syAsterisk|sySlash|syFlt|syStr;
  if (Lx.Sym!=syEof){
    Lx.GetSym(TFSet(ValSymSet)|syEof);}
  while (Lx.Sym!=syEof){
    int TupN;
    if (IsTupNm){
      TupN=Tb->AddTup(Lx.GetSymStr());
      Lx.GetSym(syComma); Lx.GetSym(ValSymSet);}
    else {TupN=Tb->AddTup();}
    for (int VarN=0; VarN<Tb->GetVars(); VarN++){
      if (VarN>0){Lx.GetSym(syComma); Lx.GetSym(ValSymSet);}
      switch (Lx.Sym){
        case syQuestion: Tb->PutVal(TupN, VarN, TTbVal(tvtUnknw)); break;
        case syAsterisk: Tb->PutVal(TupN, VarN, TTbVal(tvtUnimp)); break;
        case sySlash: Tb->PutVal(TupN, VarN, TTbVal(tvtUnapp)); break;
        case syStr: Tb->PutDsc(TupN, VarN, Lx.Str); break;
        case syFlt: Tb->PutFlt(TupN, VarN, Lx.Flt); break;
        default: Fail;
      }
    }
    Lx.GetSym(syEoln, syEof);
    while (Lx.Sym==syEoln){Lx.GetSym(TFSet(ValSymSet)|syEoln|syEof);}
  }
  Tb->DefVarTypes();
  return Tb;
}
コード例 #22
0
ファイル: tql.cpp プロジェクト: Accio/snap
TTqlExp::TTqlExp(const TStr& _ExpStr):
  ExpStr(_ExpStr), Ok(true), ErrMsg(), Item(),
  RelOpSet(), FactExpect(), TermExpect(), ExpExpect(){
  // symbol sets
  RelOpSet=TFSet(tsyLss, tsyLEq, tsyEq, tsyNEq, tsyGEq, tsyGtr);
  FactExpect=TFSet(tsyNot, tsyIncl, tsyExcl, tsyTitle, tsyLParen, tsyLBracket,
   tsyDQuote, tsyWord);
  TermExpect=FactExpect;
  ExpExpect=TermExpect;

  TTqlLx Lx(ExpStr);
  try {
    Lx.GetSym(ExpExpect);
    Item=ParseExp(Lx, TFSet()|tsyEof);
  }
  catch (ETql E){
    Ok=false; ErrMsg=E.GetErrMsg();
  }
}
コード例 #23
0
ファイル: book.cpp プロジェクト: mkarlovc/gcentralization
TBible::TBible(const TStr& FNm):
  TBook("Bible", "King James Version", "Religious"),
  ChpNmSecIdKdV(), PsalmV(), Bix(TBix::New()){
  // open file
  PSIn SIn=TFIn::New(FNm);
  TILx Lx(SIn, TFSet());
  // define state variables
  bool InPsalm=false; TStr ChpNm; TChA SecNChA; int SecN;
  TChA SSecNChA; int SSecN; TStr SSecStr;
  // parsing
  while (Lx.GetSym(syLn, syEof)!=syEof){
    TChA& Ln=Lx.Str;
    int VBarChN=Ln.SearchCh('|');
    if ((VBarChN!=-1)&&(0<VBarChN)&&(VBarChN<Lx.Str.Len())&&
     TCh::IsAlNum(Ln[VBarChN-1])&&TCh::IsNum(Ln[VBarChN+1])){
      if (InPsalm){AddPsalm(ChpNm, SecN, SSecN, SSecStr);}
//      if (PsalmV.Len()>100){return;}
      InPsalm=true;
      // psalm name
      ChpNm=Ln.GetSubStr(0, VBarChN-1).GetTrunc();
      if (ChpNmSecIdKdV.Empty()||ChpNmSecIdKdV.Last().Key!=ChpNm){
        ChpNmSecIdKdV.Add(TStrIntKd(ChpNm, PsalmV.Len()));}
      // section number
      SecNChA.Clr(); int ChN=VBarChN+1;
      while (TCh::IsNum(Ln[ChN])){SecNChA+=Ln[ChN]; ChN++;}
      SecN=TStr(SecNChA).GetInt();
      IAssert(Ln[ChN]==':');
      // subsection number
      SSecNChA.Clr(); ChN++;
      while (TCh::IsNum(Ln[ChN])){SSecNChA+=Ln[ChN]; ChN++;}
      SSecN=TStr(SSecNChA).GetInt();
      // text
      SSecStr=Ln.GetSubStr(ChN, Ln.Len()-1).GetTrunc();
    } else
    if (InPsalm){
      SSecStr=(SSecStr+' '+Ln).GetTrunc();
    }
  }
  // save last psalm
  if (InPsalm){AddPsalm(ChpNm, SecN, SSecN, SSecStr);}
}
コード例 #24
0
ファイル: webtrv.cpp プロジェクト: Accio/snap
void TWebTravelHomeNet::StartTravel(){
  PutConstrs();
  TStrV UrlStrV(300000, 0);
  TIntIntH UserIdToDocsH(1000);
  PSIn SIn=PSIn(new TFIn(InFNm));
  TILx Lx(SIn, TFSet()|iloRetEoln);
  TChA UrlStr;
  Lx.GetSym(syInt, syEof);
  while ((Lx.Sym!=syEof)&&(Lx.SymLnN<200000)){
//  while (Lx.Sym!=syEof){
    int UserId=Lx.Int; Lx.GetSym(syComma);
    Lx.GetInt(); Lx.GetSym(syComma);
    Lx.GetInt(); Lx.GetSym(syComma);
    Lx.GetInt(); Lx.GetSym(syComma);
    Lx.GetInt(); Lx.GetSym(syComma);
    TStr Method=Lx.GetIdStr(); Lx.GetSym(syComma);  // GET, POST
    UrlStr.Clr(); UrlStr+=Lx.GetIdStr(); Lx.GetSym(syComma); // http, ftp
    UrlStr+="://";
    UrlStr+=Lx.GetStrToCh(','); Lx.GetSym(syComma); // domain name
    UrlStr+=Lx.GetStrToEoln(); Lx.GetEoln(); // path
    if ((UserId==TgUserId)&&IsUrlOk(UrlStr)&&(Method=="GET")){
      UserIdToDocsH.AddDat(UserId)++;
      UrlStrV.Add(UrlStr);
    }
    Lx.GetSym(syInt, syEof);
    if (Lx.SymLnN%100000==0){OnNotify(TInt::GetStr(Lx.SymLnN)+ " docs");}
  }
  int UserIdToDocsP=UserIdToDocsH.FFirstKeyId();
  while (UserIdToDocsH.FNextKeyId(UserIdToDocsP)){
    int UserId=UserIdToDocsH.GetKey(UserIdToDocsP);
    int Docs=UserIdToDocsH[UserIdToDocsP];
    TStr MsgStr=TStr("User ")+TInt::GetStr(UserId)+": "+
     TInt::GetStr(Docs)+" Docs.";
    OnNotify(MsgStr);
  }
  UrlStrV.Shuffle(TRnd());
  for (int UrlStrN=0; UrlStrN<UrlStrV.Len(); UrlStrN++){
    Go(UrlStrV[UrlStrN]);
  }
}
コード例 #25
0
ファイル: binary_relation.cpp プロジェクト: imclab/pomagma
void BinaryRelation::validate () const
{
    POMAGMA_INFO("Validating BinaryRelation");

    m_lines.validate();

    size_t num_pairs = 0;

    DenseSet Lx(round_item_dim(), nullptr);
    DenseSet Rx(round_item_dim(), nullptr);
    for (Ob i = 1; i <= item_dim(); ++i) {
        bool sup_i = supports(i);
        Lx.init(m_lines.Lx(i));

        for (Ob j = 1; j <= item_dim(); ++j) {
            bool sup_ij = sup_i and supports(j);
            Rx.init(m_lines.Rx(j));

            bool Lx_ij = Lx.contains(j);
            bool Rx_ij = Rx.contains(i);
            num_pairs += Rx_ij;

            POMAGMA_ASSERT(Lx_ij == Rx_ij,
                    "Lx,Rx disagree at " << i << "," << j
                    << ", Lx is " << Lx_ij << ", Rx is " << Rx_ij  );

            POMAGMA_ASSERT(sup_ij or not Lx_ij,
                    "Lx unsupported at " << i << "," << j );

            POMAGMA_ASSERT(sup_ij or not Rx_ij,
                    "Rx unsupported at " << i << "," << j );
        }
    }

    size_t true_size = count_pairs();
    POMAGMA_ASSERT(num_pairs == true_size,
            "incorrect number of pairs: "
            << num_pairs << " should be " << true_size);
}
コード例 #26
0
void TTb::SaveTxt(const TStr& FNm, const bool& SaveTupNm){
  TOLx Lx(PSOut(new TFOut(FNm)), TFSet()|oloFrcEoln|oloSigNum|oloUniStr|oloTabSep);
  if (SaveTupNm){Lx.PutStr("Name");}
  for (int VarN=0; VarN<GetVars(); VarN++){
    Lx.PutStr(GetVar(VarN)->GetNm());}
  Lx.PutLn();

  for (int TupN=0; TupN<GetTups(); TupN++){
    if (SaveTupNm){Lx.PutStr(GetTupNm(TupN));}
    for (int VarN=0; VarN<GetVars(); VarN++){
      TTbVal Val=GetVal(TupN, VarN);
      switch (Val.GetValTag()){
        case tvtUnknw: Lx.PutSym(syQuestion); break;
        case tvtUnimp: Lx.PutSym(syAsterisk); break;
        case tvtUnapp: Lx.PutSym(sySlash); break;
        case tvtDsc: Lx.PutStr(GetVar(VarN)->GetVarType()->GetValStr(Val)); break;
        case tvtFlt: Lx.PutFlt(Val.GetFlt()); break;
        default: Fail;
      }
    }
    Lx.PutLn();
  }
}
コード例 #27
0
ファイル: prolog.cpp プロジェクト: SherlockYang/Archive
PPlBs TPlBs::LoadTxtPl(const TStr& FNmWc){
  PPlBs PlBs=TPlBs::New();
  printf("Loading Prolog from '%s'...\n", FNmWc.CStr());
  TFFile FFile(FNmWc); TStr FNm;
  while (FFile.Next(FNm)){
    printf("  ...loading '%s'\n", FNm.CStr());
    // process prolog-file
    PSIn SIn=TFIn::New(FNm);
    TILx Lx(SIn, TFSet()|/*iloList|*/iloCmtAlw|iloCsSens|iloUniStr|iloExcept);
    Lx.GetSym(TFSet(TupExpect)|syEof);
    while (Lx.Sym!=syEof){
      TPlVal TupVal=TPlBs::ParseTup(Lx, TFSet()|syPeriod, PlBs);
      int FuncId=PlBs->TupV[TupVal.GetTupId()]->GetFuncId();
      int Arity=PlBs->TupV[TupVal.GetTupId()]->GetVals();
      PlBs->FuncIdArityPrToTupIdVH.
       AddDat(TIntPr(FuncId, Arity)).Add(TupVal.GetTupId());
      Lx.GetSym(TFSet(TupExpect)|syEof);
    }
    //break;
  }
  printf("Done.\n");
  return PlBs;
}
コード例 #28
0
void base_bin_rel::validate() const
{
    m_support.validate();

    // TODO validate Lx, Rx agree with support
    // (move code over from dense_bin_rel::validate()

    if (_symmetric()) {

        // check emptiness outside of support
        dense_set set(item_dim(), NULL);
        dense_set round_set(m_round_item_dim, NULL);
        for (oid_t i = 0; i < m_round_item_dim; ++i) {
            if (1 <= i and i <= item_dim()) {
                set.init(Lx(i));
                set.validate();
            } else {
                round_set.init(m_Lx_lines + m_round_word_dim * i);
                round_set.validate();
                POMAGMA_ASSERT(round_set.empty(),
                        "unsupported Lx(" << i << ") has " <<
                        round_set.count_items() << " items");
            }
        }

        // check for Lx/Rx agreement
        for (oid_t i = 1; i <= item_dim(); ++i) {
        for (oid_t j = i; j <= item_dim(); ++j) {
            POMAGMA_ASSERT(Lx(i, j) == Rx(i, j),
                    "Lx, Rx disagree at " << i << ',' << j);
        }}

    } else {

        // check emptiness outside of support
        dense_set set(item_dim(), NULL);
        dense_set round_set(m_round_item_dim, NULL);
        for (oid_t i = 0; i < m_round_item_dim; ++i) {
            if (1 <= i and i <= item_dim()) {
                set.init(Lx(i));
                set.validate();
                set.init(Rx(i));
                set.validate();
            } else {
                round_set.init(m_Lx_lines + m_round_word_dim * i);
                round_set.validate();
                POMAGMA_ASSERT(round_set.empty(),
                        "unsupported Lx(" << i << ") has " <<
                        round_set.count_items() << " items");
                round_set.init(m_Rx_lines + m_round_word_dim * i);
                round_set.validate();
                POMAGMA_ASSERT(round_set.empty(),
                        "unsupported Rx(" << i << ") has " <<
                        round_set.count_items() << " items");
            }
        }

        // check for Lx/Rx agreement
        for (oid_t i = 1; i <= item_dim(); ++i) {
        for (oid_t j = 1; j <= item_dim(); ++j) {
            POMAGMA_ASSERT(Lx(i, j) == Rx(i, j),
                    "Lx, Rx disagree at " << i << ',' << j);
        }}
    }
}
コード例 #29
0
ファイル: exp.cpp プロジェクト: Accio/snap
void TExpVal::SaveTxt(const PSOut& SOut) const {
  TOLx Lx(SOut, TFSet()|oloCmtAlw|oloSigNum|oloCsSens);
  SaveTxt(Lx);
}
コード例 #30
0
ファイル: cpdoc.cpp プロジェクト: mkarlovc/gcentralization
void TCpDoc::SaveAsfaToCpd(const TStr& InFPath, const TStr& OutCpdFNm){
  // create output file
  PSOut SOut=TFOut::New(OutCpdFNm);
  // traverse files
  TStrH AccessionIdH;
  TFFile FFile(TStr::GetNrFPath(InFPath)+"*.Asfa"); TStr AsfaFNm;
  while (FFile.Next(AsfaFNm)){
    printf("Processing file '%s'\n", AsfaFNm.CStr());
    PSIn SIn=TFIn::New(AsfaFNm);
    TILx Lx(SIn, TFSet(iloRetEoln, iloExcept));
    Lx.GetSym(syLn, syEof);
    while (Lx.Sym!=syEof){
      // Query Line
      TStr QueryLnStr=Lx.Str;
      TStrV QueryStrV; QueryLnStr.SplitOnAllCh('\t', QueryStrV, false);
      IAssert(QueryStrV[0]=="Query");
      // RecordNo Line
      Lx.GetSym(syLn); TStr RecNoLnStr=Lx.Str;
      TStrV RecNoStrV; RecNoLnStr.SplitOnAllCh('\t', RecNoStrV, false);
      IAssert(RecNoStrV[0]=="RecordNo");
      //int RecN=RecNoStrV[1].GetInt();
      // fields (format: Short-Name Tab Long-Name Tab Value-String)
      TStr TitleStr, AbstractStr, PublicationYearStr, AccessionId;
      TStrV AuthorNmV; TStrV TermNmV1, TermNmV2;
      while (true){
        Lx.GetSym(syLn); TStr FldLnStr=Lx.Str;
        TStrV FldStrV; FldLnStr.SplitOnAllCh('\t', FldStrV, false);
        if (FldStrV[0]=="----"){
          if (!AccessionIdH.IsKey(AccessionId)){
            AccessionIdH.AddKey(AccessionId);
            // create & save cpd document
            PCpDoc CpDoc=TCpDoc::New();
            CpDoc->DocNm=AccessionId;
            CpDoc->DateStr=PublicationYearStr;
            CpDoc->TitleStr=TitleStr;
            CpDoc->ParStrV.Add(AbstractStr);
            CpDoc->TopCdNmV=TermNmV1;
            CpDoc->GeoCdNmV=TermNmV2;
            CpDoc->IndCdNmV=AuthorNmV;
            CpDoc->Save(*SOut);
          } else {/*printf("[%s]", AccessionId.CStr());*/}
          break;
        } else
        if (FldStrV[0]=="TI"){
          TitleStr=FldStrV[2];
        } else if (FldStrV[0]=="TI"){
          TitleStr=FldStrV[2];
        } else if (FldStrV[0]=="AU"){
          FldStrV[2].SplitOnAllCh(';', AuthorNmV);
          for (int StrN=0; StrN<AuthorNmV.Len(); StrN++){AuthorNmV[StrN].ToTrunc();}
        } else if (FldStrV[0]=="AB"){
          AbstractStr=FldStrV[2];
        } else if (FldStrV[0]=="PY"){
          PublicationYearStr=FldStrV[2];
        } else if (FldStrV[0]=="DE"){
          FldStrV[2].SplitOnAllCh(';', TermNmV1);
          for (int StrN=0; StrN<TermNmV1.Len(); StrN++){TermNmV1[StrN].ToTrunc();}
        } else if (FldStrV[0]=="CL"){
          FldStrV[2].SplitOnAllCh(';', TermNmV2);
          for (int StrN=0; StrN<TermNmV2.Len(); StrN++){TermNmV2[StrN].ToTrunc();}
        } else if (FldStrV[0]=="AN"){
          AccessionId=FldStrV[2];
        }
      }
      printf("%d\r", AccessionIdH.Len());
      Lx.GetSym(syLn, syEof);
    }
  }
}