Method: TTL2HTML::App#shapes_parse

Defined in:
lib/ttl2html.rb

#shapes_parse(shapes) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/ttl2html.rb', line 305

def shapes_parse(shapes)
  shapes.each do |shape|
    target_class = @data[shape]["http://www.w3.org/ns/shacl#targetClass"]&.first
    if target_class
      properties = @data[shape.to_s]["http://www.w3.org/ns/shacl#property"]
      if @data[shape.to_s]["http://www.w3.org/ns/shacl#or"]
        properties ||= []
        node_list = @data[shape.to_s]["http://www.w3.org/ns/shacl#or"].first
        while node_list and @data[node_list] do
          sub_shape = @data[node_list]["http://www.w3.org/1999/02/22-rdf-syntax-ns#first"].first
          if @data[sub_shape] and @data[sub_shape]["http://www.w3.org/ns/shacl#property"]
            properties += @data[sub_shape]["http://www.w3.org/ns/shacl#property"]
          end
          node_list = @data[node_list]["http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"].first
        end
      end
      if not properties.empty?
        properties.each do |property|
          path = @data[property]["http://www.w3.org/ns/shacl#path"].first
          yield target_class, property
        end
      end
    end
  end
end