Node.py 3.9 KB
#!/usr/bin/env python
'''
local-twitter : Node
@euthor: Cristina Muntean (cristina.muntean@isti.cnr.it)
@date: 7/6/16
-----------------------------


'''
import json


class Node:

    def __init__(self, node_id, description):
        self.id = node_id   # it's an int
        # self.description = json.dumps(description).replace('"', '')
        self.description = description
        self.nodeCount = 0
        self.edgeCount = 0
        self.mentionCount = 0
        self.replyCount = 0
        self.RTCount = 0
        self.innerRTCount = 0
        self.outerRTCount = 0
        self.quoteCount = 0
        self.innerQuoteCount = 0
        self.outerQuoteCount = 0

    def incrementNode(self, n=1):
        self.nodeCount += n

    def incrementEdge(self, n=1):
        self.edgeCount += n

    # attributes where we do not have the original
    def incMention(self, n=1):
        self.mentionCount += n

    def incReply(self, n=1):
        self.replyCount += n

    # attributes where we have the original and can tell if inner or outer or other
    def incRT(self, n=1):
        self.RTCount += n

    def incInnerRT(self, n=1):
        self.innerRTCount += n

    def incOuterRT(self, n=1):
        self.outerRTCount += n

    def incQuote(self, n=1):
        self.quoteCount += n

    def incInnerQuote(self, n=1):
        self.innerQuoteCount += n

    def incOuterQuote(self, n=1):
        self.outerQuoteCount += n

    def tabPrint(self):
        return "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(self.id, self.description, self.nodeCount,
                                                                       self.edgeCount, self.mentionCount,
                                                                       self.replyCount, self.RTCount, self.innerRTCount,
                                                                       self.outerRTCount, self.quoteCount,
                                                                       self.innerQuoteCount, self.outerQuoteCount)
    def tabPrintNoID(self):
        return "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(self.description, self.nodeCount,
                                                                       self.edgeCount, self.mentionCount,
                                                                       self.replyCount, self.RTCount, self.innerRTCount,
                                                                       self.outerRTCount, self.quoteCount,
                                                                       self.innerQuoteCount, self.outerQuoteCount)
    @staticmethod
    def parseString(lineString):
        """
        Given a string we create a Node object
        :param lineString:
        :return:
        """
        dataList = lineString.replace("\n", "").split("\t")
        if len(dataList) != 12:
            print "There's a problem with the column number"
            return None
        nodeId = int(dataList[0])
        nodeDesc = unicode(dataList[1])
        nodeCount = int(dataList[2])
        nodeEdgeCount = int(dataList[3])
        nodeMentionCount = int(dataList[4])
        nodeReplyCount = int(dataList[5])
        nodeRTCount = int(dataList[6])
        nodeInnerRTCount = int(dataList[7])
        nodeOuterRTCount = int(dataList[8])
        nodeQuoteCount = int(dataList[9])
        nodeInnerQuoteCount = int(dataList[10])
        nodeOuterQuoteCount = int(dataList[11])

        node = Node(nodeId, nodeDesc)
        node.nodeCount = nodeCount
        node.edgeCount = nodeEdgeCount
        node.mentionCount = nodeMentionCount
        node.replyCount = nodeReplyCount
        node.RTCount = nodeRTCount
        node.innerRTCount = nodeInnerRTCount
        node.outerRTCount = nodeOuterRTCount
        node.quoteCount = nodeQuoteCount
        node.innerQuoteCount = nodeInnerQuoteCount
        node.outerQuoteCount = nodeOuterQuoteCount
        return node


def main():
    pass


if __name__ == '__main__':
    main()