rdf2json 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b7bc9157133dd33407d3807be8d4e2ae8361424
4
- data.tar.gz: 4f22bddd6f50b8708d289f6699eaee564d7a0afe
3
+ metadata.gz: 229b623b98cb1edf2917e919f28cedaaa40d4405
4
+ data.tar.gz: e8b2debf2eceff26846ff3e9e1b549f3c188e1b9
5
5
  SHA512:
6
- metadata.gz: 4c0697837463e626dfc077ba4a0cd27ee7240fe6c3fcfdde29a3708edbf83689901e25f92ae266a8fe9a840fe34f6839c4363502b647fe207ef0fa2042908bb0
7
- data.tar.gz: ece185939cd4925b52632ca346653486905b91f185852845e5081dab6ca670de61df858795c2cbad5683bd2ebfaac23f845842185ac323412966ab8afb918b91
6
+ metadata.gz: fa6329cafa516402423d0f2f4eaef39f0021951951cb4ec8db4034b03338b5e9c4967499fb75aa9068c82b32aae95fb73f82777c738cf702dc3255800e918613
7
+ data.tar.gz: 74b64a2375e9274e24da1c8b3560fcaffb9b0264b4218ed688f14b095ad948642c9ca92f6e87124d09bc0d1873741598e6b95a38646c75fde2b2e696ffe0681c
data/README.md CHANGED
@@ -8,6 +8,20 @@ output file.
8
8
 
9
9
  Usage: `rdf2json [options] --input filename.nt --output filename.json`
10
10
 
11
+ #### Preliminaries
12
+
13
+ RDF N-Triples/N-Quads need to be sorted by subject, so that
14
+ it is possible to output JSON/JSON-LD documents on-the-fly,
15
+ without holding the entire input in memory or falling back to
16
+ time consuming file-pointer seek operations.
17
+
18
+ Both RDF formats can be sorted on Mac OS X and Linux using the
19
+ following shell command:
20
+
21
+ ```sh
22
+ sort -k 1,1 UNSORTED.EXT > SORTED.EXT
23
+ ```
24
+
11
25
  #### Required options
12
26
 
13
27
  * `-i`, `--input FILE`: Input file for the conversion; either RDF N-Triples or N-Quads.
@@ -25,6 +39,16 @@ Usage: `rdf2json [options] --input filename.nt --output filename.json`
25
39
 
26
40
  * `-h`, `--help`: Show this message.
27
41
 
42
+ #### JSON output (`--minimize` option)
43
+
44
+ * replaces "@id" keys with an alternative name if the `--namespace` option is present
45
+ * keys that start with the prefix of `--prefix` are shortened (prefix is removed)
46
+ * array contents are "lifted up", i.e. for each entry of the array:
47
+ * hashes with a "@value" key are replaced by the value of "@value", or else
48
+ * hashes with a "@id" key are replaced by the value of "@id", or else
49
+ * the array value is left unchanged
50
+ * removes all "@type" key/value pairs
51
+
28
52
  ## Installation
29
53
 
30
54
  ```sh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,8 +5,13 @@ require 'rdf/nquads'
5
5
  require 'json/ld'
6
6
  require 'optparse'
7
7
 
8
+ # Module that contains a class for transforming RDF N-Triples/N-Quads into
9
+ # JSON/JSON-LD as well as a command line interface implementation for user
10
+ # interactions.
8
11
  module RDF2JSON
9
12
 
13
+ # Command line interface; reads parameters, outputs help, or proceeds with the
14
+ # transformation of RDF N-Triples/N-Quads into JSON/JSON-LD.
10
15
  def self.cli
11
16
  options = {}
12
17
 
@@ -18,6 +23,13 @@ def self.cli
18
23
  opts.separator ' append a JSON/JSON-LD document per line in a designated'
19
24
  opts.separator ' output file.'
20
25
  opts.separator ''
26
+ opts.separator 'Notes:'
27
+ opts.separator ' Sorting on Mac OS X & Linux:'
28
+ opts.separator ' sort -k 1,1 UNSORTED.EXT > SORTED.EXT'
29
+ opts.separator ''
30
+ opts.separator ' More information on the --minimize parameter:'
31
+ opts.separator ' https://github.com/joejimbo/rdf2json'
32
+ opts.separator ''
21
33
  opts.separator 'Required:'
22
34
 
23
35
  opts.on('-i', '--input FILE', 'Input file for the conversion; either RDF N-Triples or N-Quads.') { |file|
@@ -118,8 +130,19 @@ def self.cli
118
130
  end
119
131
  end
120
132
 
133
+ # Class that takes an input file (RDF N-Triples/N-Quads) and appends JSON/JSON-LD to
134
+ # a possible pre-existing output file. A namespace and prefix can be given that handle
135
+ # `--namespace` and `--prefix` parameters in conjunction with the `--minimize` parameter.
121
136
  class Converter
122
137
 
138
+ # Initializes a new converter instance.
139
+ #
140
+ # +input_filename+:: path/filename of the input file in RDF N-Triples/N-Quads
141
+ # +output_filename+:: path/filename of the output file to which JSON/JSON-LD is being appended
142
+ # +input_format+:: format of the input file (:ntriples or :nquads)
143
+ # +output_format+:: format of the output (:json or jsonld)
144
+ # +namespace+:: a possible namespace for replacing "@id" keys (may be nil)
145
+ # +prefix+:: a possible prefix for shortening keys (may be nil)
123
146
  def initialize(input_filename, output_filename, input_format, output_format, namespace, prefix)
124
147
  @input_file = File.open(input_filename, 'r')
125
148
  @output_file = File.open(output_filename, 'a')
@@ -129,6 +152,12 @@ class Converter
129
152
  @prefix = prefix
130
153
  end
131
154
 
155
+ # Convert the input file by appending the newly formatted data to the output file.
156
+ #
157
+ # At the end of the conversion a short statistic is output. It tells the number of
158
+ # lines read from the input file, the number of errors in the N-Triples/N-Quads file,
159
+ # the number of JSON/JSON-LD documents appended to the output file (equiv. to number
160
+ # of lines appended).
132
161
  def convert
133
162
  no_of_lines = 0
134
163
  no_of_statements = 0
@@ -163,6 +192,9 @@ class Converter
163
192
  puts "JSON/JSON-LD documents output : #{no_of_statements}"
164
193
  end
165
194
 
195
+ # Minimize a JSON-LD hash to JSON.
196
+ #
197
+ # +jsonld_hash+:: a JSON-LD hash that should be rewritten to plain JSON
166
198
  def minify(jsonld_hash)
167
199
  jsonld_hash.keys.each { |key|
168
200
  if key == '@type' then
@@ -187,9 +219,14 @@ class Converter
187
219
  }
188
220
  end
189
221
 
222
+ # Takes a block of RDF statements that share the same subject and creates
223
+ # a JSON/JSON-LD document from them, which is appended to the output file.
224
+ #
225
+ # +block+:: one or more lines that share the same subject in RDF N-Triples/N-Quads
190
226
  def write_graph(block)
191
227
  return { :read_errors => 0, :no_of_statements => 0 } unless block and not block.empty?
192
228
 
229
+ # Virtuoso output error-handling:
193
230
  block.gsub!("\\'", "'")
194
231
 
195
232
  read_errors = 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joachim Baran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -117,14 +117,12 @@ extensions: []
117
117
  extra_rdoc_files:
118
118
  - LICENSE.txt
119
119
  - README.md
120
- - README.rdoc
121
120
  files:
122
121
  - .document
123
122
  - .travis.yml
124
123
  - Gemfile
125
124
  - LICENSE.txt
126
125
  - README.md
127
- - README.rdoc
128
126
  - Rakefile
129
127
  - VERSION
130
128
  - lib/rdf2json.rb
data/README.rdoc DELETED
@@ -1,48 +0,0 @@
1
- = bio-rdf2json
2
-
3
- {<img
4
- src="https://secure.travis-ci.org/joejimbo/bioruby-rdf2json.png"
5
- />}[http://travis-ci.org/#!/joejimbo/bioruby-rdf2json]
6
-
7
- Full description goes here
8
-
9
- Note: this software is under active development!
10
-
11
- == Installation
12
-
13
- gem install bio-rdf2json
14
-
15
- == Usage
16
-
17
- == Developers
18
-
19
- To use the library
20
-
21
- require 'bio-rdf2json'
22
-
23
- The API doc is online. For more code examples see also the test files in
24
- the source tree.
25
-
26
- == Project home page
27
-
28
- Information on the source tree, documentation, issues and how to contribute, see
29
-
30
- http://github.com/joejimbo/bioruby-rdf2json
31
-
32
- The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
33
-
34
- == Cite
35
-
36
- If you use this software, please cite one of
37
-
38
- * [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
39
- * [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
40
-
41
- == Biogems.info
42
-
43
- This Biogem is published at http://biogems.info/index.html#bio-rdf2json
44
-
45
- == Copyright
46
-
47
- Copyright (c) 2014 Joachim Baran. See LICENSE.txt for further details.
48
-