graphml2json 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/graphml2json.gemspec +2 -1
- data/lib/graphml2json.rb +34 -1
- data/lib/graphml2json/version.rb +1 -1
- data/spec/fixtures/graphml_with_namespacing.txt +17 -0
- data/spec/fixtures/graphml_without_namespacing.txt +13 -0
- data/spec/graphml2json_spec.rb +23 -0
- data/spec/spec_helper.rb +18 -0
- metadata +27 -5
- data/lib/graphml2json/graphml2json.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14e089c2671ab59a14de29b7ffdf0c0e4f2aaf07
|
4
|
+
data.tar.gz: ea14a41715d6830c1db90415a1f53a3008c660b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: affec461b48f8e23bdf3d1f741b0c029e5a3a479352a4a12156fc99156db440d403c1c0d223850ea23ed4470c2a2df76d8ee4bde344feaa412417aaa609eac34
|
7
|
+
data.tar.gz: 308795e4f353c5600bbd94c6bc51ed9ca15b42a724a179eaee0699e4be0c2879e9a69f17e9fb83e13b775143159e22976478e2d7a4f70a5339e9cc749d440c8a
|
data/.rspec
ADDED
data/graphml2json.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["<gregory.ostermayr@gmail.com>"]
|
11
11
|
spec.description = %q{Convert graphml to json}
|
12
12
|
spec.summary = %q{Convert graphml to json}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/gregors/graphml2json"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "nokogiri", "~> 1.6.0"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
23
24
|
spec.add_development_dependency "rake"
|
24
25
|
end
|
data/lib/graphml2json.rb
CHANGED
@@ -1 +1,34 @@
|
|
1
|
-
require '
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Graphml2Json
|
5
|
+
|
6
|
+
def self.generate(xml_string)
|
7
|
+
doc = Nokogiri::XML(xml_string)
|
8
|
+
doc.remove_namespaces!
|
9
|
+
graph = doc.xpath('//graph')
|
10
|
+
nodes = graph.xpath('//node')
|
11
|
+
edges = graph.xpath('//edge')
|
12
|
+
|
13
|
+
@mapping = {}
|
14
|
+
@json_nodes = []
|
15
|
+
|
16
|
+
@graph = {}
|
17
|
+
@graph[:nodes] = []
|
18
|
+
@graph[:edges] = []
|
19
|
+
|
20
|
+
nodes.each_with_index do |n, index|
|
21
|
+
@mapping[n[:id]] = index
|
22
|
+
@graph[:nodes] << {:name => index}
|
23
|
+
end
|
24
|
+
|
25
|
+
@json_edges = []
|
26
|
+
edges.each do |e|
|
27
|
+
source = @mapping[e[:source]]
|
28
|
+
target = @mapping[e[:target]]
|
29
|
+
@graph[:edges] << { :source => source, :target => target }
|
30
|
+
end
|
31
|
+
|
32
|
+
JSON.generate(@graph)
|
33
|
+
end
|
34
|
+
end
|
data/lib/graphml2json/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
5
|
+
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
6
|
+
<graph id="G" >
|
7
|
+
<node id="0" />
|
8
|
+
<node id="1" />
|
9
|
+
<node id="2" />
|
10
|
+
<node id="3" />
|
11
|
+
|
12
|
+
<edge source="0" target="1" />
|
13
|
+
<edge source="1" target="2" />
|
14
|
+
<edge source="2" target="3" />
|
15
|
+
<edge source="3" target="4" />
|
16
|
+
</graph>
|
17
|
+
</graphml>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<graphml>
|
2
|
+
<graph id="G" >
|
3
|
+
<node id="0" />
|
4
|
+
<node id="1" />
|
5
|
+
<node id="2" />
|
6
|
+
<node id="3" />
|
7
|
+
|
8
|
+
<edge source="0" target="1" />
|
9
|
+
<edge source="1" target="2" />
|
10
|
+
<edge source="2" target="3" />
|
11
|
+
<edge source="3" target="4" />
|
12
|
+
</graph>
|
13
|
+
</graphml>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'graphml2json'
|
3
|
+
|
4
|
+
describe Graphml2Json do
|
5
|
+
let(:json) {'{"nodes":[{"name":0},{"name":1},{"name":2},{"name":3}],"edges":[{"source":0,"target":1},{"source":1,"target":2},{"source":2,"target":3},{"source":3,"target":null}]}'}
|
6
|
+
|
7
|
+
describe ".generate" do
|
8
|
+
context "missing proper namespace" do
|
9
|
+
it 'returns valid json' do
|
10
|
+
graphml = File.read("spec/fixtures/graphml_without_namespacing.txt")
|
11
|
+
Graphml2Json::generate(graphml).should == json
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with namespace" do
|
16
|
+
it 'returns valid json' do
|
17
|
+
graphml = File.read("spec/fixtures/graphml_with_namespacing.txt")
|
18
|
+
Graphml2Json::generate(graphml).should == json
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphml2json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Ostermayr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,15 +74,19 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- .gitignore
|
77
|
+
- .rspec
|
63
78
|
- Gemfile
|
64
79
|
- LICENSE.txt
|
65
80
|
- README.md
|
66
81
|
- Rakefile
|
67
82
|
- graphml2json.gemspec
|
68
83
|
- lib/graphml2json.rb
|
69
|
-
- lib/graphml2json/graphml2json.rb
|
70
84
|
- lib/graphml2json/version.rb
|
71
|
-
|
85
|
+
- spec/fixtures/graphml_with_namespacing.txt
|
86
|
+
- spec/fixtures/graphml_without_namespacing.txt
|
87
|
+
- spec/graphml2json_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/gregors/graphml2json
|
72
90
|
licenses:
|
73
91
|
- MIT
|
74
92
|
metadata: {}
|
@@ -92,4 +110,8 @@ rubygems_version: 2.0.6
|
|
92
110
|
signing_key:
|
93
111
|
specification_version: 4
|
94
112
|
summary: Convert graphml to json
|
95
|
-
test_files:
|
113
|
+
test_files:
|
114
|
+
- spec/fixtures/graphml_with_namespacing.txt
|
115
|
+
- spec/fixtures/graphml_without_namespacing.txt
|
116
|
+
- spec/graphml2json_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
class Graphml2Json
|
5
|
-
|
6
|
-
def self.generate(xml_string)
|
7
|
-
doc = Nokogiri::XML(xml_string)
|
8
|
-
graph = doc.xpath('//xmlns:graph')
|
9
|
-
nodes = graph.xpath('//xmlns:node')
|
10
|
-
edges = graph.xpath('//xmlns:edge')
|
11
|
-
|
12
|
-
@mapping = {}
|
13
|
-
@json_nodes = []
|
14
|
-
|
15
|
-
@graph = {}
|
16
|
-
@graph[:nodes] = []
|
17
|
-
@graph[:edges] = []
|
18
|
-
|
19
|
-
nodes.each_with_index do |n, index|
|
20
|
-
@mapping[n[:id]] = index
|
21
|
-
@graph[:nodes] << {:name => index}
|
22
|
-
end
|
23
|
-
|
24
|
-
@json_edges = []
|
25
|
-
edges.each do |e|
|
26
|
-
source = @mapping[e[:source]]
|
27
|
-
target = @mapping[e[:target]]
|
28
|
-
@graph[:edges] << { :source => source, :target => target }
|
29
|
-
end
|
30
|
-
|
31
|
-
JSON.generate(@graph)
|
32
|
-
end
|
33
|
-
end
|