8 for (
int i = 1; i < Ss.
GetFlds(); i++) {
22 IntAttrEVals.
AddDat(AttrName, i-1);
24 FltAttrEVals.
AddDat(AttrName, i-1);
26 StrAttrEVals.
AddDat(AttrName, i-1);
41 if (Ss.
GetFlds() == 0)
continue;
45 if (Ss.
GetFld(0)[0] ==
'#') {
continue; }
46 if (! Ss.
GetInt(SrcColId, SrcNId) || ! Ss.
GetInt(DstColId, DstNId)) {
continue; }
47 if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
48 if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
49 int EId = Graph->AddEdge(SrcNId, DstNId);
52 if (Ss.
GetFlt(it.GetDat(), FltAttrVal)) {
53 Graph->AddFltAttrDatE(EId, FltAttrVal, it.GetKey());
58 if (Ss.
GetInt(it.GetDat(), IntAttrVal)) {
59 Graph->AddIntAttrDatE(EId, IntAttrVal, it.GetKey());
64 StrAttrVal = Ss.
GetFld(it.GetDat());
66 Graph->AddStrAttrDatE(EId,
TStr(StrAttrVal), it.GetKey());
79 for (
int i = 1; i < Ss.
GetFlds(); i++) {
89 IntAttrNVals.
AddDat(AttrName, i-1);
91 FltAttrNVals.
AddDat(AttrName, i-1);
93 StrAttrNVals.
AddDat(AttrName, i-1);
108 if (Ss.
GetFlds() == 0)
continue;
112 if (Ss.
GetFld(0)[0] ==
'#') {
continue; }
113 if (! Ss.
GetInt(NColId, NId)) {
continue; }
114 if (! Graph->IsNode(NId)) { Graph->AddNode(NId); }
117 if (Ss.
GetFlt(it.GetDat(), FltAttrVal)) {
118 Graph->AddFltAttrDatN(NId, FltAttrVal, it.GetKey());
123 if (Ss.
GetInt(it.GetDat(), IntAttrVal)) {
124 Graph->AddIntAttrDatN(NId, IntAttrVal, it.GetKey());
129 StrAttrVal = Ss.
GetFld(it.GetDat());
131 Graph->AddStrAttrDatN(NId,
TStr(StrAttrVal), it.GetKey());
140 TSsParser Ss(InFNm, Separator,
true,
false,
false);
141 bool isSchemaLine =
false;
143 while (isSchemaLine || Ss.
Next()) {
144 isSchemaLine =
false;
145 if (Ss.
GetFlds() == 0)
continue;
153 isSchemaLine =
ReadNodesFromFile(Ss, Separator, Graph, NColId, IntAttrNVals, FltAttrNVals, StrAttrNVals);
162 isSchemaLine =
ReadEdgesFromFile(Ss, Separator, Graph, SrcColId, DstColId, IntAttrEVals, FltAttrEVals, StrAttrEVals);
173 for(
int i = 0; i < IntAttrNNames.
Len(); i++) {
176 for(
int i = 0; i < FltAttrNNames.
Len(); i++) {
179 for(
int i = 0; i < StrAttrNNames.
Len(); i++) {
190 fprintf(F,
"%d", NI.GetId());
191 for(
int i = 0; i < IntAttrNNames.
Len(); i++) {
192 if (Graph->IsIntAttrDeletedN(NI.GetId(), IntAttrNNames[i])) {
196 int AttrIntVal = Graph->GetIntAttrDatN(NI.GetId(), IntAttrNNames[i]);
197 fprintf(F,
"\t%d", AttrIntVal);
199 for(
int i = 0; i < FltAttrNNames.
Len(); i++) {
200 if (Graph->IsFltAttrDeletedN(NI.GetId(), FltAttrNNames[i])) {
204 double AttrFltVal = Graph->GetFltAttrDatN(NI.GetId(), FltAttrNNames[i]);
205 fprintf(F,
"\t%f", AttrFltVal);
207 for(
int i = 0; i < StrAttrNNames.
Len(); i++) {
208 if (Graph->IsStrAttrDeletedN(NI.GetId(), StrAttrNNames[i])) {
212 char * AttrStrVal = Graph->GetStrAttrDatN(NI.GetId(), StrAttrNNames[i]).CStr();
213 fprintf(F,
"\t%s", AttrStrVal);
223 for(
int i = 0; i < IntAttrENames.
Len(); i++) {
226 for(
int i = 0; i < FltAttrENames.
Len(); i++) {
229 for(
int i = 0; i < StrAttrENames.
Len(); i++) {
240 fprintf(F,
"%d\t%d", EI.GetSrcNId(), EI.GetDstNId());
241 for(
int i = 0; i < IntAttrENames.
Len(); i++) {
242 if (Graph->IsIntAttrDeletedE(EI.GetId(), IntAttrENames[i])) {
246 int AttrIntVal = Graph->GetIntAttrDatE(EI.GetId(), IntAttrENames[i]);
247 fprintf(F,
"\t%d", AttrIntVal);
249 for(
int i = 0; i < FltAttrENames.
Len(); i++) {
250 if (Graph->IsFltAttrDeletedE(EI.GetId(), FltAttrENames[i])) {
254 double AttrFltVal = Graph->GetFltAttrDatE(EI.GetId(), FltAttrENames[i]);
255 fprintf(F,
"\t%f", AttrFltVal);
257 for(
int i = 0; i < StrAttrENames.
Len(); i++) {
258 if (Graph->IsStrAttrDeletedE(EI.GetId(), StrAttrENames[i])) {
262 char * AttrStrVal = Graph->GetStrAttrDatE(EI.GetId(), StrAttrENames[i]).CStr();
263 fprintf(F,
"\t%s", AttrStrVal);
270 FILE *F = fopen(OutFNm.
CStr(),
"wt");
271 fprintf(F,
"# Directed network: %s \n", OutFNm.
CStr());
272 if (! Desc.
Empty()) { fprintf(F,
"# %s\n", Desc.
CStr()); }
273 fprintf(F,
"# Nodes: %d Edges: %d\n", Graph->GetNodes(), Graph->GetEdges());
278 Graph->GetAttrNNames(IntAttrNNames, FltAttrNNames, StrAttrNNames);
286 Graph->GetAttrENames(IntAttrENames, FltAttrENames, StrAttrENames);
303 while (XmlLx.
TagNm==
"link") {
304 TStr Str1, Val1, Str2, Val2;
305 XmlLx.
GetArg(0, Str1, Val1); XmlLx.
GetArg(1, Str2, Val2);
306 IAssert(Str1==
"source" && Str2==
"target");
308 const int src=NIdStr.
GetKeyId(Val1);
309 const int dst=NIdStr.
GetKeyId(Val2);
331 while (XmlLx.
TagNm==
"link") {
332 TStr Str1, Val1, Str2, Val2;
333 XmlLx.
GetArg(0, Str1, Val1); XmlLx.
GetArg(1, Str2, Val2);
334 IAssert(Str1==
"source" && Str2==
"target");
336 const int src=NIdStr.
GetKeyId(Val1);
337 const int dst=NIdStr.
GetKeyId(Val2);
void GetArg(const int &ArgN, TStr &ArgNm, TStr &ArgVal) const
void SaveEdgeListNet(const PNEANet &Graph, const TStr &OutFNm, const TStr &Desc)
Saves a network into a text file. Each line encodes either an edge or a node, along with its attribut...
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
int GetKeyId(const TKey &Key) const
const TStr STR_TYPE_PREFIX
int ReadNodeSchemaFromFile(TSsParser &Ss, const char &Separator, int &NId, TStrIntH &IntAttrNVals, TStrIntH &FltAttrNVals, TStrIntH &StrAttrNVals)
static bool IsZipFNm(const TStr &FNm)
Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
TSizeTy Len() const
Returns the number of elements in the vector.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
bool GetInt(const int &FldN, int &Val) const
If the field FldN is an integer its value is returned in Val and the function returns true...
Node iterator. Only forward iteration (operator++) is supported.
int GetFlds() const
Returns the number of fields in the current line.
bool ReadNodesFromFile(TSsParser &Ss, const char &Separator, PNEANet &Graph, int &NColId, TStrIntH &IntAttrNVals, TStrIntH &FltAttrNVals, TStrIntH &StrAttrNVals)
int ReadEdgeSchemaFromFile(TSsParser &Ss, const char &Separator, int &SrcColId, int &DstColId, TStrIntH &IntAttrEVals, TStrIntH &FltAttrEVals, TStrIntH &StrAttrEVals)
static PSIn New(const TStr &FNm)
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
TVec< PNGraph > LoadDyNetGraphV(const TStr &FNm)
For more info see ORA Network Analysis Data (http://www.casos.cs.cmu.edu/computational_tools/data2.php)
void SplitOnCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
const TStr FLT_TYPE_PREFIX
static PSIn New(const TStr &FNm)
PNEANet LoadEdgeListNet(const TStr &InFNm, const char &Separator)
Loads a network from the text file InFNm with 1 node/edge per line ('Separator' separated columns...
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
void WriteEdgesToFile(FILE *F, const PNEANet &Graph, TStrV &IntAttrENames, TStrV &FltAttrENames, TStrV &StrAttrENames)
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TPt< TNGraph > PNGraph
Pointer to a directed graph (TNGraph)
int AddKey(const TKey &Key)
bool GetFlt(const int &FldN, double &Val) const
If the field FldN is a float its value is returned in Val and the function returns true...
void WriteEdgeSchemaToFile(FILE *F, TStrV &IntAttrENames, TStrV &FltAttrENames, TStrV &StrAttrENames)
Edge iterator. Only forward iteration (operator++) is supported.
void WriteNodesToFile(FILE *F, const PNEANet &Graph, TStrV &IntAttrNNames, TStrV &FltAttrNNames, TStrV &StrAttrNNames)
bool Next()
Loads next line from the input file.
PNGraph LoadDyNet(const TStr &FNm)
For more info see ORA Network Analysis Data (http://www.casos.cs.cmu.edu/computational_tools/data2.php)
const TStr INT_TYPE_PREFIX
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TDat & AddDat(const TKey &Key)
bool ReadEdgesFromFile(TSsParser &Ss, const char &Separator, PNEANet &Graph, int &SrcColId, int &DstColId, TStrIntH &IntAttrEVals, TStrIntH &FltAttrEVals, TStrIntH &StrAttrEVals)
void WriteNodeSchemaToFile(FILE *F, TStrV &IntAttrNNames, TStrV &FltAttrNNames, TStrV &StrAttrNNames)