Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 3.1
4  Written in Qt
6  parser.h - description
7  -------------------
8  copyright : (C) 2005-2023 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>
39 class QXmlStreamReader;
40 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 };
79 class Parser : public QObject {
81 public:
83  Parser();
84  ~Parser();
85  void load(const QString &fileName, const QString &codecName, const int &defNodeSize,
86  const QString &defNodeColor, const QString &defNodeShape, const QString &defNodeNumberColor,
87  const int &defNodeNumberSize, const QString &defNodeLabelColor, const int &defNodeLabelSize ,
88  const QString &defEdgeColor, const int &canvasWidth, const int &canvasHeight, const int &format,
89  const int &sm_mode, const QString &delim=QString());
91  bool parseAsPajek(const QByteArray &rawData);
92  bool parseAsAdjacency(const QByteArray &rawData);
93  bool parseAsDot(const QByteArray &rawData);
94  bool parseAsGraphML(const QByteArray &rawData);
95  bool parseAsGML(const QByteArray &rawData);
96  bool parseAsDL(const QByteArray &rawData);
97  bool parseAsEdgeListSimple(const QByteArray &rawData, const QString &delimiter);
98  bool parseAsEdgeListWeighted(const QByteArray &rawData, const QString &delimiter);
99  bool parseAsTwoModeSociomatrix(const QByteArray &rawData);
101  bool readDLKeywords(QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format);
103  void readDotProperties(QString str, qreal &, QString &label,
104  QString &shape, QString &color, QString &fontName,
105  QString &fontColor );
107  bool readGraphML(QXmlStreamReader &);
108  void readGraphMLElementGraph(QXmlStreamReader &);
109  void readGraphMLElementNode (QXmlStreamReader &);
110  void endGraphMLElementNode (QXmlStreamReader &);
111  void readGraphMLElementEdge (QXmlStreamAttributes &);
112  void endGraphMLElementEdge (QXmlStreamReader &);
113  void readGraphMLElementData (QXmlStreamReader &);
114  void readGraphMLElementUnknown (QXmlStreamReader &);
115  void readGraphMLElementKey (QXmlStreamAttributes &);
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);
126 signals:
128  void signalAddNewRelation( const QString & relName, const bool &changeRelation=false);
129  void signalSetRelation(int, const bool &updateUI=true);
130  void signalCreateNode( const int &num,
131  const int &size,
132  const QString &color,
133  const QString &numColor,
134  const int &numSize,
135  const QString &label,
136  const QString &lColor,
137  const int &lSize,
138  const QPointF &p,
139  const QString &shape,
140  const QString &iconPath=QString(),
141  const bool &signalMW=false);
142  void signalCreateNodeAtPosRandom(const bool &signalMW=false);
144  const QString &label,
145  const bool &signalMW=false
146  );
148  void signalCreateEdge (const int &source, const int &target, const qreal &weight,
149  const QString &color, const int &edgeDirType,
150  const bool &arrows, const bool &bezier,
151  const QString &edgeLabel=QString(),
152  const bool &signalMW=false);
153  void signalFileLoaded(const int &fileType,
154  const QString &fileName,
155  const QString &netName,
156  const int &totalNodes,
157  const int &totalLinks,
158  const int &edgeDirType,
159  const qint64 &elapsedTime,
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 fileDirPath;
177  QString networkName;
181  QString errorMessage;
183  QString nodeIconPath;
198  double randX, randY;
199 };
202 #endif
The CompareActors class Implements a min-priority queue Used while parsing weighted edge lists.
Definition: parser.h:59
bool operator()(Actor &t1, Actor &t2)
Definition: parser.h:61
Defines a class for network file loading and parsing.
Definition: parser.h:79
void removeDummyNode(int)
QString initNodeCustomIcon
Definition: parser.h:178
void readGraphMLElementNodeGraphics(QXmlStreamReader &)
Reads node graphics data and properties: label, color, shape, size, coordinates, etc.
Definition: parser.cpp:2689
int totalNodes
Definition: parser.h:188
bool missingNode
Definition: parser.h:193
QString initEdgeLabel
Definition: parser.h:180
void createRandomNodes(const int &fixedNum=1, const QString &label=QString(), const int &newNodes=1)
Signals to create either a single new node (numbered fixedNum) or multiple new nodes (numbered from 1...
Definition: parser.cpp:285
qreal bez_p1_y
Definition: parser.h:192
void signalCreateNodeAtPosRandomWithLabel(const int &num, const QString &label, const bool &signalMW=false)
QHash< QString, QString > edgesMissingNodesHash
Definition: parser.h:171
QString initNodeNumberColor
Definition: parser.h:179
Definition: parser.cpp:49
int nodeSize
Definition: parser.h:190
void signalCreateNode(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)
QHash< QString, QString > keyName
Definition: parser.h:170
QString networkName
Definition: parser.h:177
bool parseAsTwoModeSociomatrix(const QByteArray &rawData)
Parses the data as two-mode sociomatrix formatted network.
Definition: parser.cpp:1845
void signalCreateEdge(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)
void signalCreateNodeAtPosRandom(const bool &signalMW=false)
bool fileLoaded
Definition: parser.h:193
qreal edgeWeight
Definition: parser.h:191
bool fileContainsLinkLabels
Definition: parser.h:197
int initNodeNumberSize
Definition: parser.h:189
QString initNodeShape
Definition: parser.h:178
void readGraphMLElementNode(QXmlStreamReader &)
Reads basic node attributes and sets the nodeNumber.
Definition: parser.cpp:2346
QString key_type
Definition: parser.h:185
bool parseAsDL(const QByteArray &rawData)
Parses the data as DL-formatted (UCINET)
Definition: parser.cpp:309
int gwHeight
Definition: parser.h:187
bool bezier
Definition: parser.h:194
void finished(QString)
QString edge_weight
Definition: parser.h:186
Definition: parser.cpp:56
bool parseAsGML(const QByteArray &rawData)
Parses the data as GML formatted network.
Definition: parser.cpp:2934
QString initNodeColor
Definition: parser.h:178
QMultiMap< int, int > firstModeMultiMap
Definition: parser.h:173
int gwWidth
Definition: parser.h:187
qreal bez_p1_x
Definition: parser.h:192
int fileFormat
Definition: parser.h:188
bool parseAsEdgeListWeighted(const QByteArray &rawData, const QString &delimiter)
Parses the data as weighted edgelist formatted network.
Definition: parser.cpp:3798
double randY
Definition: parser.h:198
bool readDLKeywords(QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format)
Definition: parser.cpp:930
qreal initEdgeWeight
Definition: parser.h:191
QString initEdgeColor
Definition: parser.h:180
void readGraphMLElementGraph(QXmlStreamReader &)
Reads a graph definition.
Definition: parser.cpp:2198
QString key_name
Definition: parser.h:185
void createMissingNodeEdges()
Creates any missing node edges.
Definition: parser.cpp:2875
bool fileContainsNodeCoords
Definition: parser.h:196
QMultiMap< int, int > secondModeMultiMap
Definition: parser.h:173
QHash< QString, int > nodeHash
Definition: parser.h:169
int edgeDirType
Definition: parser.h:188
QHash< QString, QString > keyDefaultValue
Definition: parser.h:170
QString edge_source
Definition: parser.h:186
void readGraphMLElementDefaultValue(QXmlStreamReader &)
Reads default key values.
Definition: parser.cpp:2277
QString fileDirPath
Definition: parser.h:175
QString errorMessage
Definition: parser.h:181
QString nodeIconPath
Definition: parser.h:183
QString key_value
Definition: parser.h:185
QString edgeLabel
Definition: parser.h:182
int target
Definition: parser.h:190
int initNodeLabelSize
Definition: parser.h:189
QString node_id
Definition: parser.h:186
QString nodeNumberColor
Definition: parser.h:184
int source
Definition: parser.h:190
bool conv_OK
Definition: parser.h:194
int totalLinks
Definition: parser.h:188
QString edgeColor
Definition: parser.h:182
QXmlStreamReader * xml
Definition: parser.h:174
qreal arrowSize
Definition: parser.h:191
QString edge_id
Definition: parser.h:186
void signalFileLoaded(const int &fileType, const QString &fileName, const QString &netName, const int &totalNodes, const int &totalLinks, const int &edgeDirType, const qint64 &elapsedTime, const QString &message=QString())
QString delimiter
Definition: parser.h:180
void endGraphMLElementNode(QXmlStreamReader &)
Signals to create a new node.
Definition: parser.cpp:2384
bool bool_key
Definition: parser.h:195
QString key_what
Definition: parser.h:185
void signalAddNewRelation(const QString &relName, const bool &changeRelation=false)
bool fileContainsNodeColors
Definition: parser.h:195
qreal bez_p2_y
Definition: parser.h:192
void readGraphMLElementEdgeGraphics(QXmlStreamReader &)
Reads edge graphics data and properties: path, linestyle,width, arrows, etc.
Definition: parser.cpp:2766
bool readGraphML(QXmlStreamReader &)
Checks the xml token name and calls the appropriate function.
Definition: parser.cpp:2100
QStringList edgeMissingNodesList
Definition: parser.h:172
int nodeLabelSize
Definition: parser.h:190
void readGraphMLElementData(QXmlStreamReader &)
Reads data for edges and nodes.
Definition: parser.cpp:2534
QString m_textCodecName
Definition: parser.h:176
QString edge_directed
Definition: parser.h:186
int nodeNumberSize
Definition: parser.h:189
QString initNodeLabelColor
Definition: parser.h:179
void signalSetRelation(int, const bool &updateUI=true)
int two_sm_mode
Definition: parser.h:188
bool parseAsEdgeListSimple(const QByteArray &rawData, const QString &delimiter)
Parses the data as simple edgelist formatted.
Definition: parser.cpp:4106
QString nodeLabel
Definition: parser.h:182
void readGraphMLElementEdge(QXmlStreamAttributes &)
Reads basic edge creation properties.
Definition: parser.cpp:2440
bool bool_node
Definition: parser.h:195
bool fileContainsLinkColors
Definition: parser.h:196
bool parseAsDot(const QByteArray &rawData)
Parses the data as dot (Graphviz) formatted network.
Definition: parser.cpp:3255
bool isComment(QString str)
Helper. Checks if the string parameter is a comment (starts with a known char, i.e #).
Definition: parser.cpp:4408
QString key_id
Definition: parser.h:185
void readGraphMLElementUnknown(QXmlStreamReader &)
Trivial call for unknown elements.
Definition: parser.cpp:2865
QStringList edgeMissingNodesListData
Definition: parser.h:172
void readDotProperties(QString str, qreal &, QString &label, QString &shape, QString &color, QString &fontName, QString &fontColor)
Reads the properties of a dot element.
Definition: parser.cpp:3668
bool bool_edge
Definition: parser.h:195
QHash< QString, QString > keyType
Definition: parser.h:170
QString nodeLabelColor
Definition: parser.h:184
bool arrows
Definition: parser.h:194
bool parseAsAdjacency(const QByteArray &rawData)
Parses the data as adjacency sociomatrix-formatted.
Definition: parser.cpp:1614
qreal bez_p2_x
Definition: parser.h:192
QString edgeType
Definition: parser.h:182
void load(const QString &fileName, const QString &codecName, const int &defNodeSize, const QString &defNodeColor, const QString &defNodeShape, const QString &defNodeNumberColor, const int &defNodeNumberSize, const QString &defNodeLabelColor, const int &defNodeLabelSize, const QString &defEdgeColor, const int &canvasWidth, const int &canvasHeight, const int &format, const int &sm_mode, const QString &delim=QString())
Loads the data of the given network file, and calls the relevant method to parse it.
Definition: parser.cpp:100
int initNodeSize
Definition: parser.h:189
bool parseAsGraphML(const QByteArray &rawData)
Parses the data as GraphML (not GML) formatted network.
Definition: parser.cpp:1958
void readGraphMLElementKey(QXmlStreamAttributes &)
Reads a key definition.
Definition: parser.cpp:2242
bool parseAsPajek(const QByteArray &rawData)
Parses the data as Pajek-formatted.
Definition: parser.cpp:1046
QHash< QString, QString > keyFor
Definition: parser.h:170
QStringList relationsList
Definition: parser.h:172
void endGraphMLElementEdge(QXmlStreamReader &)
Signals for a new edge to be created/added.
Definition: parser.cpp:2511
double randX
Definition: parser.h:198
QString nodeShape
Definition: parser.h:182
QString nodeColor
Definition: parser.h:182
QString edge_target
Definition: parser.h:186
The Actor struct Used while parsing edge lists.
Definition: parser.h:48
QString key
Definition: parser.h:49
int value
Definition: parser.h:50