jsontonetworkgraph 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/jsontonetworkgraph.rb +58 -16
- metadata +2 -2
data/lib/jsontonetworkgraph.rb
CHANGED
@@ -16,39 +16,81 @@ class JSONToNetworkGraph
|
|
16
16
|
# Generate all the nodes
|
17
17
|
def genNodes
|
18
18
|
@input.each do |i|
|
19
|
-
|
20
|
-
|
19
|
+
if !(i[@field1].nil? || i[@field2].nil? || i[@field1].empty? || i[@field2].empty?)
|
20
|
+
arrayCheckNode(@field1, i[@field1], i)
|
21
|
+
arrayCheckNode(@field2, i[@field2], i)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Handle fields that are arrays
|
27
|
+
def arrayCheckNode(fieldname, fieldvalue, i)
|
28
|
+
if fieldvalue.is_a? Array
|
29
|
+
fieldvalue.each do |a|
|
30
|
+
addupdateNode(fieldname, a, i)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
addupdateNode(fieldname, fieldvalue, i)
|
21
34
|
end
|
22
35
|
end
|
23
36
|
|
24
37
|
# Create or update the appropriate node
|
25
|
-
def addupdateNode(fieldname, i)
|
26
|
-
if !(@nodehash.include?
|
27
|
-
@nodehash[
|
38
|
+
def addupdateNode(fieldname, fieldvalue, i)
|
39
|
+
if !(@nodehash.include? fieldvalue)
|
40
|
+
@nodehash[fieldvalue] = Node.new(@nodeindex, fieldvalue, fieldname, i)
|
28
41
|
@nodeindex += 1
|
29
42
|
else
|
30
|
-
@nodehash[
|
43
|
+
@nodehash[fieldvalue].update(i)
|
31
44
|
end
|
32
45
|
end
|
33
46
|
|
34
47
|
# Generate all the links
|
35
48
|
def genLinks
|
36
49
|
@input.each do |i|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@nodehash[i[@field1]].addLink
|
43
|
-
@nodehash[i[@field2]].addLink
|
50
|
+
if !(i[@field1].nil? || i[@field2].nil? || i[@field1].empty? || i[@field2].empty?)
|
51
|
+
arrayCheckLink(i[@field1], i[@field2], i)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
# Handle fields that are arrays
|
57
|
+
def arrayCheckLink(fieldvalue1, fieldvalue2, i)
|
58
|
+
if (fieldvalue1.is_a? Array) && !(fieldvalue2.is_a? Array)
|
59
|
+
fieldvalue1.each do |a|
|
60
|
+
addupdateLink(a, fieldvalue2, i)
|
61
|
+
end
|
62
|
+
elsif (fieldvalue2.is_a? Array) && !(fieldvalue1.is_a? Array)
|
63
|
+
fieldvalue2.each do |a|
|
64
|
+
addupdateLink(fieldvalue1, a, i)
|
65
|
+
end
|
66
|
+
elsif (fieldvalue1.is_a? Array) && (fieldvalue2.is_a? Array)
|
67
|
+
fieldvalue1.each do |a|
|
68
|
+
fieldvalue2.each do |b|
|
69
|
+
addupateLink(a, b, i)
|
70
|
+
end
|
48
71
|
end
|
72
|
+
else
|
73
|
+
addupdateLink(fieldvalue1, fieldvalue2, i)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create or update the appropriate link
|
78
|
+
def addupdateLink(fieldvalue1, fieldvalue2, i)
|
79
|
+
identifier = fieldvalue1 + "-" + fieldvalue2
|
80
|
+
if !@linkhash.include? identifier
|
81
|
+
source = @nodehash[fieldvalue1].getID
|
82
|
+
target = @nodehash[fieldvalue2].getID
|
83
|
+
|
84
|
+
@nodehash[fieldvalue1].addLink
|
85
|
+
@nodehash[fieldvalue2].addLink
|
86
|
+
|
87
|
+
@linkhash[identifier] = Link.new(source, target, fieldvalue1, fieldvalue2, i)
|
88
|
+
else
|
89
|
+
@linkhash[identifier].update(i)
|
49
90
|
end
|
50
91
|
end
|
51
92
|
|
93
|
+
# Count the number of links
|
52
94
|
def linkCount
|
53
95
|
@linkhash.each_value do |l|
|
54
96
|
count1 = @nodehash[l.instance_variable_get(:@field1)].instance_variable_get(:@linkcount)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsontonetworkgraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Generates node and link data from any JSON.
|
15
15
|
email: shidash@shidash.com
|