Ejemplo n.º 1
0
void TTable::SaveSS(const TStr& OutFNm){
  FILE* F = fopen(OutFNm.CStr(), "w");
  // debug
  if(F == NULL){
    printf("failed to open file %s\n", OutFNm.CStr());
    perror("fail ");
    return;
  }

  TInt L = S.Len();
  // print title (schema)
  for(TInt i = 0; i < L-1; i++){
    fprintf(F, "%s\t", GetSchemaColName(i).CStr());
  }  
   fprintf(F, "%s\n", GetSchemaColName(L-1).CStr());
  // print table contents
  for(TRowIterator RowI = BegRI(); RowI < EndRI(); RowI++){
    for(TInt i = 0; i < L; i++){
      char C = (i == L-1) ? '\n' : '\t';
	    switch(GetSchemaColType(i)){
	      case INT:{
		    fprintf(F, "%d%c", RowI.GetIntAttr(GetSchemaColName(i)).Val, C);
		    break;
		  }
	     case FLT:{
		    fprintf(F, "%f%c", RowI.GetFltAttr(GetSchemaColName(i)).Val, C);
		    break;
		  }
	    case STR:{
		    fprintf(F, "%s%c", RowI.GetStrAttr(GetSchemaColName(i)).CStr(), C);
		    break;
		  }
	   }
	}
 }
 fclose(F);
}
Ejemplo n.º 2
0
int main(int argc, char* argv[]) {
  Env = TEnv(argc, argv, TNotify::StdNotify);
  Env.PrepArgs(TStr::Fmt("Clique Percolation Method. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
  TExeTm ExeTm;
  Try
  
  const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt", "Input undirected graph file (single directed edge per line)");
  const int OverlapSz = Env.GetIfArgPrefixInt("-k:", 2, "Min clique overlap");
  TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "Output file prefix");
  if (OutFNm.Empty()) { OutFNm = InFNm.GetFMid(); }

  PUNGraph G;
  if (InFNm == "DEMO") { // small demo graph
    G = TUNGraph::New();
    for (int i = 1; i < 8; i++) { G->AddNode(i); }
    G->AddEdge(1,2);
    G->AddEdge(2,3); G->AddEdge(2,4);
    G->AddEdge(3,4);
    G->AddEdge(4,5); G->AddEdge(4,7);
    G->AddEdge(5,6); G->AddEdge(5,7);
    G->AddEdge(6,7);
    // draw the small graph using GraphViz
    TSnap::DrawGViz(G, gvlNeato, "small_graph.png", "", true); 
  }
  // load graph
  else if (InFNm.GetFExt().GetLc()==".ungraph") {
    TFIn FIn(InFNm);  G=TUNGraph::Load(FIn); }
  else if (InFNm.GetFExt().GetLc()==".ngraph") {
    TFIn FIn(InFNm);  G=TSnap::ConvertGraph<PUNGraph>(TNGraph::Load(FIn), false); }
  else {
    G = TSnap::LoadEdgeList<PUNGraph>(InFNm, 0, 1); }
  // find communities
  TVec<TIntV> CmtyV;
  TCliqueOverlap::GetCPMCommunities(G, OverlapSz+1, CmtyV);
  // save result
  FILE *F = fopen(TStr::Fmt("cpm-%s.txt", OutFNm.CStr()).CStr(), "wt");
  fprintf(F, "# %d Overlapping Clique Percolation Communities (min clique overlap %d)\n", CmtyV.Len(), OverlapSz);
  fprintf(F, "# Each line contains nodes belonging to the same community community\n");
  for (int i = 0; i < CmtyV.Len(); i++) {
    fprintf(F, "%d", CmtyV[i][0].Val);
    for (int j = 1; j < CmtyV[i].Len(); j++) {
      fprintf(F, "\t%d", CmtyV[i][j].Val);
    }
    fprintf(F, "\n");
  }
  Catch
  printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  return 0;
}
Ejemplo n.º 3
0
void __fastcall TVclStrGrid::OnActExtEdBtClick(TObject *Sender){
  TStr ExtNm=ActExtEdBt->Caption.c_str();
  TExtGetStrF ExtGetStrF;
  if (IsExtGetStrF(ExtNm, ExtGetStrF)){
    int ColN; int RowN;
    if (IsSelCell(ColN, RowN)){
      TStr PrevValStr=GetVal(ColN, RowN);
      TStr NewValStr; bool OkP;
      (*ExtGetStrF())(false, PrevValStr, NewValStr, OkP);
      if (OkP){
        ActExtValEd->Text=NewValStr.CStr();
      }
    }
  }
}
Ejemplo n.º 4
0
double TEnv::GetIfArgPrefixFlt(
    const TStr& PrefixStr, const double& DfVal, const TStr& DNm) const {
    if (Env.GetArgs()<=MnArgs) {
        // 'usage' argument message
        if (!SilentP) {
            printf("   %s%s (default:%g)\n", PrefixStr.CStr(), DNm.CStr(), DfVal);
        }
        return DfVal;
    } else {
        // argument & value message
        double Val;
        if (Env.IsArgPrefix(PrefixStr)) {
            TStr ValStr=Env.GetArgPostfix(PrefixStr);
            Val=ValStr.GetFlt(DfVal);
        } else {
            Val=DfVal;
        }
        TStr MsgStr=DNm+" ("+PrefixStr+")="+TFlt::GetStr(Val);
        if (!SilentP) {
            TNotify::OnStatus(Notify, MsgStr);
        }
        return Val;
    }
}
Ejemplo n.º 5
0
void TGraphKey::SaveGViz(const TStr& OutFNm, const TStr& Desc, const TStr& NodeAttrs, const int& Size) const {
  FILE *F = fopen(OutFNm.CStr(), "wt");
  fprintf(F, "/*****\n");
  fprintf(F, "  Graph (%d, %d)\n", GetNodes(), GetEdges());
  //if (! Desc.Empty()) fprintf(F, "  %s\n", Desc.CStr());
  fprintf(F, "*****/\n\n");
  fprintf(F, "digraph G {\n");
  if (Size != -1) fprintf(F, "  size=\"%d,%d\";\n", Size, Size);
  fprintf(F, "  graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
  if (NodeAttrs.Empty()) fprintf(F, "  node  [shape=ellipse, width=0.3, height=0.3]\n");
  else fprintf(F, "  node  [shape=ellipse, %s]\n", NodeAttrs.CStr());
  if (! EdgeV.Empty()) {
    for (int e = 0; e < EdgeV.Len(); e++) {
      fprintf(F, "  %d -> %d;\n", EdgeV[e].Val1(), EdgeV[e].Val2()); }
  } else {
    for (int n = 0; n < Nodes; n++) { fprintf(F, "  %d;\n", n); }
  }
  if (! Desc.Empty()) {
    fprintf(F, "  label = \"\\n%s\\n\";", Desc.CStr());
    fprintf(F, "  fontsize=24;\n");
  }
  fprintf(F, "}\n");
  fclose(F);
}
Ejemplo n.º 6
0
Archivo: gstat.cpp Proyecto: Accio/snap
void TGStat::Plot(const TGStatDistr& Distr, const TStr& FNmPref, TStr Desc, bool PowerFit) const {
  if (Desc.Empty()) Desc = FNmPref.GetUc();
  if (! HasDistr(Distr) || Distr==gsdUndef || Distr==gsdMx) { return; }
  TPlotInfo Info = GetPlotInfo(Distr);
  TGnuPlot GnuPlot(Info.Val1+TStr(".")+FNmPref, TStr::Fmt("%s. G(%d, %d)", Desc.CStr(), GetNodes(),GetEdges()));
  GnuPlot.SetXYLabel(Info.Val2, Info.Val3);
  GnuPlot.SetScale(Info.Val4);
  const int plotId = GnuPlot.AddPlot(GetDistr(Distr), gpwLinesPoints, "");
  if (PowerFit) { GnuPlot.AddPwrFit(plotId, gpwLines); }
  #ifdef GLib_MACOSX
  GnuPlot.SaveEps();
  #else
  GnuPlot.SavePng();
  #endif
}
Ejemplo n.º 7
0
TEST(TNEANet, GetSAttrNameE) {
  PNEANet Graph;
  Graph = TNEANet::New();
  TInt AttrId;
  Graph->AddSAttrE("TestInt", atInt, AttrId);
  Graph->AddSAttrE("TestFlt", atFlt, AttrId);
  Graph->AddSAttrE("TestStr", atStr, AttrId);
  TAttrType AttrType;
  TStr Name;
  int status = Graph->GetSAttrNameE(0, Name, AttrType);
  EXPECT_EQ(0, status);
  EXPECT_EQ(atInt, AttrType);
  EXPECT_STREQ("TestInt", Name.CStr());
  status = Graph->GetSAttrNameE(1, Name, AttrType);
  EXPECT_EQ(0, status);
  EXPECT_EQ(atFlt, AttrType);
  EXPECT_STREQ("TestFlt", Name.CStr());
  status = Graph->GetSAttrNameE(2, Name, AttrType);
  EXPECT_EQ(0, status);
  EXPECT_EQ(atStr, AttrType);
  EXPECT_STREQ("TestStr", Name.CStr());
  status = Graph->GetSAttrNameE(3, Name, AttrType);
  EXPECT_EQ(-1, status);
}
Ejemplo n.º 8
0
void TNetInfBs::SavePajek(const TStr& OutFNm) {
    TIntSet NIdSet;
    FILE *F = fopen(OutFNm.CStr(), "wt");
    fprintf(F, "*Vertices %d\r\n", NIdSet.Len());
    for (THash<TInt, TNodeInfo>::TIter NI = NodeNmH.BegI(); NI < NodeNmH.EndI(); NI++) {
      const TNodeInfo& I = NI.GetDat();
      fprintf(F, "%d \"%s\" ic Blue x_fact %f y_fact %f\r\n", NI.GetKey().Val,
        I.Name.CStr(), TMath::Mx<double>(log((double)I.Vol)-5,1), TMath::Mx<double>(log((double)I.Vol)-5,1));
    }
    fprintf(F, "*Arcs\r\n");
    for (TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
      fprintf(F, "%d %d 1\r\n", EI.GetSrcNId(), EI.GetDstNId());
    }
    fclose(F);
}
Ejemplo n.º 9
0
TZipIn::TZipIn(const TStr& FNm) : TSBase(FNm.CStr()), TSIn(FNm), ZipStdoutRd(NULL), ZipStdoutWr(NULL),
  FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
  EAssertR(! FNm.Empty(), "Empty file-name.");
  EAssertR(TFile::Exists(FNm), TStr::Fmt("File %s does not exist", FNm.CStr()).CStr());
  FLen = TZipIn::GetFLen(FNm);
  if (FLen == 0) { return; } // empty file
  #ifdef GLib_WIN
  // create pipes
  SECURITY_ATTRIBUTES saAttr;
  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
  saAttr.bInheritHandle = TRUE;
  saAttr.lpSecurityDescriptor = NULL;
    // Create a pipe for the child process's STDOUT.
  const int PipeBufferSz = 32*1024;
  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed");
  // Ensure the read handle to the pipe for STDOUT is not inherited.
  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
  #else
  // no implementation needed
  #endif
  CreateZipProcess(GetCmd(FNm), FNm);
  Bf = new char[MxBfL]; BfC = BfL=-1;
  FillBf();
}
Ejemplo n.º 10
0
void TNetInfBs::SavePlaneTextNet(const TStr& OutFNm) {
	TIntSet NIdSet;
	FILE *F = fopen(OutFNm.CStr(), "wt");
	for (THash<TInt, TNodeInfo>::TIter NI = NodeNmH.BegI(); NI < NodeNmH.EndI(); NI++) {
		const TNodeInfo& I = NI.GetDat();
		fprintf(F, "%d,%d\r\n", NI.GetKey().Val, NI.GetKey().Val);
	}

	fprintf(F, "\r\n");

	for (TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
		fprintf(F, "%d,%d\r\n", EI.GetSrcNId(), EI.GetDstNId());
	}
	fclose(F);
}
Ejemplo n.º 11
0
/// dump bipartite community affiliation into a text file with node names
void TAGMUtil::DumpCmtyVV(const TStr OutFNm, TVec<TIntV>& CmtyVV, TIntStrH& NIDNmH) {
    FILE* F = fopen(OutFNm.CStr(), "wt");
    for (int c = 0; c < CmtyVV.Len(); c++) {
        for (int u = 0; u < CmtyVV[c].Len(); u++) {
            if (NIDNmH.IsKey(CmtyVV[c][u])) {
                fprintf(F, "%s\t", NIDNmH.GetDat(CmtyVV[c][u]).CStr());
            }
            else {
                fprintf(F, "%d\t", (int) CmtyVV[c][u]);
            }
        }
        fprintf(F, "\n");
    }
    fclose(F);
}
Ejemplo n.º 12
0
int main(int argc, char *argv[]) {
  TDocBase *DocBase = new TDocBase;
  TChA Url = TChA("http://www.newyorktimes.com/news_story");
  TSecTm Date = TSecTm::GetCurTm();
  TChA Content = TChA("foo bar foo foo");
  TVec<TChA> Links;
  Links.Add(TChA("http://www.google.com"));
  Links.Add(TChA("http://www.yahoo.com"));
  DocBase->AddDoc(Url, Date, Content, Links);

  printf("Number of documents: %d\n", DocBase->Len());
  
  TDoc t;
  DocBase->GetDoc(0, t);
  TStr tUrl;
  t.GetUrl(tUrl);
  printf("URL: %s\n", tUrl.CStr());
  
  TStrV l;
  t.GetLinks(l);
  printf("Link1: %s\n", l[0].CStr());
  printf("Link2: %s\n", l[1].CStr());

  { TFOut FOut("tmp.bin"); DocBase->Save(FOut); }
  printf("Save data successfully\n");

  delete DocBase;

  TFIn FIn("tmp.bin");
  printf("Load data successfully\n");
  TDocBase *DocBase2 = new TDocBase;
  DocBase2->Load(FIn);

  printf("Number of documents: %d\n", DocBase2->Len());

  TDoc t2;
  DocBase2->GetDoc(0, t2);
  TStr t2Url;
  t2.GetUrl(t2Url);
  printf("URL: %s\n", t2Url.CStr());

  t2.GetLinks(l);
  printf("Link1: %s\n", l[0].CStr());
  printf("Link2: %s\n", l[1].CStr());

  delete DocBase2;
  return 0;
}
Ejemplo n.º 13
0
void InitHt(Handle<Object> Exports, const TStr& NsNm) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	Handle<Object> NsObj = Object::New(Isolate);

	TNodeJsStrStrH::Init(NsObj);
	TNodeJsStrIntH::Init(NsObj);
	TNodeJsStrFltH::Init(NsObj);

	TNodeJsIntStrH::Init(NsObj);
	TNodeJsIntIntH::Init(NsObj);
	TNodeJsIntFltH::Init(NsObj);

	Exports->Set(String::NewFromUtf8(Isolate, NsNm.CStr()), NsObj);
}
Ejemplo n.º 14
0
v8::Local<v8::Object> TNodeJsFIn::New(const TStr& FNm) {
    v8::Isolate* Isolate = v8::Isolate::GetCurrent();
    v8::EscapableHandleScope HandleScope(Isolate);

    v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(Isolate, constructor);
    v8::Local<v8::Value> ArgFNm = v8::String::NewFromUtf8(Isolate, FNm.CStr());
    // Pass file path as argument to New 
    const int Argc = 1;
    v8::Local<v8::Value> Argv[Argc] = { ArgFNm };
    v8::Local<v8::Object> Instance = cons->NewInstance(Argc, Argv);

    TNodeJsFIn* JsFIn = new TNodeJsFIn(FNm);
    JsFIn->Wrap(Instance);

    return HandleScope.Escape(Instance);
}
Ejemplo n.º 15
0
void TSockSys::GetAsyncSockHost(const TStr& HostNm, const PSockHost& SockHost) {
	// prepare address info request
	uv_getaddrinfo_t* Request = (uv_getaddrinfo_t*)malloc(sizeof(uv_getaddrinfo_t));
	// submit the request
	int ResCd = uv_getaddrinfo(Loop, Request, TSockSys::OnGetHost, HostNm.CStr(), NULL, NULL);
	// check submission went fine
	if (ResCd != 0) {
		// cleanup first
		free(Request);
		// and throw exception
		throw TExcept::New("TSockSys.GetAsyncSockHost: Error requestiong resolve of hostname " + HostNm);
	}
	// remember SockHost for the callback
	TUInt64 RequestHnd = (uint64)Request;
	HndToSockHostH.AddDat(RequestHnd, SockHost);
}
Ejemplo n.º 16
0
v8::Local<v8::Value> TNodeJsUtil::ParseJson(v8::Isolate* Isolate, const PJsonVal& JsonVal) {
    v8::EscapableHandleScope HandleScope(Isolate);
    
    if (!JsonVal->IsDef()) {
        return v8::Undefined(Isolate);
    }
    else if (JsonVal->IsBool()) {
        return v8::Boolean::New(Isolate, JsonVal->GetBool());
    }
    else if (JsonVal->IsNull()) {
        return v8::Null(Isolate);
    }
    else if (JsonVal->IsNum()) {
        return HandleScope.Escape(v8::Number::New(Isolate, JsonVal->GetNum()));
    }
    else if (JsonVal->IsStr()) {
        return HandleScope.Escape(v8::String::NewFromUtf8(Isolate, JsonVal->GetStr().CStr()));
    }
    else if (JsonVal->IsArr()) {
        const uint Len = JsonVal->GetArrVals();

        v8::Local<v8::Array> ResArr = v8::Array::New(Isolate, Len);

        for (uint i = 0; i < Len; i++) {
            ResArr->Set(i, ParseJson(Isolate, JsonVal->GetArrVal(i)));
        }

        return HandleScope.Escape(ResArr);
    }
    else if (JsonVal->IsObj()) {
        v8::Local<v8::Object> ResObj = v8::Object::New(Isolate);

        const int NKeys = JsonVal->GetObjKeys();

        for (int i = 0; i < NKeys; i++) {
            TStr Key;    PJsonVal Val;
            JsonVal->GetObjKeyVal(i, Key, Val);

            ResObj->Set(v8::String::NewFromUtf8(Isolate, Key.CStr()), ParseJson(Isolate, Val));
        }

        return HandleScope.Escape(ResObj);
    }
    else {
        throw TExcept::New("Invalid JSON!", "TNodeJsUtil::ParseJson");
    }
}
Ejemplo n.º 17
0
TFRnd::TFRnd(const TStr& _FNm, const TFAccess& FAccess,
 const bool& CreateIfNo, const int& _HdLen, const int& _RecLen):
  FileId(NULL), FNm(_FNm.CStr()),
  RecAct(false), HdLen(_HdLen), RecLen(_RecLen){
  RecAct=(HdLen>=0)&&(RecLen>0);
  switch (FAccess){
    case faCreate: FileId=fopen(FNm.CStr(), "w+b"); break;
    case faUpdate: FileId=fopen(FNm.CStr(), "r+b"); break;
    case faAppend: FileId=fopen(FNm.CStr(), "r+b");
      if (FileId!=NULL){fseek(FileId, SEEK_END, 0);} break;
    case faRdOnly: FileId=fopen(FNm.CStr(), "rb"); break;
    default: Fail;
  }
  if ((FileId==NULL)&&(CreateIfNo)){
    FileId=fopen(FNm.CStr(), "w+b");}
  EAssertR(FileId!=NULL, "Can not open file '"+_FNm+"'.");
}
Ejemplo n.º 18
0
TMovieTy TImdbNet::GetMovieTy(const TStr& MovieTyStr) {
  TStr LcStr = MovieTyStr.GetTrunc().GetLc();
  if (LcStr == "m") return mtyMovie;
  else if (LcStr == "tv") return mtyTv;
  else if (LcStr == "v") return mtyV;
  else if (LcStr == "vg") return mtyVg;
  else if (LcStr == "a") return mtyA;
  else if (LcStr == "scene") return mtyScene;
  else if (LcStr == "mini") return mtyMini;
  else if (LcStr == "archiv") return mtyArch;
  else if (LcStr == "voice") return mtyVoice;
  else if (LcStr == "singin") return mtySing;
  else if (LcStr == "als") return mtyAls;
  else if (LcStr == "episod") return mtyEpisod;
  else if (LcStr == "unconfirmed") return mtyUndef;
  printf("Unknown type: '%s'\n", LcStr.CStr());
  return mtyUndef;
}
Ejemplo n.º 19
0
Archivo: gstat.cpp Proyecto: Accio/snap
void TGStatVec::Plot(const TGStatVal& XVal, const TGStatVal& YVal, const TStr& OutFNm, TStr& Desc, const TGpScaleTy& Scale,const bool& PowerFit) const {
  if (! Last()->HasVal(XVal) || ! Last()->HasVal(YVal)) {
    if (! Last()->HasVal(XVal)) { printf("** Does not have %s statistic\n", TGStat::GetValStr(XVal).CStr()); }
    if (! Last()->HasVal(YVal)) { printf("** Does not have %s statistic\n", TGStat::GetValStr(YVal).CStr()); }
    return;
  }
  if (Desc.Empty()) { Desc = OutFNm; }
  TFltPrV ValV;
  TGStatVec::GetValV(XVal, YVal, ValV);
  TGnuPlot GP(TStr::Fmt("%s-%s.%s", TGStat::GetValStr(XVal).CStr(), TGStat::GetValStr(YVal).CStr(), OutFNm.CStr()),
    TStr::Fmt("%s. %s vs. %s. G(%d,%d)", Desc.CStr(), TGStat::GetValStr(XVal).CStr(), TGStat::GetValStr(YVal).CStr(),
    Last()->GetNodes(), Last()->GetEdges()));
  GP.SetScale(Scale);
  GP.SetXYLabel(TGStat::GetValStr(XVal), TGStat::GetValStr(YVal));
  const int Id = GP.AddPlot(ValV, gpwLinesPoints);
  if (PowerFit) { GP.AddPwrFit(Id); }
  GP.SavePng();
}
Ejemplo n.º 20
0
void InitLa(Handle<Object> Exports, const TStr& NsNm) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	Handle<Object> NsObj = Object::New(Isolate);

	TNodeJsLinAlg::Init(NsObj);
	TNodeJsVec<TFlt, TAuxFltV>::Init(NsObj);
	TNodeJsVec<TInt, TAuxIntV>::Init(NsObj);
	TNodeJsVec<TStr, TAuxStrV>::Init(NsObj);

	TNodeJsBoolV::Init(NsObj);
	TNodeJsFltVV::Init(NsObj);
	TNodeJsSpVec::Init(NsObj);
	TNodeJsSpMat::Init(NsObj);

	Exports->Set(String::NewFromUtf8(Isolate, NsNm.CStr()), NsObj);
}
Ejemplo n.º 21
0
v8::Local<v8::Object> TNodeJsFOut::New(const TStr& FNm, const bool& AppendP) {
    v8::Isolate* Isolate = v8::Isolate::GetCurrent();
    v8::EscapableHandleScope HandleScope(Isolate);

    v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(Isolate, constructor);

    v8::Local<v8::Value> ArgFNm = v8::String::NewFromUtf8(Isolate, FNm.CStr());
    v8::Local<v8::Value> ArgAppendP = v8::Boolean::New(Isolate, AppendP);
    // Pass file path and AppendP flag as arguments to New 
    const int Argc = 2;
    v8::Local<v8::Value> Argv[Argc] = { ArgFNm, ArgAppendP };
    v8::Local<v8::Object> Instance = cons->NewInstance(Argc, Argv);

    TNodeJsFOut* JsFOut = new TNodeJsFOut(FNm, AppendP);
    JsFOut->Wrap(Instance);

    return HandleScope.Escape(Instance);
}
Ejemplo n.º 22
0
TZipOut::TZipOut(const TStr& FNm) : TSBase(FNm.CStr()), TSOut(FNm), ZipStdinRd(NULL), ZipStdinWr(NULL), Bf(NULL), BfL(0){
  EAssertR(! FNm.Empty(), "Empty file-name.");
  #ifdef GLib_WIN
  // create pipes
  SECURITY_ATTRIBUTES saAttr;
  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
  saAttr.bInheritHandle = TRUE;
  saAttr.lpSecurityDescriptor = NULL;
  // Create a pipe for the child process's STDOUT.
  EAssertR(CreatePipe(&ZipStdinRd, &ZipStdinWr, &saAttr, 0), "Stdout pipe creation failed");
  // Ensure the read handle to the pipe for STDOUT is not inherited.
  SetHandleInformation(ZipStdinWr, HANDLE_FLAG_INHERIT, 0);
  #else
  // no implementation necessary
  #endif
  CreateZipProcess(GetCmd(FNm), FNm);
  Bf=new char[MxBfL];  BfL=0;
}
Ejemplo n.º 23
0
void TFile::Copy(const TStr& SrcFNm, const TStr& DstFNm, 
 const bool& ThrowExceptP, const bool& FailIfExistsP){
  if (ThrowExceptP){
    if (CopyFile(SrcFNm.CStr(), DstFNm.CStr(), FailIfExistsP) == 0) {
        int ErrorCode = (int)GetLastError();
        TExcept::Throw(TStr::Fmt(
            "Error %d copying file '%s' to '%s'.", 
            ErrorCode, SrcFNm.CStr(), DstFNm.CStr()));
    }
  } else {
    CopyFile(SrcFNm.CStr(), DstFNm.CStr(), FailIfExistsP);
  }
}
Ejemplo n.º 24
0
void PyInit(const TStr& PySettings)
{
	Try
	ifstream f(PySettings.CStr());
	if (f.is_open())
	{
		std::string s;
		std::getline(f, s);
		Py_Initialize(); // инициализация интерпретатора  */
		AddPath(s);
		AddPath(s+"\\\\networkx\\\\generators");
		AddPath(s+"\\\\networkx\\\\readwrite");
		AddPath(s+"\\\\networkx\\\\classes");
	}
	return;		
	IAssert(1);
	Catch
	
}
Ejemplo n.º 25
0
void em_multi(ExamMgr& ExM) {
	TExeTm tm;
	TFltV Alphas(ExM.CPU), ThVs[ExM.CPU];
	for (int i=0; i<ExM.CPU; i++) ThVs[i] = TFltV(ExM.W+1);
	std::vector<std::thread> threads;
	for (int i=0; i<ExM.CPU; i++) threads.emplace_back([i, &ExM, &Alphas, &ThVs] { em_sub(i, ExM, Alphas[i], ThVs[i]); });
	for(std::thread& t: threads) t.join();
	for (int n=1; n<ExM.CPU; n++) Alphas[0] += Alphas[n];
	Alphas[0] /= ExM.CPU;
	for (int i=0; i<=ExM.W; i++) {
		for (int n=1; n<ExM.CPU; n++) ThVs[0][i] += ThVs[n][i];
		ThVs[0][i] /= ExM.CPU;
	}
	if (ExM.TrimTail) ExM.TrimTailNTh(ThVs[0], Alphas[0]);
	const TStr OFnm = ExM.GetBNTHFNm();
	BIO::SaveFltVWithIdx(ThVs[0], OFnm, TStr::Fmt("# Nodes: %d\n# Repeated: %d\n# Avg time cost: %.2f secs.\n# Alpha: %.6e",
			ExM.N, ExM.GetRpt(), tm.GetSecs()/ExM.GetRpt(), Alphas[0].Val));
	printf("Saved to %s\n", OFnm.CStr());
}
Ejemplo n.º 26
0
void InitSnap(Handle<Object> Exports, const TStr& NsNm) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	Handle<Object> NsObj = Object::New(Isolate);

	TNodeJsSnap::Init(NsObj);
	TNodeJsGraph<TUNGraph>::Init(NsObj);
	TNodeJsGraph<TNGraph>::Init(NsObj);
	TNodeJsGraph<TNEGraph>::Init(NsObj);
	TNodeJsNode<TUNGraph>::Init(NsObj);
	TNodeJsNode<TNGraph>::Init(NsObj);
	TNodeJsNode<TNEGraph>::Init(NsObj);
	TNodeJsEdge<TUNGraph>::Init(NsObj);
	TNodeJsEdge<TNGraph>::Init(NsObj);
	TNodeJsEdge<TNEGraph>::Init(NsObj);

	Exports->Set(String::NewFromUtf8(Isolate, NsNm.CStr()), NsObj);
}
Ejemplo n.º 27
0
// <last_name>_<first name innitial>
TStr TStrUtil::GetStdName(TStr AuthorName) {
  TStr StdName;
  AuthorName.ToLc();
  AuthorName.ChangeChAll('\n', ' ');
  AuthorName.ChangeChAll('.', ' ');
  // if there is a number in the name, remove it and everything after it
  int i, pos = 0;
  while (pos<AuthorName.Len() && (AuthorName[pos]!='#' && !TCh::IsNum(AuthorName[pos]))) {
    pos++; }
  if (pos < AuthorName.Len()) {
    AuthorName = AuthorName.GetSubStr(0, pos-1).ToTrunc(); }
  if (AuthorName.Empty()) { return TStr::GetNullStr(); }

  // replace everything after '('
  int b = AuthorName.SearchCh('(');
  if (b != -1) {
    AuthorName = AuthorName.GetSubStr(0, b-1).ToTrunc(); }
  // skip if contains ')'
  if (AuthorName .SearchCh(')')!=-1) { return TStr::GetNullStr(); }
  // skip if it is not a name
  if (AuthorName .SearchStr("figures")!=-1 || AuthorName .SearchStr("macros")!=-1
   || AuthorName .SearchStr("univ")!=-1 || AuthorName .SearchStr("institute")!=-1) {
    return TStr::GetNullStr();
  }
  // remove all non-letters (latex tags, ...)
  TChA NewName;
  for (i = 0; i < AuthorName.Len(); i++) {
    const char Ch = AuthorName[i];
    if (TCh::IsAlpha(Ch) || TCh::IsWs(Ch) || Ch=='-') { NewName += Ch; }
  }
  StdName = NewName;  StdName.ToTrunc();
  TStrV AuthNmV; StdName.SplitOnWs(AuthNmV);
  // too short -- not a name
  if (! AuthNmV.Empty() && AuthNmV.Last() == "jr") AuthNmV.DelLast();
  if (AuthNmV.Len() < 2) return TStr::GetNullStr();

  const TStr LastNm = AuthNmV.Last();
  if (! TCh::IsAlpha(LastNm[0]) || LastNm.Len() == 1) return TStr::GetNullStr();

  IAssert(isalpha(AuthNmV[0][0]));
  return TStr::Fmt("%s_%c", LastNm.CStr(), AuthNmV[0][0]);
}
Ejemplo n.º 28
0
int ParseArgument(const TStr& arg, const TStr& argType, PyObject** argPy)
{
	if (argType == "int")
	{
		*argPy = PyLong_FromLong(arg.GetInt());
	}
	else if (argType == "double")
	{
		*argPy = PyFloat_FromDouble(arg.GetFlt());
	}
	else if (argType == "string")
	{
		*argPy = PyUnicode_FromString(arg.CStr());
	}
	if (!*argPy) {
        fprintf(stderr, "Cannot convert argument\n");
        return 0;
    }
	return 1;
}
Ejemplo n.º 29
0
void InitAnalytics(Handle<Object> Exports, const TStr& NsNm) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	Handle<Object> NsObj = Object::New(Isolate);

	// QMiner package
	TNodeJsSVC::Init(NsObj);
	TNodeJsSVR::Init(NsObj);
    TNodeJsRidgeReg::Init(NsObj);
    TNodeJsSigmoid::Init(NsObj);
	TNodeJsRecLinReg::Init(NsObj);
	TNodeJsLogReg::Init(NsObj);
	TNodeJsPropHaz::Init(NsObj);
	TNodeJsStreamStory::Init(NsObj);
	TNodeJsNNet::Init(NsObj);
	TNodeJsTokenizer::Init(NsObj);

	Exports->Set(String::NewFromUtf8(Isolate, NsNm.CStr()), NsObj);
}
int main(int argc, char *argv[]) {
  LogOutput Log;
  Log.SetupNewOutputDirectory(OUTPUT_DIRECTORY);

  THash<TStr, TStr> Arguments;
  ArgumentParser::ParseArguments(argc, argv, Arguments, Log);
  // default: compare partitioning methods
  bool CompareEdgeScores = Arguments.IsKey("edgescore");

  if (CompareEdgeScores) {
    fprintf(stderr, "Comparing edge scores!\n");
  }

  // Load saved QB, DB, and graph (before edges are deleted) from file
  TFIn SavedQBDBG(SAVED_QBDBGRAPH_FILE);
  TQuoteBase QB;
  TDocBase DB;
  PNGraph QGraph;
  fprintf(stderr, "Loading QB\n");
  QB.Load(SavedQBDBG);
  fprintf(stderr, "Loading DB\n");
  DB.Load(SavedQBDBG);
  fprintf(stderr, "Loading Graph\n");
  QGraph = TNGraph::Load(SavedQBDBG);


  if (!CompareEdgeScores) {
    fprintf(stderr, "Calculating and logging percent edges deleted for different partitioning methods\n");
    TEdgesDel::ComparePartitioningMethods(&QB, &DB, QGraph, Log);
  } else {
    fprintf(stderr, "Calculating and logging percent edges deleted for different edge scores\n");
    TEdgesDel::CompareEdgeScores(&QB, &DB, QGraph, Log);
  }

  TSecTm EndDate(END_DATE);
  Log.WriteClusteringStatisticsToFile(EndDate);

  TStr Directory;
  Log.GetDirectory(Directory);
  Err("Done with analyzing percent edges deleted! Directory created at: %s\n", Directory.CStr());
}