parser.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.5
4  Written in Qt
5 
6  parser.h - description
7  -------------------
8  copyright : (C) 2005-2018 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();
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::null);
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);
98 
99  bool loadEdgeListSimple(const QString &delimiter);
100  bool loadEdgeListWeighed(const QString &delimiter);
101  bool loadTwoModeSociomatrix();
102 
103  void readDotProperties(QString str, float &, 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();
120 
121  bool isComment(QString str);
122  void createRandomNodes(const int &fixedNum=1,const QString &label=QString::null,
123  const int &newNodes=1);
124 
125  void loadFileError(const QString &errorMessage);
126 
127 signals:
128  void addRelation( const QString & relName, const bool &changeRelation=false);
129  void relationSet( int );
130  void createNode(
131  const int &num, const int &size, const QString &color,
132  const QString &numColor, const int &numSize,
133  const QString &label, const QString &lColor, const int &lSize,
134  const QPointF &p,
135  const QString &shape, const bool &signalMW=false);
136  void createNodeAtPosRandom(const bool &signalMW=false);
137  void createNodeAtPosRandomWithLabel (const int &num,
138  const QString &label,
139  const bool &signalMW=false
140  );
141 
142  void edgeCreate (const int &source, const int &target, const float &weight,
143  const QString &color, const int &edgeDirType,
144  const bool &arrows, const bool &bezier,
145  const QString &edgeLabel=QString::null,
146  const bool &signalMW=false);
147  void networkFileLoaded(int fileType,
148  QString fileName,
149  QString netName,
150  int totalNodes,
151  int totalLinks,
152  bool edgeDirType,
153  const QString &message=QString::null);
154 
155 
156  void removeDummyNode (int);
157  void finished(QString);
158 
159 protected:
160 
161 private:
162  QHash<QString, int> nodeHash;
163  QHash<QString, QString> keyFor, keyName, keyType, keyDefaultValue ;
164  QHash<QString, QString> edgesMissingNodesHash;
165  QStringList edgeMissingNodesList,edgeMissingNodesListData, relationsList;
166  QMultiMap<int, int> firstModeMultiMap, secondModeMultiMap;
167  QXmlStreamReader *xml;
168  QString fileName, userSelectedCodecName, networkName, initNodeColor;
169  QString initEdgeColor, initNodeShape, initNodeNumberColor, initNodeLabelColor;
170  QString initEdgeLabel, delimiter, errorMessage;
171  QString nodeColor, edgeColor, edgeType, nodeShape, nodeLabel, edgeLabel;
172  QString nodeNumberColor, nodeLabelColor;
173  QString key_id, key_value, key_name, key_what, key_type;
174  QString node_id, edge_id, edge_source, edge_target, edge_weight, edge_directed;
175  int gwWidth, gwHeight;
176  int totalLinks, totalNodes, fileFormat, two_sm_mode, edgeDirType;
177  int initNodeSize, initNodeNumberSize, nodeNumberSize, initNodeLabelSize;
178  int nodeLabelSize, source, target, nodeSize;
179  float initEdgeWeight, edgeWeight, arrowSize;
180  float bez_p1_x,bez_p1_y, bez_p2_x, bez_p2_y;
182  bool arrows, bezier, conv_OK;
183  bool bool_key, bool_node, bool_edge, fileContainsNodeColors;
184  bool fileContainsNodeCoords, fileContainsLinkColors;
186  double randX, randY;
187 };
188 
189 
190 #endif
bool missingNode
Definition: parser.h:181
bool operator()(Actor &t1, Actor &t2)
Definition: parser.h:61
QStringList relationsList
Definition: parser.h:165
QXmlStreamReader * xml
Definition: parser.h:167
QHash< QString, int > nodeHash
Definition: parser.h:162
double randY
Definition: parser.h:186
QString initEdgeLabel
Definition: parser.h:170
QString userSelectedCodecName
Definition: parser.h:168
QString key_what
Definition: parser.h:173
QString nodeShape
Definition: parser.h:171
int gwWidth
Definition: parser.h:175
The CompareActors class Implements a min-priority queue Used in loadEdgeListWeighed.
Definition: parser.h:59
QHash< QString, QString > keyType
Definition: parser.h:163
QString nodeNumberColor
Definition: parser.h:172
float bez_p2_y
Definition: parser.h:180
int nodeNumberSize
Definition: parser.h:177
int value
Definition: parser.h:50
QString key
Definition: parser.h:49
bool conv_OK
Definition: parser.h:182
bool fileContainsLinkLabels
Definition: parser.h:185
bool fileContainsNodeColors
Definition: parser.h:183
QHash< QString, QString > edgesMissingNodesHash
Definition: parser.h:164
QMultiMap< int, int > secondModeMultiMap
Definition: parser.h:166
The Actor struct Used in loadEdgeListWeighed and loadEdgeListSimple.
Definition: parser.h:48
int target
Definition: parser.h:178
int two_sm_mode
Definition: parser.h:176
QString node_id
Definition: parser.h:174
QString initNodeShape
Definition: parser.h:169
bool fileContainsNodeCoords
Definition: parser.h:184
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:179