Defines a class for network file loading and parsing. More...

#include <parser.h>

+ Inheritance diagram for Parser:
+ Collaboration diagram for Parser:

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 int &sm_mode, const QString &delim=QString())
 Loads the data of the given network file, and calls the relevant method to parse it. More...
 
bool parseAsPajek (const QByteArray &rawData)
 Parses the data as Pajek-formatted. More...
 
bool parseAsAdjacency (const QByteArray &rawData)
 Parses the data as adjacency sociomatrix-formatted. More...
 
bool parseAsDot (const QByteArray &rawData)
 Parses the data as dot (Graphviz) formatted network. More...
 
bool parseAsGraphML (const QByteArray &rawData)
 Parses the data as GraphML (not GML) formatted network. More...
 
bool parseAsGML (const QByteArray &rawData)
 Parses the data as GML formatted network. More...
 
bool parseAsDL (const QByteArray &rawData)
 Parses the data as DL-formatted (UCINET) More...
 
bool parseAsEdgeListSimple (const QByteArray &rawData, const QString &delimiter)
 Parses the data as simple edgelist formatted. More...
 
bool parseAsEdgeListWeighted (const QByteArray &rawData, const QString &delimiter)
 Parses the data as weighted edgelist formatted network. More...
 
bool parseAsTwoModeSociomatrix (const QByteArray &rawData)
 Parses the data as two-mode sociomatrix formatted network. More...
 
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. More...
 
bool readGraphML (QXmlStreamReader &)
 Checks the xml token name and calls the appropriate function. More...
 
void readGraphMLElementGraph (QXmlStreamReader &)
 Reads a graph definition. More...
 
void readGraphMLElementNode (QXmlStreamReader &)
 Reads basic node attributes and sets the nodeNumber. More...
 
void endGraphMLElementNode (QXmlStreamReader &)
 Signals to create a new node. More...
 
void readGraphMLElementEdge (QXmlStreamAttributes &)
 Reads basic edge creation properties. More...
 
void endGraphMLElementEdge (QXmlStreamReader &)
 Signals for a new edge to be created/added. More...
 
void readGraphMLElementData (QXmlStreamReader &)
 Reads data for edges and nodes. More...
 
void readGraphMLElementUnknown (QXmlStreamReader &)
 Trivial call for unknown elements. More...
 
void readGraphMLElementKey (QXmlStreamAttributes &)
 Reads a key definition. More...
 
void readGraphMLElementDefaultValue (QXmlStreamReader &)
 Reads default key values. More...
 
void readGraphMLElementNodeGraphics (QXmlStreamReader &)
 Reads node graphics data and properties: label, color, shape, size, coordinates, etc. More...
 
void readGraphMLElementEdgeGraphics (QXmlStreamReader &)
 Reads edge graphics data and properties: path, linestyle,width, arrows, etc. More...
 
void createMissingNodeEdges ()
 Creates any missing node edges. More...
 
bool isComment (QString str)
 Helper. Checks if the string parameter is a comment (starts with a known char, i.e #). More...
 
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) More...
 

Private Attributes

QHash< QString, int > nodeHash
 
QHash< QString, QString > keyFor
 
QHash< QString, QString > keyName
 
QHash< QString, QString > keyType
 
QHash< QString, QString > keyDefaultValue
 
QHash< QString, QString > edgesMissingNodesHash
 
QStringList edgeMissingNodesList
 
QStringList edgeMissingNodesListData
 
QStringList relationsList
 
QMultiMap< int, int > firstModeMultiMap
 
QMultiMap< int, int > secondModeMultiMap
 
QXmlStreamReader * xml
 
QString fileDirPath
 
QString m_textCodecName
 
QString networkName
 
QString initNodeColor
 
QString initNodeShape
 
QString initNodeCustomIcon
 
QString initNodeNumberColor
 
QString initNodeLabelColor
 
QString initEdgeColor
 
QString initEdgeLabel
 
QString delimiter
 
QString errorMessage
 
QString nodeColor
 
QString edgeColor
 
QString edgeType
 
QString nodeShape
 
QString nodeLabel
 
QString edgeLabel
 
QString nodeIconPath
 
QString nodeNumberColor
 
QString nodeLabelColor
 
QString key_id
 
QString key_value
 
QString key_name
 
QString key_what
 
QString key_type
 
QString node_id
 
QString edge_id
 
QString edge_source
 
QString edge_target
 
QString edge_weight
 
QString edge_directed
 
int gwWidth
 
int gwHeight
 
int totalLinks
 
int totalNodes
 
int fileFormat
 
int two_sm_mode
 
int edgeDirType
 
int initNodeSize
 
int initNodeNumberSize
 
int nodeNumberSize
 
int initNodeLabelSize
 
int nodeLabelSize
 
int source
 
int target
 
int nodeSize
 
qreal initEdgeWeight
 
qreal edgeWeight
 
qreal arrowSize
 
qreal bez_p1_x
 
qreal bez_p1_y
 
qreal bez_p2_x
 
qreal bez_p2_y
 
bool fileLoaded
 
bool missingNode
 
bool arrows
 
bool bezier
 
bool conv_OK
 
bool bool_key
 
bool bool_node
 
bool bool_edge
 
bool fileContainsNodeColors
 
bool fileContainsNodeCoords
 
bool fileContainsLinkColors
 
bool fileContainsLinkLabels
 
double randX
 
double randY
 

Detailed Description

Defines a class for network file loading and parsing.

Supports GraphML, Pajek, Adjacency, Graphviz, UCINET, EdgeLists etc

Constructor & Destructor Documentation

◆ Parser()

Parser::Parser ( )

◆ ~Parser()

Parser::~Parser ( )

Member Function Documentation

◆ createMissingNodeEdges()

void Parser::createMissingNodeEdges ( )

Creates any missing node edges.

◆ createRandomNodes()

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)

Parameters
fixedNum
label
newNodes

◆ endGraphMLElementEdge()

void Parser::endGraphMLElementEdge ( QXmlStreamReader &  xml)

Signals for a new edge to be created/added.

Called at the end of edge element

Parameters
xml

◆ endGraphMLElementNode()

void Parser::endGraphMLElementNode ( QXmlStreamReader &  xml)

Signals to create a new node.

called at the end of a node element

Parameters
xml

◆ finished

void Parser::finished ( QString  )
signal

◆ isComment()

bool Parser::isComment ( QString  str)

Helper. Checks if the string parameter is a comment (starts with a known char, i.e #).

Parameters
str
Returns
bool

◆ load()

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 int &  sm_mode,
const QString &  delim = QString() 
)

Loads the data of the given network file, and calls the relevant method to parse it.

Parameters
fileName
codecName
defNodeSize
defNodeColor
defNodeShape
defNodeNumberColor
defNodeNumberSize
defNodeLabelColor
defNodeLabelSize
defEdgeColor
width
height
format
sm_mode
delim

◆ parseAsAdjacency()

bool Parser::parseAsAdjacency ( const QByteArray &  rawData)

Parses the data as adjacency sociomatrix-formatted.

Returns
bool

◆ parseAsDL()

bool Parser::parseAsDL ( const QByteArray &  rawData)

Parses the data as DL-formatted (UCINET)

Parameters
rawData
Returns
bool

◆ parseAsDot()

bool Parser::parseAsDot ( const QByteArray &  rawData)

Parses the data as dot (Graphviz) formatted network.

Parameters
rawData
Returns

◆ parseAsEdgeListSimple()

bool Parser::parseAsEdgeListSimple ( const QByteArray &  rawData,
const QString &  delimiter 
)

Parses the data as simple edgelist formatted.

Parameters
rawData
delimiter
Returns
bool

◆ parseAsEdgeListWeighted()

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:

edgelist with node numbers

1 2 1 1 3 2 1 6 2 1 8 2 ...

edgelist with node labels

actor1 actor2 1 actor2 actor4 2 actor1 actor3 1 actorX actorY 3 name othername 1 othername somename 2 ...

Parameters
rawData
delimiter
Returns

◆ parseAsGML()

bool Parser::parseAsGML ( const QByteArray &  rawData)

Parses the data as GML formatted network.

Parameters
rawData
Returns
bool

◆ parseAsGraphML()

bool Parser::parseAsGraphML ( const QByteArray &  rawData)

Parses the data as GraphML (not GML) formatted network.

Parameters
rawData
Returns
bool

◆ parseAsPajek()

bool Parser::parseAsPajek ( const QByteArray &  rawData)

Parses the data as Pajek-formatted.

Parameters
rawData
Returns

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

◆ parseAsTwoModeSociomatrix()

bool Parser::parseAsTwoModeSociomatrix ( const QByteArray &  rawData)

Parses the data as two-mode sociomatrix formatted network.

Parameters
rawData
Returns

◆ readDLKeywords()

bool Parser::readDLKeywords ( QStringList &  strList,
int &  N,
int &  NM,
int &  NR,
int &  NC,
bool &  fullmatrixFormat,
bool &  edgelist1Format 
)

◆ readDotProperties()

void Parser::readDotProperties ( QString  str,
qreal &  nValue,
QString &  label,
QString &  shape,
QString &  color,
QString &  fontName,
QString &  fontColor 
)

Reads the properties of a dot element.

Parameters
str
nValue
label
shape
color
fontName
fontColor

◆ readGraphML()

bool Parser::readGraphML ( QXmlStreamReader &  xml)

Checks the xml token name and calls the appropriate function.

Parameters
xml
Returns
bool

◆ readGraphMLElementData()

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)

Parameters
xml

◆ readGraphMLElementDefaultValue()

void Parser::readGraphMLElementDefaultValue ( QXmlStreamReader &  xml)

Reads default key values.

Called at a default element (usually nested inside key element)

Parameters
xml

◆ readGraphMLElementEdge()

void Parser::readGraphMLElementEdge ( QXmlStreamAttributes &  xmlStreamAttr)

Reads basic edge creation properties.

called at the start of an edge element

Parameters
xmlStreamAttr

◆ readGraphMLElementEdgeGraphics()

void Parser::readGraphMLElementEdgeGraphics ( QXmlStreamReader &  xml)

Reads edge graphics data and properties: path, linestyle,width, arrows, etc.

Parameters
xml

◆ readGraphMLElementGraph()

void Parser::readGraphMLElementGraph ( QXmlStreamReader &  xml)

Reads a graph definition.

Called at Graph element

Parameters
xml

◆ readGraphMLElementKey()

void Parser::readGraphMLElementKey ( QXmlStreamAttributes &  xmlStreamAttr)

Reads a key definition.

called at key element

Parameters
xmlStreamAttr

◆ readGraphMLElementNode()

void Parser::readGraphMLElementNode ( QXmlStreamReader &  xml)

Reads basic node attributes and sets the nodeNumber.

called at the start of a node element

Parameters
xml

◆ readGraphMLElementNodeGraphics()

void Parser::readGraphMLElementNodeGraphics ( QXmlStreamReader &  xml)

Reads node graphics data and properties: label, color, shape, size, coordinates, etc.

Parameters
xml

◆ readGraphMLElementUnknown()

void Parser::readGraphMLElementUnknown ( QXmlStreamReader &  xml)

Trivial call for unknown elements.

Parameters
xml

◆ removeDummyNode

void Parser::removeDummyNode ( int  )
signal

◆ signalAddNewRelation

void Parser::signalAddNewRelation ( const QString &  relName,
const bool &  changeRelation = false 
)
signal

◆ signalCreateEdge

void Parser::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 
)
signal

◆ signalCreateNode

void Parser::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 
)
signal

◆ signalCreateNodeAtPosRandom

void Parser::signalCreateNodeAtPosRandom ( const bool &  signalMW = false)
signal

◆ signalCreateNodeAtPosRandomWithLabel

void Parser::signalCreateNodeAtPosRandomWithLabel ( const int &  num,
const QString &  label,
const bool &  signalMW = false 
)
signal

◆ signalFileLoaded

void Parser::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() 
)
signal

◆ signalSetRelation

void Parser::signalSetRelation ( int  ,
const bool &  updateUI = true 
)
signal

Member Data Documentation

◆ arrows

bool Parser::arrows
private

◆ arrowSize

qreal Parser::arrowSize
private

◆ bez_p1_x

qreal Parser::bez_p1_x
private

◆ bez_p1_y

qreal Parser::bez_p1_y
private

◆ bez_p2_x

qreal Parser::bez_p2_x
private

◆ bez_p2_y

qreal Parser::bez_p2_y
private

◆ bezier

bool Parser::bezier
private

◆ bool_edge

bool Parser::bool_edge
private

◆ bool_key

bool Parser::bool_key
private

◆ bool_node

bool Parser::bool_node
private

◆ conv_OK

bool Parser::conv_OK
private

◆ delimiter

QString Parser::delimiter
private

◆ edge_directed

QString Parser::edge_directed
private

◆ edge_id

QString Parser::edge_id
private

◆ edge_source

QString Parser::edge_source
private

◆ edge_target

QString Parser::edge_target
private

◆ edge_weight

QString Parser::edge_weight
private

◆ edgeColor

QString Parser::edgeColor
private

◆ edgeDirType

int Parser::edgeDirType
private

◆ edgeLabel

QString Parser::edgeLabel
private

◆ edgeMissingNodesList

QStringList Parser::edgeMissingNodesList
private

◆ edgeMissingNodesListData

QStringList Parser::edgeMissingNodesListData
private

◆ edgesMissingNodesHash

QHash<QString, QString> Parser::edgesMissingNodesHash
private

◆ edgeType

QString Parser::edgeType
private

◆ edgeWeight

qreal Parser::edgeWeight
private

◆ errorMessage

QString Parser::errorMessage
private

◆ fileContainsLinkColors

bool Parser::fileContainsLinkColors
private

◆ fileContainsLinkLabels

bool Parser::fileContainsLinkLabels
private

◆ fileContainsNodeColors

bool Parser::fileContainsNodeColors
private

◆ fileContainsNodeCoords

bool Parser::fileContainsNodeCoords
private

◆ fileDirPath

QString Parser::fileDirPath
private

◆ fileFormat

int Parser::fileFormat
private

◆ fileLoaded

bool Parser::fileLoaded
private

◆ firstModeMultiMap

QMultiMap<int, int> Parser::firstModeMultiMap
private

◆ gwHeight

int Parser::gwHeight
private

◆ gwWidth

int Parser::gwWidth
private

◆ initEdgeColor

QString Parser::initEdgeColor
private

◆ initEdgeLabel

QString Parser::initEdgeLabel
private

◆ initEdgeWeight

qreal Parser::initEdgeWeight
private

◆ initNodeColor

QString Parser::initNodeColor
private

◆ initNodeCustomIcon

QString Parser::initNodeCustomIcon
private

◆ initNodeLabelColor

QString Parser::initNodeLabelColor
private

◆ initNodeLabelSize

int Parser::initNodeLabelSize
private

◆ initNodeNumberColor

QString Parser::initNodeNumberColor
private

◆ initNodeNumberSize

int Parser::initNodeNumberSize
private

◆ initNodeShape

QString Parser::initNodeShape
private

◆ initNodeSize

int Parser::initNodeSize
private

◆ key_id

QString Parser::key_id
private

◆ key_name

QString Parser::key_name
private

◆ key_type

QString Parser::key_type
private

◆ key_value

QString Parser::key_value
private

◆ key_what

QString Parser::key_what
private

◆ keyDefaultValue

QHash<QString, QString> Parser::keyDefaultValue
private

◆ keyFor

QHash<QString, QString> Parser::keyFor
private

◆ keyName

QHash<QString, QString> Parser::keyName
private

◆ keyType

QHash<QString, QString> Parser::keyType
private

◆ m_textCodecName

QString Parser::m_textCodecName
private

◆ missingNode

bool Parser::missingNode
private

◆ networkName

QString Parser::networkName
private

◆ node_id

QString Parser::node_id
private

◆ nodeColor

QString Parser::nodeColor
private

◆ nodeHash

QHash<QString, int> Parser::nodeHash
private

◆ nodeIconPath

QString Parser::nodeIconPath
private

◆ nodeLabel

QString Parser::nodeLabel
private

◆ nodeLabelColor

QString Parser::nodeLabelColor
private

◆ nodeLabelSize

int Parser::nodeLabelSize
private

◆ nodeNumberColor

QString Parser::nodeNumberColor
private

◆ nodeNumberSize

int Parser::nodeNumberSize
private

◆ nodeShape

QString Parser::nodeShape
private

◆ nodeSize

int Parser::nodeSize
private

◆ randX

double Parser::randX
private

◆ randY

double Parser::randY
private

◆ relationsList

QStringList Parser::relationsList
private

◆ secondModeMultiMap

QMultiMap<int, int> Parser::secondModeMultiMap
private

◆ source

int Parser::source
private

◆ target

int Parser::target
private

◆ totalLinks

int Parser::totalLinks
private

◆ totalNodes

int Parser::totalNodes
private

◆ two_sm_mode

int Parser::two_sm_mode
private

◆ xml

QXmlStreamReader* Parser::xml
private

The documentation for this class was generated from the following files: