Class: Reddy::N3Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/reddy/n3parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n3_str, uri = nil) ⇒ N3Parser

Creates a new parser for N3 (or Turtle).

Parameters:

  • n3_str (String)

    the Notation3/Turtle string

  • uri (String) (defaults to: nil)

    the URI of the document

Author:

  • Patrick Sinclair (metade)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/reddy/n3parser.rb', line 17

def initialize(n3_str, uri=nil)
  @uri = Addressable::URI.parse(uri) unless uri.nil?
  parser = N3GrammerParser.new
  document = parser.parse(n3_str)
  if document
    @graph = Graph.new
    process_directives(document)
    process_statements(document)
  else
    parser.terminal_failures.each do |tf|
      puts "Expected #{tf.expected_string.inspect} (#{tf.index})- '#{n3_str[tf.index,10].inspect}'"
    end
  end
end

Instance Attribute Details

#graphObject

Returns the value of attribute graph.



8
9
10
# File 'lib/reddy/n3parser.rb', line 8

def graph
  @graph
end