Code Documentation 3.1
Social Network Visualizer
|
Defines a class for network file loading and parsing. More...
#include <parser.h>
Signals | |
void | signalAddNewRelation (const QString &relName, const bool &changeRelation=false) |
void | signalSetRelation (int, const bool &updateUI=true) |
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) |
void | signalCreateNodeAtPosRandom (const bool &signalMW=false) |
void | signalCreateNodeAtPosRandomWithLabel (const int &num, const QString &label, const bool &signalMW=false) |
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 | 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()) |
void | removeDummyNode (int) |
void | finished (QString) |
Public Member Functions | |
Parser () | |
~Parser () | |
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. | |
bool | parseAsPajek (const QByteArray &rawData) |
Parses the data as Pajek-formatted. | |
bool | parseAsAdjacency (const QByteArray &rawData, const QString &delimiter=",", const bool &sm_has_labels=false) |
bool | parseAsDot (const QByteArray &rawData) |
Parses the data as dot (Graphviz) formatted network. | |
bool | parseAsGraphML (const QByteArray &rawData) |
Parses the data as GraphML (not GML) formatted network. | |
bool | parseAsGML (const QByteArray &rawData) |
Parses the data as GML formatted network. | |
bool | parseAsDL (const QByteArray &rawData) |
Parses the data as DL-formatted (UCINET) | |
bool | parseAsEdgeListSimple (const QByteArray &rawData, const QString &delimiter) |
Parses the data as simple edgelist formatted. | |
bool | parseAsEdgeListWeighted (const QByteArray &rawData, const QString &delimiter) |
Parses the data as weighted edgelist formatted network. | |
bool | parseAsTwoModeSociomatrix (const QByteArray &rawData) |
Parses the data as two-mode sociomatrix formatted network. | |
bool | readDLKeywords (QStringList &strList, int &N, int &NM, int &NR, int &NC, bool &fullmatrixFormat, bool &edgelist1Format) |
void | readDotProperties (QString str, qreal &, QString &label, QString &shape, QString &color, QString &fontName, QString &fontColor) |
Reads the properties of a dot element. | |
bool | readGraphML (QXmlStreamReader &) |
Checks the xml token name and calls the appropriate function. | |
void | readGraphMLElementGraph (QXmlStreamReader &) |
Reads a graph definition. | |
void | readGraphMLElementNode (QXmlStreamReader &) |
Reads basic node attributes and sets the nodeNumber. | |
void | endGraphMLElementNode (QXmlStreamReader &) |
Signals to create a new node. | |
void | readGraphMLElementEdge (QXmlStreamAttributes &) |
Reads basic edge creation properties. | |
void | endGraphMLElementEdge (QXmlStreamReader &) |
Signals for a new edge to be created/added. | |
void | readGraphMLElementData (QXmlStreamReader &) |
Reads data for edges and nodes. | |
void | readGraphMLElementUnknown (QXmlStreamReader &) |
Trivial call for unknown elements. | |
void | readGraphMLElementKey (QXmlStreamAttributes &) |
Reads a key definition. | |
void | readGraphMLElementDefaultValue (QXmlStreamReader &) |
Reads default key values. | |
void | readGraphMLElementNodeGraphics (QXmlStreamReader &) |
Reads node graphics data and properties: label, color, shape, size, coordinates, etc. | |
void | readGraphMLElementEdgeGraphics (QXmlStreamReader &) |
Reads edge graphics data and properties: path, linestyle,width, arrows, etc. | |
void | createMissingNodeEdges () |
Creates any missing node edges. | |
bool | isComment (QString str) |
Helper. Checks if the string parameter is a comment (starts with a known char, i.e #). | |
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 to to newNodes) | |
Private Member Functions | |
bool | validateAndInitialize (const QByteArray &rawData, const QString &delimiter, const bool &sm_has_labels, QStringList &nodeLabels) |
void | resetCounters () |
bool | doParseAdjacency (QTextStream &ts, const QString &delimiter, const QStringList &nodeLabels) |
void | createNodeWithDefaults (int nodeIndex, const QString &label) |
bool | createEdgesForRow (const QStringList ¤tRow, int rowIndex) |
bool | containsReservedKeywords (const QString &str) const |
Defines a class for network file loading and parsing.
Supports GraphML, Pajek, Adjacency, Graphviz, UCINET, EdgeLists etc
Parser::Parser | ( | ) |
Parser::~Parser | ( | ) |
|
private |
Checks if the given string contains any reserved keywords. Reserved keywords suggest the file is not adjacency-formatted but in another graph format. Parsing is aborted if a reserved keyword is found.
str | The string to check for keywords. |
|
private |
Iterates through a row of the adjacency matrix to create edges. Emits a signal for each non-zero weight to create an edge between nodes. Parsing is aborted immediately if any invalid data is encountered.
currentRow | The adjacency matrix row being processed. |
rowIndex | The index of the row (source node for edges). |
void Parser::createMissingNodeEdges | ( | ) |
Creates any missing node edges.
|
private |
Emits a signal to create a node with the specified properties. Assigns a random position for the node within the graph dimensions.
nodeIndex | Index of the node to create. |
label | Label for the node (numerical or custom). |
void Parser::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 to to newNodes)
fixedNum | |
label | |
newNodes |
|
private |
Processes the adjacency matrix file to create nodes and edges. Reads each line of the matrix, creates nodes for the first row, and creates edges for subsequent rows. Uses nodeLabels
to assign labels to nodes if provided. Parsing is aborted immediately if any issue is encountered.
ts | QTextStream of the decoded adjacency matrix file. |
delimiter | Delimiter used to split rows and columns. |
nodeLabels | List of node labels (optional). If empty, numeric labels are used. |
void Parser::endGraphMLElementEdge | ( | QXmlStreamReader & | xml | ) |
Signals for a new edge to be created/added.
Called at the end of edge element
xml |
void Parser::endGraphMLElementNode | ( | QXmlStreamReader & | xml | ) |
Signals to create a new node.
called at the end of a node element
xml |
|
signal |
bool Parser::isComment | ( | QString | str | ) |
Helper. Checks if the string parameter is a comment (starts with a known char, i.e #).
str |
void Parser::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.
fileName | |
codecName | |
defNodeSize | |
defNodeColor | |
defNodeShape | |
defNodeNumberColor | |
defNodeNumberSize | |
defNodeLabelColor | |
defNodeLabelSize | |
defEdgeColor | |
width | |
height | |
format | |
sm_mode | |
delim |
bool Parser::parseAsAdjacency | ( | const QByteArray & | rawData, |
const QString & | delimiter = "," , |
||
const bool & | sm_has_labels = false |
||
) |
Main function to parse adjacency-formatted data. Validates the format, resets counters, and processes the file to create nodes and edges. If sm_has_labels
is true, the first comment line is treated as node labels. NOTE: Parsing is aborted if any invalid data is encountered.
Example of a supported adjacency matrix file with node labels:
0, 1, 1 1, 0, 0 1, 0, 0
In this example:
rawData | Raw input data as QByteArray. |
delimiter | Delimiter used to split rows and columns. |
sm_has_labels | Indicates if the sociomatrix has labels in the first comment line. |
bool Parser::parseAsDL | ( | const QByteArray & | rawData | ) |
Parses the data as DL-formatted (UCINET)
rawData |
bool Parser::parseAsDot | ( | const QByteArray & | rawData | ) |
Parses the data as dot (Graphviz) formatted network.
rawData |
bool Parser::parseAsEdgeListSimple | ( | const QByteArray & | rawData, |
const QString & | delimiter | ||
) |
Parses the data as simple edgelist formatted.
rawData | |
delimiter |
bool Parser::parseAsEdgeListWeighted | ( | const QByteArray & | rawData, |
const QString & | delimiter | ||
) |
Parses the data as weighted edgelist formatted network.
This method can read and parse edgelist formated files where edge source and target are either named with numbers or with labels That is the following formats can be parsed:
1 2 1 1 3 2 1 6 2 1 8 2 ...
actor1 actor2 1 actor2 actor4 2 actor1 actor3 1 actorX actorY 3 name othername 1 othername somename 2 ...
rawData | |
delimiter |
bool Parser::parseAsGML | ( | const QByteArray & | rawData | ) |
Parses the data as GML formatted network.
rawData |
bool Parser::parseAsGraphML | ( | const QByteArray & | rawData | ) |
Parses the data as GraphML (not GML) formatted network.
rawData |
bool Parser::parseAsPajek | ( | const QByteArray & | rawData | ) |
Parses the data as Pajek-formatted.
rawData |
SPLIT EACH LINE (ON EMPTY SPACE CHARACTERS) IN SEVERAL ELEMENTS
READING NODES
NODELABEL
NODESHAPE: There are five possible .
NODECOLORS
READ NODE COORDINATES
EDGES
ARCS
ARCSlist
matrix
bool Parser::parseAsTwoModeSociomatrix | ( | const QByteArray & | rawData | ) |
Parses the data as two-mode sociomatrix formatted network.
rawData |
bool Parser::readDLKeywords | ( | QStringList & | strList, |
int & | N, | ||
int & | NM, | ||
int & | NR, | ||
int & | NC, | ||
bool & | fullmatrixFormat, | ||
bool & | edgelist1Format | ||
) |
void Parser::readDotProperties | ( | QString | str, |
qreal & | nValue, | ||
QString & | label, | ||
QString & | shape, | ||
QString & | color, | ||
QString & | fontName, | ||
QString & | fontColor | ||
) |
Reads the properties of a dot element.
str | |
nValue | |
label | |
shape | |
color | |
fontName | |
fontColor |
bool Parser::readGraphML | ( | QXmlStreamReader & | xml | ) |
Checks the xml token name and calls the appropriate function.
xml |
void Parser::readGraphMLElementData | ( | QXmlStreamReader & | xml | ) |
Reads data for edges and nodes.
called at a data element (usually nested inside a node or an edge element)
xml |
void Parser::readGraphMLElementDefaultValue | ( | QXmlStreamReader & | xml | ) |
Reads default key values.
Called at a default element (usually nested inside key element)
xml |
void Parser::readGraphMLElementEdge | ( | QXmlStreamAttributes & | xmlStreamAttr | ) |
Reads basic edge creation properties.
called at the start of an edge element
xmlStreamAttr |
void Parser::readGraphMLElementEdgeGraphics | ( | QXmlStreamReader & | xml | ) |
Reads edge graphics data and properties: path, linestyle,width, arrows, etc.
xml |
void Parser::readGraphMLElementGraph | ( | QXmlStreamReader & | xml | ) |
void Parser::readGraphMLElementKey | ( | QXmlStreamAttributes & | xmlStreamAttr | ) |
Reads a key definition.
called at key element
xmlStreamAttr |
void Parser::readGraphMLElementNode | ( | QXmlStreamReader & | xml | ) |
Reads basic node attributes and sets the nodeNumber.
called at the start of a node element
xml |
void Parser::readGraphMLElementNodeGraphics | ( | QXmlStreamReader & | xml | ) |
Reads node graphics data and properties: label, color, shape, size, coordinates, etc.
xml |
void Parser::readGraphMLElementUnknown | ( | QXmlStreamReader & | xml | ) |
Trivial call for unknown elements.
xml |
|
signal |
|
private |
Resets counters and data structures used during parsing. Clears relations and resets node and edge counters to ensure a clean state.
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
private |
Validates the adjacency matrix file format and, optionally, gets node labels from first line (if it is a comment line). Checks for reserved keywords, row consistency, and appropriate delimiters in the first 11 rows. Parsing is aborted immediately if any issue is encountered.
rawData | Raw input data as QByteArray. |
delimiter | Delimiter used to split rows and columns. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |