Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 3.0.2
4  Written in Qt
6  parser.h - description
7  -------------------
8  copyright : (C) 2005-2021 by Dimitris B. Kalamaras
9  project site :
11  ***************************************************************************/
13 /*******************************************************************************
14 * This program is free software: you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation, either version 3 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program. If not, see <>. *
26 ********************************************************************************/
28 #ifndef PARSER_H
29 #define PARSER_H
31 #include <QThread>
32 #include <QHash>
33 #include <QStringList>
34 #include <QPointF>
35 #include <QObject>
36 #include <QMultiMap>
37 #include <QDebug>
38 class QXmlStreamReader;
39 class QXmlStreamAttributes;
48 struct Actor {
49  QString key;
50  int value;
51 };
60  public:
61  bool operator()(Actor& t1, Actor& t2)
62  {
63  if (t1.value== t2.value)
64  return t1.key > t2.key ;
65 // qDebug () << t1.value << " > " << t2.value << "?"
66 // << ( t1.value > t2.value ) ;
67  return t1.value > t2.value; //minimum priority
68  // Returns true if t2.value smaller than t1.value
69  }
70 };
78 class Parser : public QObject {
80 public:
82  Parser();
83  ~Parser();
84  void load(const QString fn, const QString codec, const int iNS,
85  const QString iNC, const QString iNSh, const QString iNNC,
86  const int iNNS, const QString iNLC, const int iNLS ,
87  const QString iEC, const int w, const int h, const int format,
88  const int sm_mode,
89  const QString delim=QString());
90  bool loadPajek();
91  bool loadAdjacency();
92  bool loadDot();
93  bool loadGraphML();
94  bool loadGML();
95  bool loadGW();
96  bool loadDL();
97  bool readDLKeywords(QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format);
99  bool loadEdgeListSimple(const QString &delimiter);
100  bool loadEdgeListWeighed(const QString &delimiter);
101  bool loadTwoModeSociomatrix();
103  void readDotProperties(QString str, qreal &, QString &label,
104  QString &shape, QString &color, QString &fontName,
105  QString &fontColor );
106  bool readGraphML(QXmlStreamReader &);
107  void readGraphMLElementGraph(QXmlStreamReader &);
108  void readGraphMLElementNode (QXmlStreamReader &);
109  void endGraphMLElementNode (QXmlStreamReader &);
110  void readGraphMLElementEdge (QXmlStreamAttributes &);
111  void endGraphMLElementEdge (QXmlStreamReader &);
112  void readGraphMLElementData (QXmlStreamReader &);
113  void readGraphMLElementUnknown (QXmlStreamReader &);
114  void readGraphMLElementKey (QXmlStreamAttributes &);
115  bool xmlStreamHasAttribute( QXmlStreamAttributes &, QString ) const ;
116  void readGraphMLElementDefaultValue(QXmlStreamReader &);
117  void readGraphMLElementNodeGraphics (QXmlStreamReader &);
118  void readGraphMLElementEdgeGraphics (QXmlStreamReader &);
119  void createMissingNodeEdges();
121  bool isComment(QString str);
122  void createRandomNodes(const int &fixedNum=1,const QString &label=QString(),
123  const int &newNodes=1);
125  void loadFileError(const QString &errorMessage);
127 signals:
129  void addRelation( const QString & relName, const bool &changeRelation=false);
130  void relationSet( int );
131  void createNode( const int &num,
132  const int &size,
133  const QString &color,
134  const QString &numColor,
135  const int &numSize,
136  const QString &label,
137  const QString &lColor,
138  const int &lSize,
139  const QPointF &p,
140  const QString &shape,
141  const QString &iconPath=QString(),
142  const bool &signalMW=false);
143  void createNodeAtPosRandom(const bool &signalMW=false);
144  void createNodeAtPosRandomWithLabel (const int &num,
145  const QString &label,
146  const bool &signalMW=false
147  );
149  void edgeCreate (const int &source, const int &target, const qreal &weight,
150  const QString &color, const int &edgeDirType,
151  const bool &arrows, const bool &bezier,
152  const QString &edgeLabel=QString(),
153  const bool &signalMW=false);
154  void networkFileLoaded(int fileType,
155  QString fileName,
156  QString netName,
157  int totalNodes,
158  int totalLinks,
159  int edgeDirType,
160  const QString &message=QString());
163  void removeDummyNode (int);
164  void finished(QString);
166 protected:
168 private:
169  QHash<QString, int> nodeHash;
170  QHash<QString, QString> keyFor, keyName, keyType, keyDefaultValue ;
171  QHash<QString, QString> edgesMissingNodesHash;
173  QMultiMap<int, int> firstModeMultiMap, secondModeMultiMap;
174  QXmlStreamReader *xml;
175  QString fileName;
176  QString fileDirPath;
178  QString networkName;
182  QString errorMessage;
184  QString nodeIconPath;
199  double randX, randY;
200 };
203 #endif
QXmlStreamReader * xml
Definition: parser.h:174
int nodeNumberSize
Definition: parser.h:190
int totalLinks
Definition: parser.h:189
void readGraphMLElementEdgeGraphics(QXmlStreamReader &)
Definition: parser.cpp:2700
int value
Definition: parser.h:50
QString key_value
Definition: parser.h:186
void loadFileError(const QString &errorMessage)
Definition: parser.cpp:230
QHash< QString, QString > keyName
Definition: parser.h:170
bool fileContainsLinkColors
Definition: parser.h:197
void createNodeAtPosRandomWithLabel(const int &num, const QString &label, const bool &signalMW=false)
int source
Definition: parser.h:191
QString nodeIconPath
Definition: parser.h:184
bool bezier
Definition: parser.h:195
bool operator()(Actor &t1, Actor &t2)
Definition: parser.h:61
QHash< QString, int > nodeHash
Definition: parser.h:169
QString nodeLabelColor
Definition: parser.h:185
QString fileName
Definition: parser.h:175
bool loadAdjacency()
Tries to load the file as adjacency sociomatrix-formatted. If not it returns -1.
Definition: parser.cpp:1551
void createMissingNodeEdges()
Definition: parser.cpp:2813
double randY
Definition: parser.h:199
void removeDummyNode(int)
bool bool_node
Definition: parser.h:196
QString initNodeColor
Definition: parser.h:179
Definition: parser.cpp:56
QString initEdgeColor
Definition: parser.h:181
int nodeLabelSize
Definition: parser.h:191
void endGraphMLElementNode(QXmlStreamReader &)
Definition: parser.cpp:2328
int target
Definition: parser.h:191
void readGraphMLElementDefaultValue(QXmlStreamReader &)
Reads default key values Called at a default element (usually nested inside key element)
Definition: parser.cpp:2220
QString userSelectedCodecName
Definition: parser.h:177
bool isComment(QString str)
Definition: parser.cpp:4328
QStringList edgeMissingNodesList
Definition: parser.h:172
bool loadEdgeListWeighed(const QString &delimiter)
A method to load a weighted edge list formatted file.
Definition: parser.cpp:3718
QString key_name
Definition: parser.h:186
void load(const QString fn, const QString codec, const int iNS, const QString iNC, const QString iNSh, const QString iNNC, const int iNNS, const QString iNLC, const int iNLS, const QString iEC, const int w, const int h, const int format, const int sm_mode, const QString delim=QString())
Loads the network calling one of the load* methods.
Definition: parser.cpp:82
int edgeDirType
Definition: parser.h:189
int gwHeight
Definition: parser.h:188
QString errorMessage
Definition: parser.h:182
bool loadGW()
QString edgeColor
Definition: parser.h:183
QString initNodeShape
Definition: parser.h:179
void edgeCreate(const int &source, const int &target, const qreal &weight, const QString &color, const int &edgeDirType, const bool &arrows, const bool &bezier, const QString &edgeLabel=QString(), const bool &signalMW=false)
int gwWidth
Definition: parser.h:188
QString edge_target
Definition: parser.h:187
void readGraphMLElementKey(QXmlStreamAttributes &)
Definition: parser.cpp:2180
int two_sm_mode
Definition: parser.h:189
bool missingNode
Definition: parser.h:194
QString key_id
Definition: parser.h:186
QString initNodeNumberColor
Definition: parser.h:180
bool conv_OK
Definition: parser.h:195
bool loadEdgeListSimple(const QString &delimiter)
Definition: parser.cpp:4028
bool loadGML()
Definition: parser.cpp:2867
void addRelation(const QString &relName, const bool &changeRelation=false)
qreal edgeWeight
Definition: parser.h:192
qreal bez_p1_y
Definition: parser.h:193
The Actor struct Used in loadEdgeListWeighed and loadEdgeListSimple.
Definition: parser.h:48
QHash< QString, QString > keyDefaultValue
Definition: parser.h:170
double randX
Definition: parser.h:199
bool bool_edge
Definition: parser.h:196
QString fileDirPath
Definition: parser.h:176
QHash< QString, QString > keyFor
Definition: parser.h:170
void readGraphMLElementUnknown(QXmlStreamReader &)
Definition: parser.cpp:2806
void readGraphMLElementData(QXmlStreamReader &)
Reads data for edges and nodes called at a data element (usually nested inside a node or an edge elem...
Definition: parser.cpp:2467
bool bool_key
Definition: parser.h:196
int fileFormat
Definition: parser.h:189
void createRandomNodes(const int &fixedNum=1, const QString &label=QString(), const int &newNodes=1)
Definition: parser.cpp:251
bool loadDot()
Definition: parser.cpp:3186
QString nodeShape
Definition: parser.h:183
qreal arrowSize
Definition: parser.h:192
QString nodeNumberColor
Definition: parser.h:185
int initNodeLabelSize
Definition: parser.h:190
qreal bez_p2_x
Definition: parser.h:193
bool loadPajek()
Definition: parser.cpp:995
QString nodeLabel
Definition: parser.h:183
void networkFileLoaded(int fileType, QString fileName, QString netName, int totalNodes, int totalLinks, int edgeDirType, const QString &message=QString())
int initNodeNumberSize
Definition: parser.h:190
bool fileContainsNodeCoords
Definition: parser.h:197
void endGraphMLElementEdge(QXmlStreamReader &)
Definition: parser.cpp:2446
QString node_id
Definition: parser.h:187
QString delimiter
Definition: parser.h:181
QMultiMap< int, int > secondModeMultiMap
Definition: parser.h:173
Definition: parser.cpp:49
void readDotProperties(QString str, qreal &, QString &label, QString &shape, QString &color, QString &fontName, QString &fontColor)
Definition: parser.cpp:3591
QString initEdgeLabel
Definition: parser.h:181
The Parser class Main class for network file parsing and loading Supports GraphML,...
Definition: parser.h:78
void finished(QString)
void readGraphMLElementNode(QXmlStreamReader &)
Definition: parser.cpp:2295
qreal bez_p2_y
Definition: parser.h:193
QString edgeLabel
Definition: parser.h:183
bool readGraphML(QXmlStreamReader &)
Checks the xml token name and calls the appropriate function. Called from loadGraphML.
Definition: parser.cpp:2028
QString edge_source
Definition: parser.h:187
bool fileContainsLinkLabels
Definition: parser.h:198
QHash< QString, QString > edgesMissingNodesHash
Definition: parser.h:171
QStringList relationsList
Definition: parser.h:172
QString key
Definition: parser.h:49
QString nodeColor
Definition: parser.h:183
bool loadTwoModeSociomatrix()
Definition: parser.cpp:1763
void createNode(const int &num, const int &size, const QString &color, const QString &numColor, const int &numSize, const QString &label, const QString &lColor, const int &lSize, const QPointF &p, const QString &shape, const QString &iconPath=QString(), const bool &signalMW=false)
int totalNodes
Definition: parser.h:189
qreal initEdgeWeight
Definition: parser.h:192
QMultiMap< int, int > firstModeMultiMap
Definition: parser.h:173
QString key_type
Definition: parser.h:186
void readGraphMLElementEdge(QXmlStreamAttributes &)
Definition: parser.cpp:2381
void readGraphMLElementGraph(QXmlStreamReader &)
Reads a graph definition Called at Graph element.
Definition: parser.cpp:2126
bool loadGraphML()
Tries to load a file as GraphML (not GML) formatted network. If not GraphML, it returns false.
Definition: parser.cpp:1879
QString edge_weight
Definition: parser.h:187
void createNodeAtPosRandom(const bool &signalMW=false)
QString edgeType
Definition: parser.h:183
int initNodeSize
Definition: parser.h:190
QString initNodeCustomIcon
Definition: parser.h:179
void readGraphMLElementNodeGraphics(QXmlStreamReader &)
Definition: parser.cpp:2621
bool loadDL()
Definition: parser.cpp:275
bool arrows
Definition: parser.h:195
int nodeSize
Definition: parser.h:191
qreal bez_p1_x
Definition: parser.h:193
QString edge_id
Definition: parser.h:187
void relationSet(int)
QString networkName
Definition: parser.h:178
QString key_what
Definition: parser.h:186
QStringList edgeMissingNodesListData
Definition: parser.h:172
The CompareActors class Implements a min-priority queue Used in loadEdgeListWeighed.
Definition: parser.h:59
bool readDLKeywords(QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format)
Definition: parser.cpp:882
bool xmlStreamHasAttribute(QXmlStreamAttributes &, QString) const
Definition: parser.cpp:2164
QString initNodeLabelColor
Definition: parser.h:180
QHash< QString, QString > keyType
Definition: parser.h:170
bool fileContainsNodeColors
Definition: parser.h:196
QString edge_directed
Definition: parser.h:187