Code Documentation 3.1
Social Network Visualizer
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1
17#ifndef PARSER_H
18#define PARSER_H
19
20#include <QThread>
21#include <QHash>
22#include <QStringList>
23#include <QPointF>
24#include <QObject>
25#include <QMultiMap>
26#include <QDebug>
27
28class QXmlStreamReader;
29class QXmlStreamAttributes;
30
31
32
37struct Actor {
38 QString key;
39 int value;
40};
41
42
49 public:
50 bool operator()(Actor& t1, Actor& t2)
51 {
52 if (t1.value== t2.value)
53 return t1.key > t2.key ;
54// qDebug () << t1.value << " > " << t2.value << "?"
55// << ( t1.value > t2.value ) ;
56 return t1.value > t2.value; //minimum priority
57 // Returns true if t2.value smaller than t1.value
58 }
59};
60
61
68class Parser : public QObject {
69 Q_OBJECT
70public:
71
72 Parser();
73 ~Parser();
74 void load(const QString &fileName, const QString &codecName, const int &defNodeSize,
75 const QString &defNodeColor, const QString &defNodeShape, const QString &defNodeNumberColor,
76 const int &defNodeNumberSize, const QString &defNodeLabelColor, const int &defNodeLabelSize ,
77 const QString &defEdgeColor, const int &canvasWidth, const int &canvasHeight, const int &format,
78 const QString &delim=QString(), const int &sm_mode=1, const bool &sm_has_labels=false);
79
80 bool parseAsPajek(const QByteArray &rawData);
81 bool parseAsAdjacency(const QByteArray &rawData, const QString &delimiter=",", const bool &sm_has_labels=false);
82 bool parseAsDot(const QByteArray &rawData);
83 bool parseAsGraphML(const QByteArray &rawData);
84 bool parseAsGML(const QByteArray &rawData);
85 bool parseAsDL(const QByteArray &rawData);
86 bool parseAsEdgeListSimple(const QByteArray &rawData, const QString &delimiter);
87 bool parseAsEdgeListWeighted(const QByteArray &rawData, const QString &delimiter);
88 bool parseAsTwoModeSociomatrix(const QByteArray &rawData);
89
90 bool readDLKeywords(QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format);
91
92 void readDotProperties(QString str, qreal &, QString &label,
93 QString &shape, QString &color, QString &fontName,
94 QString &fontColor );
95
96 bool readGraphML(QXmlStreamReader &);
97 void readGraphMLElementGraph(QXmlStreamReader &);
98 void readGraphMLElementNode (QXmlStreamReader &);
99 void endGraphMLElementNode (QXmlStreamReader &);
100 void readGraphMLElementEdge (QXmlStreamAttributes &);
101 void endGraphMLElementEdge (QXmlStreamReader &);
102 void readGraphMLElementData (QXmlStreamReader &);
103 void readGraphMLElementUnknown (QXmlStreamReader &);
104 void readGraphMLElementKey (QXmlStreamAttributes &);
105 void readGraphMLElementDefaultValue(QXmlStreamReader &);
106 void readGraphMLElementNodeGraphics (QXmlStreamReader &);
107 void readGraphMLElementEdgeGraphics (QXmlStreamReader &);
109
110 bool isComment(QString str);
111 void createRandomNodes(const int &fixedNum=1,const QString &label=QString(),
112 const int &newNodes=1);
113
114
115signals:
116
117 void signalAddNewRelation( const QString & relName, const bool &changeRelation=false);
118 void signalSetRelation(int, const bool &updateUI=true);
119 void signalCreateNode( const int &num,
120 const int &size,
121 const QString &color,
122 const QString &numColor,
123 const int &numSize,
124 const QString &label,
125 const QString &lColor,
126 const int &lSize,
127 const QPointF &p,
128 const QString &shape,
129 const QString &iconPath=QString(),
130 const bool &signalMW=false);
131 void signalCreateNodeAtPosRandom(const bool &signalMW=false);
133 const QString &label,
134 const bool &signalMW=false
135 );
136
137 void signalCreateEdge (const int &source, const int &target, const qreal &weight,
138 const QString &color, const int &edgeDirType,
139 const bool &arrows, const bool &bezier,
140 const QString &edgeLabel=QString(),
141 const bool &signalMW=false);
142 void signalFileLoaded(const int &fileType,
143 const QString &fileName,
144 const QString &netName,
145 const int &totalNodes,
146 const int &totalLinks,
147 const int &edgeDirType,
148 const qint64 &elapsedTime,
149 const QString &message=QString());
150
151
152 void removeDummyNode (int);
153 void finished(QString);
154
155protected:
156
157private:
158
159 bool validateAndInitialize(const QByteArray &rawData, const QString &delimiter, const bool &sm_has_labels, QStringList &nodeLabels);
160 void resetCounters();
161 bool doParseAdjacency(QTextStream &ts, const QString &delimiter, const QStringList &nodeLabels);
162 void createNodeWithDefaults(int nodeIndex, const QString &label);
163 bool createEdgesForRow(const QStringList &currentRow, int rowIndex);
164 bool containsReservedKeywords(const QString &str) const;
165
166 QHash<QString, int> nodeHash;
167 QHash<QString, QString> keyFor, keyName, keyType, keyDefaultValue ;
168 QHash<QString, QString> edgesMissingNodesHash;
171 QXmlStreamReader *xml;
172 QString fileDirPath;
174 QString networkName;
195 double randX, randY;
196};
197
198
199#endif
The CompareActors class Implements a min-priority queue Used while parsing weighted edge lists.
Definition parser.h:48
bool operator()(Actor &t1, Actor &t2)
Definition parser.h:50
Defines a class for network file loading and parsing.
Definition parser.h:68
void removeDummyNode(int)
QString initNodeCustomIcon
Definition parser.h:175
void readGraphMLElementNodeGraphics(QXmlStreamReader &)
Reads node graphics data and properties: label, color, shape, size, coordinates, etc.
Definition parser.cpp:2740
int totalNodes
Definition parser.h:185
bool parseAsAdjacency(const QByteArray &rawData, const QString &delimiter=",", const bool &sm_has_labels=false)
Definition parser.cpp:1625
bool missingNode
Definition parser.h:190
QString initEdgeLabel
Definition parser.h:177
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:277
qreal bez_p1_y
Definition parser.h:189
void signalCreateNodeAtPosRandomWithLabel(const int &num, const QString &label, const bool &signalMW=false)
QHash< QString, QString > edgesMissingNodesHash
Definition parser.h:168
QString initNodeNumberColor
Definition parser.h:176
Parser()
Definition parser.cpp:39
int nodeSize
Definition parser.h:187
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:167
QString networkName
Definition parser.h:174
bool parseAsTwoModeSociomatrix(const QByteArray &rawData)
Parses the data as two-mode sociomatrix formatted network.
Definition parser.cpp:1896
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 containsReservedKeywords(const QString &str) const
Definition parser.cpp:1875
bool createEdgesForRow(const QStringList &currentRow, int rowIndex)
Definition parser.cpp:1837
bool fileLoaded
Definition parser.h:190
qreal edgeWeight
Definition parser.h:188
bool fileContainsLinkLabels
Definition parser.h:194
int initNodeNumberSize
Definition parser.h:186
QString initNodeShape
Definition parser.h:175
void readGraphMLElementNode(QXmlStreamReader &)
Reads basic node attributes and sets the nodeNumber.
Definition parser.cpp:2397
QString key_type
Definition parser.h:182
bool parseAsDL(const QByteArray &rawData)
Parses the data as DL-formatted (UCINET)
Definition parser.cpp:301
int gwHeight
Definition parser.h:184
bool bezier
Definition parser.h:191
void finished(QString)
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 QString &delim=QString(), const int &sm_mode=1, const bool &sm_has_labels=false)
Loads the data of the given network file, and calls the relevant method to parse it.
Definition parser.cpp:90
QString edge_weight
Definition parser.h:183
~Parser()
Definition parser.cpp:46
bool parseAsGML(const QByteArray &rawData)
Parses the data as GML formatted network.
Definition parser.cpp:2985
QString initNodeColor
Definition parser.h:175
QMultiMap< int, int > firstModeMultiMap
Definition parser.h:170
int gwWidth
Definition parser.h:184
qreal bez_p1_x
Definition parser.h:189
int fileFormat
Definition parser.h:185
bool parseAsEdgeListWeighted(const QByteArray &rawData, const QString &delimiter)
Parses the data as weighted edgelist formatted network.
Definition parser.cpp:3849
double randY
Definition parser.h:195
bool readDLKeywords(QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format)
Definition parser.cpp:922
qreal initEdgeWeight
Definition parser.h:188
QString initEdgeColor
Definition parser.h:177
void readGraphMLElementGraph(QXmlStreamReader &)
Reads a graph definition.
Definition parser.cpp:2249
QString key_name
Definition parser.h:182
void createMissingNodeEdges()
Creates any missing node edges.
Definition parser.cpp:2926
bool validateAndInitialize(const QByteArray &rawData, const QString &delimiter, const bool &sm_has_labels, QStringList &nodeLabels)
Definition parser.cpp:1670
bool fileContainsNodeCoords
Definition parser.h:193
QMultiMap< int, int > secondModeMultiMap
Definition parser.h:170
QHash< QString, int > nodeHash
Definition parser.h:166
int edgeDirType
Definition parser.h:185
QHash< QString, QString > keyDefaultValue
Definition parser.h:167
QString edge_source
Definition parser.h:183
void readGraphMLElementDefaultValue(QXmlStreamReader &)
Reads default key values.
Definition parser.cpp:2328
QString fileDirPath
Definition parser.h:172
QString errorMessage
Definition parser.h:178
QString nodeIconPath
Definition parser.h:180
QString key_value
Definition parser.h:182
QString edgeLabel
Definition parser.h:179
int target
Definition parser.h:187
void createNodeWithDefaults(int nodeIndex, const QString &label)
Definition parser.cpp:1819
int initNodeLabelSize
Definition parser.h:186
QString node_id
Definition parser.h:183
QString nodeNumberColor
Definition parser.h:181
int source
Definition parser.h:187
bool conv_OK
Definition parser.h:191
int totalLinks
Definition parser.h:185
QString edgeColor
Definition parser.h:179
QXmlStreamReader * xml
Definition parser.h:171
qreal arrowSize
Definition parser.h:188
QString edge_id
Definition parser.h:183
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:177
void endGraphMLElementNode(QXmlStreamReader &)
Signals to create a new node.
Definition parser.cpp:2435
bool bool_key
Definition parser.h:192
QString key_what
Definition parser.h:182
void signalAddNewRelation(const QString &relName, const bool &changeRelation=false)
bool fileContainsNodeColors
Definition parser.h:192
qreal bez_p2_y
Definition parser.h:189
void readGraphMLElementEdgeGraphics(QXmlStreamReader &)
Reads edge graphics data and properties: path, linestyle,width, arrows, etc.
Definition parser.cpp:2817
bool readGraphML(QXmlStreamReader &)
Checks the xml token name and calls the appropriate function.
Definition parser.cpp:2151
QStringList edgeMissingNodesList
Definition parser.h:169
int nodeLabelSize
Definition parser.h:187
void readGraphMLElementData(QXmlStreamReader &)
Reads data for edges and nodes.
Definition parser.cpp:2585
QString m_textCodecName
Definition parser.h:173
bool doParseAdjacency(QTextStream &ts, const QString &delimiter, const QStringList &nodeLabels)
Definition parser.cpp:1757
QString edge_directed
Definition parser.h:183
int nodeNumberSize
Definition parser.h:186
QString initNodeLabelColor
Definition parser.h:176
void signalSetRelation(int, const bool &updateUI=true)
int two_sm_mode
Definition parser.h:185
bool parseAsEdgeListSimple(const QByteArray &rawData, const QString &delimiter)
Parses the data as simple edgelist formatted.
Definition parser.cpp:4157
QString nodeLabel
Definition parser.h:179
void readGraphMLElementEdge(QXmlStreamAttributes &)
Reads basic edge creation properties.
Definition parser.cpp:2491
bool bool_node
Definition parser.h:192
bool fileContainsLinkColors
Definition parser.h:193
bool parseAsDot(const QByteArray &rawData)
Parses the data as dot (Graphviz) formatted network.
Definition parser.cpp:3306
bool isComment(QString str)
Helper. Checks if the string parameter is a comment (starts with a known char, i.e #).
Definition parser.cpp:4460
QString key_id
Definition parser.h:182
void readGraphMLElementUnknown(QXmlStreamReader &)
Trivial call for unknown elements.
Definition parser.cpp:2916
QStringList edgeMissingNodesListData
Definition parser.h:169
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:3719
bool bool_edge
Definition parser.h:192
QHash< QString, QString > keyType
Definition parser.h:167
QString nodeLabelColor
Definition parser.h:181
bool arrows
Definition parser.h:191
qreal bez_p2_x
Definition parser.h:189
QString edgeType
Definition parser.h:179
int initNodeSize
Definition parser.h:186
void resetCounters()
Definition parser.cpp:1739
bool parseAsGraphML(const QByteArray &rawData)
Parses the data as GraphML (not GML) formatted network.
Definition parser.cpp:2009
void readGraphMLElementKey(QXmlStreamAttributes &)
Reads a key definition.
Definition parser.cpp:2293
bool parseAsPajek(const QByteArray &rawData)
Parses the data as Pajek-formatted.
Definition parser.cpp:1038
QHash< QString, QString > keyFor
Definition parser.h:167
QStringList relationsList
Definition parser.h:169
void endGraphMLElementEdge(QXmlStreamReader &)
Signals for a new edge to be created/added.
Definition parser.cpp:2562
double randX
Definition parser.h:195
QString nodeShape
Definition parser.h:179
QString nodeColor
Definition parser.h:179
QString edge_target
Definition parser.h:183
The Actor struct Used while parsing edge lists.
Definition parser.h:37
QString key
Definition parser.h:38
int value
Definition parser.h:39