parser.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.2
4  Written in Qt
5 
6  parser.h - description
7  -------------------
8  copyright : (C) 2005-2017 by Dimitris B. Kalamaras
9  project site : http://socnetv.org
10 
11  ***************************************************************************/
12 
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 *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
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 <http://www.gnu.org/licenses/>. *
26 ********************************************************************************/
27 
28 #ifndef PARSER_H
29 #define PARSER_H
30 
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;
40 
41 
42 
43 
48 struct Actor {
49  QString key;
50  int value;
51 };
52 
53 
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 };
71 
72 
78 class Parser : public QObject {
79  Q_OBJECT
80 public:
81 
82  Parser(const QString fn, const QString codec, const int iNS,
83  const QString iNC, const QString iNSh, const QString iNNC,
84  const int iNNS, const QString iNLC, const int iNLS ,
85  const QString iEC, const int w, const int h, const int format,
86  const int sm_mode,
87  const QString delim=QString::null);
88  ~Parser();
89  void run();
90  bool loadPajek();
91  bool loadAdjacency();
92  bool loadDot();
93  bool loadGraphML();
94  bool loadGML();
95  bool loadGW();
96  bool loadDL();
97  bool loadEdgeListSimple(const QString &delimiter);
98  bool loadEdgeListWeighed(const QString &delimiter);
99  bool loadTwoModeSociomatrix();
100 
101  void readDotProperties(QString str, float &, QString &label,
102  QString &shape, QString &color, QString &fontName,
103  QString &fontColor );
104  bool readGraphML(QXmlStreamReader &);
105  void readGraphMLElementGraph(QXmlStreamReader &);
106  void readGraphMLElementNode (QXmlStreamReader &);
107  void endGraphMLElementNode (QXmlStreamReader &);
108  void readGraphMLElementEdge (QXmlStreamAttributes &);
109  void endGraphMLElementEdge (QXmlStreamReader &);
110  void readGraphMLElementData (QXmlStreamReader &);
111  void readGraphMLElementUnknown (QXmlStreamReader &);
112  void readGraphMLElementKey (QXmlStreamAttributes &);
113  bool xmlStreamHasAttribute( QXmlStreamAttributes &, QString ) const ;
114  void readGraphMLElementDefaultValue(QXmlStreamReader &);
115  void readGraphMLElementNodeGraphics (QXmlStreamReader &);
116  void readGraphMLElementEdgeGraphics (QXmlStreamReader &);
117  void createMissingNodeEdges();
118 
119  bool isComment(QString str);
120  void createRandomNodes(const int &fixedNum=1,const QString &label=QString::null,
121  const int &newNodes=1);
122 
123  void loadFileError(const QString &errorMessage);
124 
125 signals:
126  void addRelation( const QString & relName, const bool &changeRelation=false);
127  void relationSet( int );
128  void createNode(
129  const int &num, const int &size, const QString &color,
130  const QString &numColor, const int &numSize,
131  const QString &label, const QString &lColor, const int &lSize,
132  const QPointF &p,
133  const QString &shape, const bool &signalMW=false);
134  void createNodeAtPosRandom(const bool &signalMW=false);
135  void createNodeAtPosRandomWithLabel (const int &num,
136  const QString &label,
137  const bool &signalMW=false
138  );
139 
140  void edgeCreate (const int &source, const int &target, const float &weight,
141  const QString &color, const int &edgeDirType,
142  const bool &arrows, const bool &bezier,
143  const QString &edgeLabel=QString::null,
144  const bool &signalMW=false);
145  void networkFileLoaded(int fileType,
146  QString fileName,
147  QString netName,
148  int totalNodes,
149  int totalLinks,
150  bool edgeDirType,
151  const QString &message=QString::null);
152 
153 
154  void removeDummyNode (int);
155  void finished(QString);
156 
157 protected:
158 
159 private:
160  QHash<QString, int> nodeHash;
161  QHash<QString, QString> keyFor, keyName, keyType, keyDefaultValue ;
162  QHash<QString, QString> edgesMissingNodesHash;
163  QStringList edgeMissingNodesList,edgeMissingNodesListData, relationsList;
164  QMultiMap<int, int> firstModeMultiMap, secondModeMultiMap;
165  QXmlStreamReader *xml;
166  QString fileName, userSelectedCodecName, networkName, initNodeColor;
167  QString initEdgeColor, initNodeShape, initNodeNumberColor, initNodeLabelColor;
168  QString initEdgeLabel, delimiter, errorMessage;
169  QString nodeColor, edgeColor, edgeType, nodeShape, nodeLabel, edgeLabel;
170  QString nodeNumberColor, nodeLabelColor;
171  QString key_id, key_value, key_name, key_what, key_type;
172  QString node_id, edge_id, edge_source, edge_target, edge_weight, edge_directed;
173  int gwWidth, gwHeight;
174  int totalLinks, totalNodes, fileFormat, two_sm_mode, edgeDirType;
175  int initNodeSize, initNodeNumberSize, nodeNumberSize, initNodeLabelSize;
176  int nodeLabelSize, source, target, nodeSize;
177  float initEdgeWeight, edgeWeight, arrowSize;
178  float bez_p1_x,bez_p1_y, bez_p2_x, bez_p2_y;
180  bool arrows, bezier, conv_OK;
181  bool bool_key, bool_node, bool_edge, fileContainsNodeColors;
182  bool fileContainsNodeCoords, fileContainsLinkColors;
184  double randX, randY;
185 };
186 
187 
188 #endif
bool missingNode
Definition: parser.h:179
bool operator()(Actor &t1, Actor &t2)
Definition: parser.h:61
QStringList relationsList
Definition: parser.h:163
QXmlStreamReader * xml
Definition: parser.h:165
QHash< QString, int > nodeHash
Definition: parser.h:160
double randY
Definition: parser.h:184
QString initEdgeLabel
Definition: parser.h:168
QString userSelectedCodecName
Definition: parser.h:166
QString key_what
Definition: parser.h:171
QString nodeShape
Definition: parser.h:169
int gwWidth
Definition: parser.h:173
The CompareActors class Implements a min-priority queue Used in loadEdgeListWeighed.
Definition: parser.h:59
QHash< QString, QString > keyType
Definition: parser.h:161
QString nodeNumberColor
Definition: parser.h:170
float bez_p2_y
Definition: parser.h:178
int nodeNumberSize
Definition: parser.h:175
int value
Definition: parser.h:50
QString key
Definition: parser.h:49
bool conv_OK
Definition: parser.h:180
bool fileContainsLinkLabels
Definition: parser.h:183
bool fileContainsNodeColors
Definition: parser.h:181
QHash< QString, QString > edgesMissingNodesHash
Definition: parser.h:162
QMultiMap< int, int > secondModeMultiMap
Definition: parser.h:164
The Actor struct Used in loadEdgeListWeighed and loadEdgeListSimple.
Definition: parser.h:48
int target
Definition: parser.h:176
int two_sm_mode
Definition: parser.h:174
QString node_id
Definition: parser.h:172
QString initNodeShape
Definition: parser.h:167
bool fileContainsNodeCoords
Definition: parser.h:182
The Parser class Main class for network file parsing and loading Supports GraphML, Pajek, Adjacency, Graphviz, UCINET, EdgeLists etc.
Definition: parser.h:78
float initEdgeWeight
Definition: parser.h:177