tao_rdfizer 0.10.2 → 0.11.0

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
  SHA256:
3
- metadata.gz: 112cb7c3d78d77ca2df491e26f05eeb52334ed291483bb6bfa586bf707304608
4
- data.tar.gz: e4bbdf5b014fed6779dc79f3b786a2d9d066a2a4dd9a8a1e8a87dec466d908ae
3
+ metadata.gz: ce27142842502109c882dc01222a5aa8e402f21c9305bcd5797a712dde5a0f8b
4
+ data.tar.gz: 8b542b1d3d4992e1129fa95cde633967bb55e805d7ed69fc36cb95940215004f
5
5
  SHA512:
6
- metadata.gz: a291bf21a29a638ec0c3b42b16ff06e7530a8d7245965fb0901f7b4452358d6ecc7876a89c8d8c244a89fb7f47276c9105fb9b301311c09e51b86a5c0e1576dd
7
- data.tar.gz: ad6a621f7a38146ee0ca0eccaa1b2c709a315b2d39bd000c801c4249f7fee0ecf22600fef4ff8baeb6160cf155e4fa033034d4aff5fa1d0d8cf4e9b78d16a5c8
6
+ metadata.gz: 65aecd55bf6fbd609565800231c8f87cad533bc25422912927ef9293e4e7e03bcab6bb5fd639320bf184cd7f0b0aa5de9c5a880734e768f6830761b5eaa6afec
7
+ data.tar.gz: ef195ea7ddae0dfa1409659066e5700369659d08fd40390c85f3384c3476ca44defd9c8eee602d6ebb5ef0dc75d63894a76fc5f597d79e57f1bf28598ecd20f5
data/bin/tao_rdfizer CHANGED
@@ -3,6 +3,7 @@ require 'tao_rdfizer'
3
3
  require 'json'
4
4
 
5
5
  mode = nil
6
+ options = {}
6
7
 
7
8
  ## command line option processing
8
9
  require 'optparse'
@@ -17,6 +18,14 @@ optparse = OptionParser.new do |opts|
17
18
  mode = :spans
18
19
  end
19
20
 
21
+ opts.on('-x', '--x-prefixes', 'without prefixes.') do
22
+ options[:with_prefixes] = false
23
+ end
24
+
25
+ opts.on('-o', '--only-prefixes', 'only prefixes.') do
26
+ options[:only_prefixes] = true
27
+ end
28
+
20
29
  opts.on('-h', '--help', 'displays this screen.') do
21
30
  puts opts
22
31
  exit
@@ -34,7 +43,7 @@ begin
34
43
  annotations = JSON.parse File.read(ARGV[0]), :symbolize_names => true
35
44
  annotations = [annotations] unless annotations.class == Array
36
45
  rdfizer = TAO::RDFizer.new(mode)
37
- puts rdfizer.rdfize(annotations)
46
+ puts rdfizer.rdfize(annotations, options)
38
47
  rescue ArgumentError, IOError => e
39
48
  puts e.message
40
49
  end
@@ -14,12 +14,15 @@ class TAO::RDFizer
14
14
  else
15
15
  ERB_ANNOTATIONS_TTL
16
16
  end
17
-
18
17
  @tao_ttl_erb = ERB.new(template, nil, '-')
19
18
  @prefix_ttl_erb = ERB.new(ERB_PREFIXES_TTL, nil, '-')
20
19
  end
21
20
 
22
- def rdfize(annotations_col, with_prefix = true)
21
+ def rdfize(annotations_col, options = nil)
22
+ options ||= {}
23
+ only_prefixes = options.has_key?(:only_prefixes) ? options[:only_prefixes] == true : false
24
+ with_prefixes = options.has_key?(:with_prefixes) ? options[:with_prefixes] == true : true
25
+
23
26
  # check the format
24
27
  annotations_col.each do |annotations|
25
28
  raise "'target' is missing" unless annotations.has_key? :target
@@ -31,6 +34,25 @@ class TAO::RDFizer
31
34
  anns = annotations_col.first
32
35
  anns[:namespaces].each {|n| namespaces[n[:prefix]] = n[:uri]} unless anns[:namespaces].nil?
33
36
 
37
+ prefixes_ttl = @prefix_ttl_erb.result_with_hash(namespaces:namespaces) if only_prefixes || with_prefixes
38
+
39
+ if only_prefixes
40
+ prefixes_ttl
41
+ else
42
+ annotations_ttl = get_annotations_ttl(annotations_col, namespaces)
43
+ if with_prefixes
44
+ prefixes_ttl + annotations_ttl
45
+ else
46
+ annotations_ttl
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def get_annotations_ttl(annotations_col, namespaces)
54
+ anns = annotations_col.first
55
+
34
56
  unless @mode ==:spans
35
57
  raise ArgumentError, "A project name has to be specified." unless anns.has_key?(:project)
36
58
  prefix_for_this = anns[:project].downcase.gsub(/ /, '_')
@@ -65,7 +87,7 @@ class TAO::RDFizer
65
87
  end
66
88
 
67
89
  begin
68
- if @mode == :annotations
90
+ unless @mode == :span
69
91
  # index attributes
70
92
  attributesh = _attributes.inject({}) do |h, a|
71
93
  if a[:pred].end_with?('_id')
@@ -172,13 +194,9 @@ class TAO::RDFizer
172
194
  spans += _spans unless @mode == :annotations
173
195
  end
174
196
 
175
- ttl = ''
176
- ttl += @prefix_ttl_erb.result(binding) if with_prefix
177
- ttl += @tao_ttl_erb.result(binding)
197
+ @tao_ttl_erb.result(binding)
178
198
  end
179
199
 
180
- private
181
-
182
200
  def include_parent?(spans, span)
183
201
  # spans.each{|s| return true if (s[:begin] <= span[:begin] && s[:end] > span[:end]) || (s[:begin] < span[:begin] && s[:end] >= span[:end])}
184
202
  spans.each{|s| return true if s[:begin] <= span[:begin] && s[:end] >= span[:end]}
@@ -210,6 +228,7 @@ class TAO::RDFizer
210
228
  end
211
229
  end
212
230
 
231
+ # variable: denotations, relations
213
232
  ERB_ANNOTATIONS_TTL = <<~HEREDOC
214
233
  <% denotations.each do |d| -%>
215
234
  <%= d[:obj_uri] %> tao:denoted_by <%= d[:span_uri] %> ;
@@ -221,6 +240,7 @@ class TAO::RDFizer
221
240
  <% end -%>
222
241
  HEREDOC
223
242
 
243
+ # variable: spans
224
244
  ERB_SPANS_TTL = <<~HEREDOC
225
245
  <% spans.each do |s| -%>
226
246
  <%= s[:span_uri] %> rdf:type tao:Text_span ;
@@ -237,6 +257,7 @@ class TAO::RDFizer
237
257
  <% end -%>
238
258
  HEREDOC
239
259
 
260
+ # variable: namespaces
240
261
  ERB_PREFIXES_TTL = <<~HEREDOC
241
262
  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
242
263
  @prefix tao: <http://pubannotation.org/ontology/tao.owl#> .
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tao_rdfizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jin-Dong Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-15 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: It uses TAO (text annotation ontology) for representation of annotations
14
14
  to text.