Node.py
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/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()