joerivandervelde-molgenis-gem 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = MOLGENIS[http://molgenis.sourceforge.net] Metamodel Interaction gem
2
+
3
+ Author:: Morris Swertz, Joeri van der Velde
4
+ Version:: 0.0.1
5
+ Contact:: m.a.swertz@rug.nl
6
+ URL:: http://molgenis.sourceforge.net/
7
+ Licence:: LGPL 3 (See LICENCE or http://www.gnu.org/licenses/lgpl.html)
8
+ Copyright:: (c) 2004-2009 University of Groningen, University Medical Center Groningen, Inventory.nl
9
+
10
+
11
+
12
+ == Synopsis
13
+
14
+ This is a Ruby library to support the interaction with and visualization of MOLGENIS meta models [http://molgenis.sourceforge.net].
15
+ - GraphViz[http://www.graphviz.org/Download.php] (a graph visualization package)
16
+ - Rdoc gem
17
+ - LibXml gem
@@ -0,0 +1,167 @@
1
+ require "erb"
2
+
3
+
4
+ module MOLGENIS
5
+ class Dot
6
+ def write_dot(stream, model)
7
+ b = binding
8
+ template = %q{
9
+ digraph G {
10
+ compound = true
11
+ fontname = "Bitstream Vera Sans"
12
+ fontsize = 8
13
+ page = "12f,12f"
14
+ pagedir="TB"
15
+ rankdir="BT"
16
+ clusterrank = "local"
17
+ bgcolor = "white"
18
+ overlap = "false"
19
+ splines = "false"
20
+ layers = "1:2"
21
+ outputorder="edgesfirst"
22
+
23
+
24
+ node [
25
+ fontname = "Arial"
26
+ fontsize = 8
27
+ shape = "record"
28
+ color = "#808080"
29
+ style="filled"
30
+ fillcolor = "white"
31
+ layer = "2"
32
+ ]
33
+
34
+ edge [
35
+ fontname = "Bitstream Vera Sans"
36
+ fontsize = 8
37
+ layer = "1"
38
+ ]
39
+ <% if model.modules.size > 0 %>
40
+ subgraph cluster_legend {
41
+ rankdir ="LR";
42
+ label = "module legend"
43
+ color = "white"
44
+ fillcolor = "white"
45
+ rankType = "same"
46
+ <% model.modules.each { |m| %>
47
+ "<%= m.name %>"
48
+ [
49
+ style = "filled"
50
+ colorscheme= "pastel19"
51
+ fillcolor = "<%= m.color %>"
52
+ fontname = "Arial"
53
+ fontcolor = "black"
54
+ color = "black"
55
+ label = "{<%= m.name %>}"
56
+ ]
57
+ <% } %>
58
+
59
+ node [
60
+ style = "invis"
61
+ width = 0
62
+ ]
63
+ "spook_legend"
64
+ }
65
+ <% end %>
66
+
67
+ subgraph cluster_main {
68
+ rankdir ="TB";
69
+ pagedir="TB"
70
+ fillcolor = "white"
71
+
72
+ <% model.all_entities.each { |entity| %>
73
+ "<%= entity.name %>"
74
+ [
75
+ style = "filled"
76
+ <% if entity.color == 0 %>
77
+ fillcolor="lemonchiffon1"
78
+ <% else %>
79
+ colorscheme=pastel19
80
+ fillcolor = "<%=entity.color%>"
81
+ <% end %>
82
+ <%if entity.abstract %>
83
+ fontname = "Arial-Italic"
84
+ fontcolor = "dimgrey"
85
+ color = "dimgrey"
86
+ <% else %>
87
+ fontname = "Arial"
88
+ fontcolor = "black"
89
+ color = "black"
90
+ <% end %>
91
+ label = "{<% if entity.abstract %>Interface:<% end %><%= entity.name %><% entity.implements.each do |interface| %>\nimplements <%=interface%><% end %>|<% entity.fields.each do |f| %><% if !f.system %><%=f.name%> : <%=f.type %><% if (f.type=="xref" || f.type=="mref") %>(<%= f.xref_entity %>.<%=f.xref_field %>)<%end%>\l<%end%><%end%>}"
92
+ ]
93
+ <% } %>
94
+
95
+ /*interface relationships*/
96
+ edge [
97
+ arrowhead = "empty"
98
+ color = "grey"
99
+ ]
100
+ <% model.all_entities.each do |entity| %>
101
+ <% if entity.implements %>
102
+ <% entity.implements.each do |interface| %>
103
+ "<%= entity.name %>" -> "<%= interface %>"
104
+ <%end%>
105
+ <%end %>
106
+ <% end %>
107
+
108
+ /*extends relationships*/
109
+ edge [
110
+ arrowhead = "empty"
111
+ color = "black"
112
+ ]
113
+ <% model.all_entities.each do |entity| %>
114
+ <% if entity.extends %>
115
+ "<%= entity.name %>" -> "<%= entity.extends %>"
116
+ <%end %>
117
+ <% end %>
118
+
119
+ /*one to many 'xref' foreign key relationships*/
120
+ edge [
121
+ arrowhead = "open"
122
+ taillabel = "*"
123
+ ]
124
+
125
+ <% model.all_entities.each do |entity| %>
126
+ <% entity.fields.each do |f| %>
127
+ <% if f.type == "xref" %>
128
+ "<%= entity.name %>" -> "<%= f.xref_entity%>"
129
+ <% end %>
130
+ <% end %>
131
+ <% end %>
132
+
133
+ /*one to many 'mref' foreign key relationships*/
134
+ edge [
135
+ arrowhead = "open"
136
+ arrowtail = "open"
137
+ color = "black"
138
+ taillabel = "*"
139
+ arrowsize = 0.6
140
+ rank = "same"
141
+ ]
142
+
143
+ <% model.all_entities.each do |entity| %>
144
+ <% entity.fields.each do |f| %>
145
+ <% if f.type == "mref" %>
146
+ "<%= entity.name %>" -> "<%= f.xref_entity%>"
147
+ <% end %>
148
+ <% end %>
149
+ <% end %>
150
+
151
+ node [
152
+ style = "invis"
153
+ width = 0
154
+ ]
155
+ "spook_main"
156
+ }
157
+
158
+ edge [style = "invis"]
159
+ <% if model.modules.size > 0%>"spook_legend" -> "spook_main"<% end %>
160
+ }
161
+ }.gsub(/^ /, '')
162
+ imagedot = ERB.new(template, 0, "%<>")
163
+ stream.puts imagedot.result(b)
164
+ stream.flush
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,55 @@
1
+
2
+ module MOLGENIS # :nodoc:
3
+
4
+ # The model for a given MOLGENIS model
5
+ class MolgenisModel
6
+ # The list of all the entities that make up the model
7
+ attr_accessor :version,:name,:label,:entities, :modules, :description
8
+
9
+ # Creates an empty model a
10
+ def initialize
11
+ @entities = []
12
+ @modules = []
13
+ end
14
+
15
+ def all_entities
16
+ all_entities = []
17
+ @entities.each{|entity|
18
+ all_entities << entity
19
+ }
20
+ @modules.each { |module_obj|
21
+ module_obj.entities.each {|entity|
22
+ all_entities << entity
23
+ }
24
+
25
+ }
26
+ puts all_entities.size
27
+ puts @modules.size
28
+ all_entities
29
+ end
30
+ end
31
+
32
+ class ModuleModel
33
+ attr_accessor :name,:label,:entities, :description, :color
34
+
35
+ def initialize
36
+ @entities = []
37
+ end
38
+ end
39
+
40
+ #Definition of an Entity in MOLGENIS model
41
+ class EntityModel
42
+ attr_accessor :name, :label, :fields, :abstract,:implements,:extends,:module_name,:color
43
+
44
+ # Creates an empty entity
45
+ def initialize
46
+ @fields = []
47
+ @implements = []
48
+ end
49
+
50
+ end
51
+
52
+ class FieldModel
53
+ attr_accessor :name,:type,:system,:xref_entity,:xref_field
54
+ end
55
+ end
@@ -0,0 +1,98 @@
1
+ require "libxml"
2
+
3
+ module MOLGENIS
4
+
5
+ class Parser
6
+ # Returns the model for the given molgenis_model.
7
+ # The method accepts objects of classes File, StringIO and String only.
8
+ # ===Usage
9
+ # foo = ... # stuff to initialize foo here
10
+ # bar = MOLGENIS_MODEL:Parser.new.parse(foo)
11
+ def parse(molgenis_src)
12
+ case molgenis_src.class.to_s
13
+ when /^string$/i
14
+ document = LibXML::XML::Parser.string(molgenis_src).parse
15
+ when /^stringio|file$/i
16
+ molgenis_src.rewind
17
+ document = LibXML::XML::Parser.string(molgenis_src.read).parse
18
+ else
19
+ raise "Error parsing file."
20
+ end
21
+
22
+ root = document.root
23
+ return nil if(root.name != "molgenis")
24
+
25
+ raise "Doesn't appear to be a MOLGENIS model" if root.name != "molgenis"
26
+ version = root["version"]
27
+
28
+ create_model(root, version)
29
+ end
30
+
31
+ def create_model(element, version) # :nodoc:
32
+ model = MolgenisModel.new
33
+ model.name = element.attributes['name']
34
+ puts element.attributes['name'] + model.name
35
+ model.version = version
36
+ model.description = ""
37
+ element.find("description").each { |desc|
38
+ desc.children.each { |el|
39
+ model.description = model.description + el.to_s
40
+ }
41
+ }
42
+
43
+ color = 0
44
+ parse_entities(element.find("entity"),model, color)
45
+
46
+ element.find("module").each { |module_xml|
47
+
48
+ module_obj = ModuleModel.new
49
+ module_attributes = module_xml.attributes
50
+ module_obj.name = module_attributes["name"]
51
+ entities = module_xml.find("entity")
52
+
53
+ color += 1
54
+ module_obj.color = color
55
+ parse_entities(entities,module_obj,color)
56
+
57
+ model.modules << module_obj
58
+ }
59
+
60
+ return model
61
+ end
62
+
63
+ def parse_entities(entities,module_obj,colorno)
64
+ if entities
65
+ entities.each do |entity_xml|
66
+ entity = EntityModel.new
67
+ entity.module_name = module_obj.name
68
+ entity_attributes = entity_xml.attributes
69
+ entity.name = entity_attributes["name"]
70
+ entity.color = colorno
71
+ entity_attributes["implements"].split(",").each { |interface|
72
+ entity.implements << interface
73
+ } if !entity_attributes["implements"].nil?
74
+ entity.extends = entity_attributes["extends"]
75
+
76
+ entity_xml.find("field").each do |field_xml|
77
+ field = FieldModel.new
78
+ field_attributes = field_xml.attributes
79
+ field.name = field_attributes["name"]
80
+ field.type = field_attributes["type"]
81
+ if(field_attributes["xref_field"])
82
+ split = field_attributes["xref_field"].split(".")
83
+ if(split.size == 2)
84
+ field.xref_entity = split[0]
85
+ field.xref_field = split[1]
86
+ else
87
+ field.xref_field = split[0]
88
+ field.xref_entity = field_attributes["xref_entity"]
89
+ end
90
+ end
91
+ entity.fields << field
92
+ end
93
+ module_obj.entities << entity
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: joerivandervelde-molgenis-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Morris Swertz
8
+ - Joeri van der Velde
9
+ autorequire: ""
10
+ bindir: bin
11
+ cert_chain:
12
+ date: 2009-08-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: libxml-ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: darkfish-rdoc
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.5
44
+ version:
45
+ description: This gem has simple classes to allow parsing and visualization of MOLGENIS datamodels.
46
+ email: m.a.swertz@rug.nl
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ - LICENCE
54
+ files:
55
+ - lib/molgenis_dot.rb
56
+ - lib/molgenis_model.rb
57
+ - lib/molgenis_parser.rb
58
+ - README.rdoc
59
+ - LICENCE
60
+ has_rdoc: true
61
+ homepage: http://gbic.target.rug.nl/trac/molgenis
62
+ licenses:
63
+ post_install_message:
64
+ rdoc_options:
65
+ - -N
66
+ - --tab-width=2
67
+ - --main=README.rdoc
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.0.1
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.5
86
+ signing_key:
87
+ specification_version: 1
88
+ summary: A Ruby implementation of the interaction of MOLGENIS datamodels (XML).
89
+ test_files: []
90
+