biointerchange 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.travis.yml +3 -3
  2. data/Gemfile +2 -1
  3. data/README.md +192 -7
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/examples/vocabulary.rb +23 -0
  7. data/generators/javaify.rb +131 -0
  8. data/generators/pythonify.rb +67 -0
  9. data/generators/rdfxml.rb +152 -44
  10. data/lib/biointerchange/core.rb +2 -1
  11. data/lib/biointerchange/exceptions.rb +27 -0
  12. data/lib/biointerchange/genomics/gff3_rdf_ntriples.rb +21 -18
  13. data/lib/biointerchange/gff3o.rb +495 -0
  14. data/lib/biointerchange/gvf1o.rb +730 -0
  15. data/lib/biointerchange/registry.rb +2 -2
  16. data/lib/biointerchange/sio.rb +10951 -5845
  17. data/lib/biointerchange/sofa.rb +2171 -1300
  18. data/spec/exceptions_spec.rb +6 -0
  19. data/spec/gff3_rdfwriter_spec.rb +7 -1
  20. data/spec/text_mining_pdfx_xml_reader_spec.rb +6 -0
  21. data/spec/text_mining_pubannos_json_reader_spec.rb +6 -0
  22. data/spec/text_mining_rdfwriter_spec.rb +6 -0
  23. data/supplemental/java/biointerchange/pom.xml +45 -0
  24. data/supplemental/java/biointerchange/src/main/java/org/biointerchange/App.java +58 -0
  25. data/supplemental/java/biointerchange/src/main/java/org/biointerchange/AppSIO.java +49 -0
  26. data/supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/GFF3O.java +647 -0
  27. data/supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/GVF1O.java +946 -0
  28. data/supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/SIO.java +15390 -0
  29. data/supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/SOFA.java +2968 -0
  30. data/supplemental/java/biointerchange/src/test/java/org/biointerchange/AppTest.java +38 -0
  31. data/supplemental/python/biointerchange/__init__.py +4 -0
  32. data/supplemental/python/biointerchange/gff3o.py +581 -0
  33. data/supplemental/python/biointerchange/gvf1o.py +864 -0
  34. data/supplemental/python/biointerchange/sio.py +11772 -0
  35. data/supplemental/python/biointerchange/sofa.py +2422 -0
  36. data/supplemental/python/example.py +19 -0
  37. data/supplemental/python/setup.py +13 -0
  38. data/web/about.html +3 -0
  39. data/web/api.html +219 -0
  40. data/web/index.html +4 -3
  41. data/web/ontologies.html +109 -0
  42. data/web/webservices.html +1 -0
  43. metadata +144 -117
  44. data/docs/exceptions_readme.txt +0 -13
  45. data/lib/biointerchange/gff3.rb +0 -135
data/.travis.yml CHANGED
@@ -4,9 +4,9 @@ rvm:
4
4
  - 1.9.3
5
5
  - jruby-19mode # JRuby in 1.9 mode
6
6
  - rbx-19mode
7
- # - 1.8.7
8
- # - jruby-18mode # JRuby in 1.8 mode
9
- # - rbx-18mode
7
+ - 1.8.7
8
+ - jruby-18mode # JRuby in 1.8 mode
9
+ - rbx-18mode
10
10
 
11
11
  # uncomment this line if your project needs to run something other than `rake`:
12
12
  # script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -5,12 +5,13 @@ source "http://rubygems.org"
5
5
  gem "rdf", ">= 0.3.4.1"
6
6
  gem "json", ">= 1.6.4"
7
7
  gem "getopt", ">= 1.4.1"
8
+ gem "addressable", ">= 2.3.2"
8
9
 
9
10
  # Add dependencies to develop your gem here.
10
11
  # Include everything needed to run rake, tests, features, etc.
11
12
  group :development do
12
13
  gem "rspec", "~> 2.8.0"
13
- gem "bundler", "~> 1.2.1"
14
+ gem "bundler", ">= 1.1.5"
14
15
  gem "jeweler", "~> 1.8.4"
15
16
  gem "bio", ">= 1.4.2"
16
17
  gem "rdoc", "~> 3.12"
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  BioInterchange
2
2
  ==============
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/joejimbo/bioruby-biointerchange.png)](http://travis-ci.org/joejimbo/bioruby-biointerchange)
4
+ [![Build Status](https://secure.travis-ci.org/BioInterchange/BioInterchange.png?branch=master)](https://travis-ci.org/BioInterchange/BioInterchange)
5
5
 
6
6
  BioInterchange is a tool for generating interchangable RDF from non-RDF data sources.
7
7
 
@@ -16,7 +16,10 @@ Supported RDF output formats:
16
16
 
17
17
  Ontologies used in the RDF output:
18
18
 
19
+ * [Generic Feature Format Version 3 Ontology](http://www.biointerchange.org/ontologies.html) (GFF3O)
20
+ * [Genome Variation Format Version 1 Ontology](http://www.biointerchange.org/ontologies.html) (GVF1O)
19
21
  * [Semanticscience Integrated Ontology](http://code.google.com/p/semanticscience/wiki/SIO) (SIO)
22
+ * [Sequence Ontology Feature Annotation](http://www.sequenceontology.org/index.html) (SOFA)
20
23
 
21
24
  Usage
22
25
  -----
@@ -24,7 +27,7 @@ Usage
24
27
  Four interfaces to BioInterchange are available:
25
28
 
26
29
  1. command-line tool-suite
27
- 2. Ruby API/Ruby gem
30
+ 2. API (Ruby gem, Python egg)
28
31
  3. RESTful web-service
29
32
  4. interactive web-site
30
33
 
@@ -53,7 +56,9 @@ Output formats:
53
56
  * `rdf.bh12.sio`
54
57
 
55
58
 
56
- ### Ruby API/Ruby gem
59
+ ### Application Programming Interface
60
+
61
+ #### Ruby
57
62
 
58
63
  The Ruby gem is under active development, so the following may or may not work out of the box.
59
64
 
@@ -63,6 +68,120 @@ To use BioInterchange in your Ruby projects, include the following line in your
63
68
 
64
69
  require 'biointerchange'
65
70
 
71
+ #### Python
72
+
73
+ Currently, there are only wrappers to the vocabularies of the ontologies that are used by
74
+ BioInterchange available.
75
+
76
+ To install the BioInterchange egg, run:
77
+
78
+ sudo easy_install rdflib
79
+ sudo easy_install http://www.biointerchange.org/eggs/biointerchange-0.1.2-py2.7.egg
80
+
81
+ Usage examples:
82
+
83
+ import biointerchange
84
+ from biointerchange import *
85
+
86
+ # Get the URI of an ontology term by label:
87
+ GFF3O.seqid()
88
+
89
+ # Ambiguous labels will return an array of URIs:
90
+ # "start" can refer to a sub-property of "feature_properties" or "target_properties"
91
+ GFF3O.start()
92
+ # "feature_properties" can be either a datatype or object property
93
+ GFF3O.feature_properties()
94
+
95
+ # Use build-in method "is_datatype_property" to resolve ambiguity:
96
+ # (Note: there is exactly one item in the result set, so the selection of the first item is acceptable.)
97
+ feature_properties = filter(lambda uri: GFF3O.is_datatype_property(uri), GFF3O.feature_properties())[0]
98
+
99
+ # Use build-in method "with_parent" to pick properties based on their context:
100
+ GFF3O.with_parent(GFF3O.start(), feature_properties)
101
+
102
+ #### Java
103
+
104
+ Only vocabulary wrapper classes are provided for the Java API. In order to make use of the RDF generation features in BioInterchange, either use the Ruby implementation or connect Java to BioInterchange's web-services.
105
+
106
+ To use the BioInterchange artifact, set-up add the following to your Maven POM file:
107
+
108
+ <repositories>
109
+ <repository>
110
+ <id>biointerchange</id>
111
+ <name>BioInterchange</name>
112
+ <url>http://www.biointerchange.org/artifacts</url>
113
+ </repository>
114
+ </repositories>
115
+
116
+ <dependencies>
117
+ <dependency>
118
+ <groupId>org.biointerchange</groupId>
119
+ <artifactId>vocabularies</artifactId>
120
+ <version>0.1.2</version>
121
+ </dependency>
122
+ </dependencies>
123
+
124
+ Usage examples:
125
+
126
+ package org.biointerchange;
127
+
128
+ import com.hp.hpl.jena.rdf.model.*;
129
+ import com.hp.hpl.jena.vocabulary.*;
130
+ import org.apache.commons.collections.CollectionUtils;
131
+ import org.apache.commons.collections.Predicate;
132
+
133
+ import java.util.Set;
134
+
135
+ import org.biointerchange.vocabulary.*;
136
+
137
+ /**
138
+ * Demo on how to make use of BioInterchange's vocabulary classes.
139
+ *
140
+ * @author Joachim Baran
141
+ */
142
+ public class App
143
+ {
144
+ public static void main(String[] args) {
145
+ Resource seqid = GFF3O.seqid();
146
+ System.out.println("'seqid' property:");
147
+ printResource(seqid);
148
+
149
+ System.out.println("'start' properties:");
150
+ Set<Resource> start = GFF3O.start();
151
+ for (Resource startSynonym : start)
152
+ printResource(startSynonym);
153
+
154
+ System.out.println("'feature_properties' properties:");
155
+ Set<Resource> featureProperties = GFF3O.feature_properties();
156
+ for (Resource featurePropertiesSynonym : featureProperties)
157
+ printResource(featurePropertiesSynonym);
158
+
159
+ System.out.println("'feature_properties' properties, which are a datatype property:");
160
+ CollectionUtils.filter(featureProperties, new Predicate() {
161
+ public boolean evaluate(Object o) {
162
+ return GFF3O.isDatatypeProperty((Resource)o);
163
+ }
164
+ });
165
+ for (Resource featurePropertiesSynonym : featureProperties)
166
+ printResource(featurePropertiesSynonym);
167
+
168
+ System.out.println("'start' property with parent datatype property 'feature_properties':");
169
+ Set<Resource> startUnderDatatypeFeatureProperties = GFF3O.withParent(start, featureProperties.iterator().next());
170
+ for (Resource startSynonym : startUnderDatatypeFeatureProperties)
171
+ printResource(startSynonym);
172
+ }
173
+
174
+ private static void printResource(Resource resource) {
175
+ System.out.println(" " + resource.toString());
176
+ System.out.println(" Namespace: " + resource.getNameSpace());
177
+ System.out.println(" Local name: " + resource.getLocalName());
178
+ System.out.println(" Jena Property (rather than Resource): " + (resource instanceof Property));
179
+ System.out.println(" Ontology class: " + GFF3O.isClass(resource));
180
+ System.out.println(" Ontology object property: " + GFF3O.isObjectProperty(resource));
181
+ System.out.println(" Ontology datatype property: " + GFF3O.isDatatypeProperty(resource));
182
+ }
183
+ }
184
+
66
185
  ### RESTful Web-Service
67
186
 
68
187
  TODO
@@ -78,13 +197,34 @@ This section is only relevant if you are building newer versions of BioInterchan
78
197
 
79
198
  Note that the following set-up only works with Ruby 1.9.2p290 or newer.
80
199
 
200
+ ### Prerequisites
201
+
202
+ Software requirements:
203
+
204
+ * Ruby 1.9.2p290 or newer
205
+ * Bundler gem 1.1.5 or newer
206
+ * Rake gem 0.8.7 or newer
207
+
208
+ With Ruby installed, the following commands install the additional packages:
209
+
210
+ sudo gem install bundler
211
+ sudo gem install rake
212
+ bundle
213
+
214
+ The last step, `bundle`, will install gem dependencies of BioInterchange automatically.
215
+
216
+ ### Building Vocabulary Classes
217
+
81
218
  Building a new version of the Ruby vocabulary classes for GFF3, SIO, SOFA (requires that the OBO files are saves as RDF/XML using [Protege](http://protege.stanford.edu)):
82
219
 
83
220
  sudo gem install rdf
84
221
  sudo gem install rdf-rdfxml
85
- echo -e "module BioInterchange\n" > lib/biointerchange/gff3.rb
86
- ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gff3> GFF3 >> lib/biointerchange/gff3.rb
87
- echo -e "\nend" >> lib/biointerchange/gff3.rb
222
+ echo -e "require 'rdf'\nmodule BioInterchange\n" > lib/biointerchange/gff3o.rb
223
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gff3o> GFF3O >> lib/biointerchange/gff3o.rb
224
+ echo -e "\nend" >> lib/biointerchange/gff3o.rb
225
+ echo -e "module BioInterchange\n" > lib/biointerchange/gvf1o.rb
226
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gvf1o> GVF1O >> lib/biointerchange/gvf1o.rb
227
+ echo -e "\nend" >> lib/biointerchange/gvf1o.rb
88
228
  echo -e "module BioInterchange\n" > lib/biointerchange/sio.rb
89
229
  ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-sio> SIO >> lib/biointerchange/sio.rb
90
230
  echo -e "\nend" >> lib/biointerchange/sio.rb
@@ -92,6 +232,50 @@ Building a new version of the Ruby vocabulary classes for GFF3, SIO, SOFA (requi
92
232
  ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-sofa> SOFA >> lib/biointerchange/sofa.rb
93
233
  echo -e "\nend" >> lib/biointerchange/sofa.rb
94
234
 
235
+ #### Python Vocabulary Classes
236
+
237
+ The source-code generation can be skipped, if none of the ontologies that are used by BioInterchange have been changed. Otherwise, the existing Python vocabulary class wrappers can be generated as follows:
238
+
239
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gff3o> GFF3O | ruby generators/pythonify.rb > supplemental/python/biointerchange/gff3o.py
240
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gvf1o> GVF1O | ruby generators/pythonify.rb > supplemental/python/biointerchange/gvf1o.py
241
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-sio> SIO | ruby generators/pythonify.rb > supplemental/python/biointerchange/sio.py
242
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-sofa> SOFA | ruby generators/pythonify.rb > supplemental/python/biointerchange/sofa.py
243
+
244
+ Generate the BioInterchange Python vocabulary egg:
245
+
246
+ cd supplemental/python
247
+ python setup.py bdist_egg
248
+
249
+ ##### Required Python Library
250
+
251
+ The vocabulary wrapper makes used of RDFLib, which does not install automatically with the egg.
252
+
253
+ * (RDFLib)[https://github.com/RDFLib/rdflib]
254
+
255
+ #### Java Vocabulary Classes
256
+
257
+ The source-code generation can be skipped, if none of the ontologies that are used by BioInterchange have been changed. Otherwise, the existing Java vocabulary class wrappers can be generated as follows:
258
+
259
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gff3o> GFF3O | ruby generators/javaify.rb > supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/GFF3O.java
260
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-gvf1o> GVF1O | ruby generators/javaify.rb > supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/GVF1O.java
261
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-sio> SIO | ruby generators/javaify.rb > supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/SIO.java
262
+ ruby generators/rdfxml.rb <path-to-rdf/xml-version-of-sofa> SOFA | ruby generators/javaify.rb "http://purl.obolibrary.org/obo/" > supplemental/java/biointerchange/src/main/java/org/biointerchange/vocabulary/SOFA.java
263
+
264
+ Generate the BioInterchange Java vocabulary artifact:
265
+
266
+ cd supplemental/java/biointerchange
267
+ mvn package
268
+
269
+ ##### Required Java Packages
270
+
271
+ The following Java packages will automatically install alongside BioInterchange's Maven artifact:
272
+
273
+ * (Jena Core)[http://mvnrepository.com/artifact/org.apache.jena/jena-core]
274
+ * (Apache Commons Collections)[http://mvnrepository.com/artifact/org.apache.directory.studio/org.apache.commons.collections]
275
+ * (SLF4J)[http://mvnrepository.com/artifact/org.slf4j/slf4j-api]
276
+ * (Xerces)[http://mvnrepository.com/artifact/xerces/xerces]
277
+ * (JUnit)[http://mvnrepository.com/artifact/junit/junit]
278
+
95
279
  ### Gem Bundling/Installing
96
280
 
97
281
  sudo bundle exec rake install
@@ -106,6 +290,7 @@ BioInterchange uses unit testing using [RSpec](http://rspec.info), where the uni
106
290
 
107
291
  Using bundler, a quick check can be carried out using:
108
292
 
293
+ bundle update
109
294
  bundle exec rake spec
110
295
 
111
296
  A more verbose is produced by calling `rspec` directly:
@@ -129,7 +314,6 @@ This can be solved by executing:
129
314
 
130
315
  sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
131
316
 
132
-
133
317
  Contributors
134
318
  ------------
135
319
 
@@ -139,6 +323,7 @@ In alphabetical order of the last name:
139
323
  * [Kevin B. Cohen](http://compbio.ucdenver.edu/Hunter_lab/Cohen/index.shtml)
140
324
  * [Geraint Duck](http://www.cs.man.ac.uk/~duckg)
141
325
  * [Michel Dumontier](http://dumontierlab.com)
326
+ * [Jin-Dong Kim](http://www.bioontology.org/Jin-Dong_Kim)
142
327
 
143
328
  Cite
144
329
  ----
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.summary = %Q{An open source framework for transforming heterogeneous data formats into RDF.}
21
21
  gem.description = %Q{BioInterchange is a Ruby gem, command-line tool, web-service for turning heterogeneous data formats such as JSON, XML, GFF3, etc., into RDF."}
22
22
  gem.email = "joachim.baran@gmail.com"
23
- gem.authors = ["Joachim Baran", "Kevin B. Cohen", "Geraint Duck", "Michel Dumontier"]
23
+ gem.authors = ["Joachim Baran", "Kevin B. Cohen", "Geraint Duck", "Michel Dumontier", "Jin-Dong Kim"]
24
24
  gem.executable = 'biointerchange'
25
25
  # dependencies defined in Gemfile
26
26
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'biointerchange'
5
+
6
+ include BioInterchange
7
+
8
+ # Get the URI of an ontology term by label:
9
+ GFF3O.seqid()
10
+
11
+ # Ambiguous labels will return an array of URIs:
12
+ # "start" can refer to a sub-property of "feature_properties" or "target_properties"
13
+ GFF3O.start()
14
+ # "feature_properties" can be either a datatype or object property
15
+ GFF3O.feature_properties()
16
+
17
+ # Use build-in method "is_datatype_property" to resolve ambiguity:
18
+ # (Note: there is exactly one item in the result set, so the selection of the first item is acceptable.)
19
+ feature_properties = GFF3O.feature_properties().select { |uri| GFF3O.is_datatype_property(uri) }[0]
20
+
21
+ # Use build-in method "with_parent" to pick properties based on their context:
22
+ GFF3O.with_parent(GFF3O.start(), feature_properties)
23
+
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/ruby
2
+
3
+ private_scope = false
4
+ java_class = nil
5
+ namespace = nil
6
+ comment = nil
7
+
8
+ if ARGV.length == 1 then
9
+ namespace = ARGV[0]
10
+ end
11
+
12
+ cls = ''
13
+
14
+ puts 'package org.biointerchange.vocabulary;'
15
+ puts ''
16
+ puts 'import java.util.Arrays;'
17
+ puts 'import java.util.Map;'
18
+ puts 'import java.util.HashMap;'
19
+ puts 'import java.util.HashSet;'
20
+ puts 'import java.util.Set;'
21
+ puts 'import com.hp.hpl.jena.rdf.model.Property;'
22
+ puts 'import com.hp.hpl.jena.rdf.model.Resource;'
23
+ puts 'import com.hp.hpl.jena.rdf.model.ResourceFactory;'
24
+ puts 'import org.apache.commons.collections.CollectionUtils;'
25
+ puts 'import org.apache.commons.collections.Predicate;'
26
+ puts ''
27
+
28
+ STDIN.each { |line|
29
+ line.chomp!
30
+
31
+ if line.match('http://') then
32
+ if line.match(/http:\/\/[^'")]+#[^'")]+/) then
33
+ namespace = line.scan(/http:\/\/[^'")]+/)[0].sub(/(#).*$/, '\1') unless namespace
34
+ else
35
+ namespace = line.scan(/http:\/\/[^'")]+/)[0].sub(/\/[^\/]+$/, '/') unless namespace
36
+ end
37
+ if line.match("#{namespace}\w+") then
38
+ line.gsub!(namespace, '') unless line.strip.start_with?('#')
39
+ end
40
+ end
41
+
42
+ if line.start_with?('class') then
43
+ java_class = line.sub(/^.* /, '')
44
+ transduction = "public class #{java_class} {"
45
+ elsif line.strip.start_with?('def ') then
46
+ leading_spaces = line.gsub(/[^ ].*$/, '')
47
+ transduction = ''
48
+ if comment then
49
+ transduction << "#{("/**\n *" + comment).gsub(/^/, "#{leading_spaces}")}\n#{leading_spaces} */\n"
50
+ comment = nil
51
+ end
52
+ transduction << " public static #{line.sub('?', '').sub(/self\./, '').sub(/ *def\ /, '')}"
53
+ method_name = transduction.sub(/^.*public static /m, '').sub(/(\(.*)?$/, '')
54
+ transduction.sub!("public static #{method_name}", "public static _#{method_name}_") if method_name.match(/^(true|false|class|public|private|static|return|if|while|do|clone|equals|toString|hashCode)$/)
55
+ variables = transduction.scan(/^\s*public static \w+\((.+)\)$/)
56
+ variables = variables[0][0].split(',').map { |variable| variable.strip } if variables.length > 0
57
+ if method_name == 'is_object_property' then
58
+ transduction.sub!(/public static .*$/, "public static boolean isObjectProperty(Resource #{variables[0]})")
59
+ elsif method_name == 'is_datatype_property' then
60
+ transduction.sub!(/public static .*$/, "public static boolean isDatatypeProperty(Resource #{variables[0]})")
61
+ elsif method_name == 'is_class' then
62
+ transduction.sub!(/public static .*$/, "public static boolean isClass(Resource #{variables[0]})")
63
+ elsif method_name == 'is_named_individual' then
64
+ transduction.sub!(/public static .*$/, "public static boolean isNamedIndividual(Resource #{variables[0]})")
65
+ elsif method_name == 'with_parent' then
66
+ transduction.sub!(/public static .*$/, "public static Set<Resource> withParent(Set<Resource> #{variables[0]}, final Resource #{variables[1]})")
67
+ elsif method_name == 'has_parent' then
68
+ transduction.sub!(/public static .*$/, "public static boolean hasParent(Resource #{variables[0]}, Resource #{variables[1]})")
69
+ else
70
+ if transduction.match(/\/\*\*[^E]*Either:.*Or:/m) or transduction.match(/\/\*\*[^A]*Ambiguous label\./) then
71
+ transduction.sub!(/public static /, 'public static Set<Resource> ')
72
+ else
73
+ transduction.sub!(/public static /, 'public static Resource ')
74
+ end
75
+ end
76
+ transduction << '()' unless transduction.end_with?(")")
77
+ transduction << ' {'
78
+ elsif line.strip.start_with?('#') then
79
+ unless comment then
80
+ comment = line.strip.sub(/^# ?/, ' ')
81
+ else
82
+ comment << "\n#{line.strip.gsub(/^# ?/, ' * ').gsub(/\+([^+]+)\+::/, '@param \1')}"
83
+ end
84
+ transduction = nil
85
+ elsif line.strip.start_with?('end') then
86
+ transduction = line.sub(/end/, '}')
87
+ elsif line.strip.start_with?('if ') or line.strip.start_with?('elsif') then
88
+ transduction = "#{line.sub(/ then$/, '').sub('elsif', 'else if').gsub('@@', '__').gsub(/RDF::URI\.new\(([^)]+)\)/, "_namespace_#{java_class}(\\1)").gsub(/(\w)\?\(/, '\1(')}".gsub(/\.has_key\(([^)]+)\)/, '.containsKey(\1)').gsub(/\[([^\]]+)\]/, '.get(\1)')
89
+ if transduction.match(/if ([^=]+|_namespace_[^=]+) ?== ?([^_].*|_namespace_.*)/)
90
+ transduction.sub!(/if ([^= ]+) ?== ?(\S+)\s+$/, 'if \1.equals(\2)')
91
+ transduction.sub!(/_namespace_\w+\('(\w+)'\)/, "\"#{namespace}\\1\"")
92
+ end
93
+ transduction.sub!(/\.equals\(("[^"]+")\)/, '.equals(ResourceFactory.createResource(\1))')
94
+ transduction.sub!(/if /, 'if (')
95
+ transduction.sub!(/$/, ') {')
96
+ elsif line.strip.start_with?('return [') then
97
+ transduction = line.sub(/return \[/, 'return new HashSet<Resource>(Arrays.asList(new Resource[] {').sub(/\]$/, '}));').gsub(/RDF::URI\.new\(([^)]+)\)/, "_namespace_#{java_class}(\\1)")
98
+ elsif line.strip.start_with?('private') then
99
+ private_scope = true
100
+ transduction = " private static Resource _namespace_#{java_class}(String accession) {\n"
101
+ transduction << " if (isClass(ResourceFactory.createResource(\"#{namespace}\" + accession))) {\n"
102
+ transduction << " return ResourceFactory.createResource(\"#{namespace}\" + accession);\n"
103
+ transduction << " } else {\n"
104
+ transduction << " return ResourceFactory.createProperty(\"#{namespace}\" + accession);\n"
105
+ transduction << " }\n"
106
+ transduction << " }\n\n"
107
+ else
108
+ transduction = line.gsub('@@', '__').gsub(/RDF::URI\.new\(([^)]+)\)/, "_namespace_#{java_class}(\\1)").gsub(/(\w+)\.select ?\{ ?\|(\w+)\| ?(.*[^ ]) ?\}/, 'new HashSet<Resource>(CollectionUtils.select(\1, new Predicate() { public boolean evaluate(Object \2) { return \3; } }))').gsub(/(\w)\?\(/, '\1(').gsub('has_parent(', 'hasParent((Resource)').gsub(/\[([^\]]+)\]/, '.get(\1)')
109
+ transduction.gsub!('__', '__') unless line.strip.start_with?('@@')
110
+ transduction << ';' unless line.strip.empty?
111
+ end
112
+
113
+ if transduction and transduction.strip.start_with?('__') then
114
+ variable = transduction.scan(/__\w+/)[0]
115
+ map = {}
116
+ map = Hash[*transduction.sub(/^.* \{/, '').sub(/\};/, '').split(',').map { |assignment| assignment.split('=>').map { |kv| kv.strip } }.flatten.map { |function| if function.match(/'\w+'/) then "#{namespace}#{function.scan(/'\w+'/)[0].gsub(/'/, '')}" else nil end }.compact ] if transduction.match(/\{\s*\S+.*\}/)
117
+ transduction = " private static Map<Resource, Resource> #{variable} = _init_#{variable}();\n\n"
118
+ transduction << " private static Map<Resource, Resource> _init_#{variable}() {\n"
119
+ transduction << " Map<Resource, Resource> map = new HashMap<Resource, Resource>();\n\n"
120
+ map.each_pair { |key, value| transduction << " map.put(ResourceFactory.createResource(\"#{key}\"), ResourceFactory.createResource(\"#{value}\"));\n" }
121
+ transduction << "\n"
122
+ transduction << " return map;\n"
123
+ transduction << " }\n"
124
+ end
125
+
126
+ cls << "#{transduction}\n".gsub(/'/, '"') if transduction
127
+
128
+ }
129
+
130
+ puts cls
131
+