Class: RDF::Raptor::FFI::Reader
- Inherits:
-
RDF::Reader
- Object
- RDF::Reader
- RDF::Raptor::FFI::Reader
- Includes:
- Util::Logger
- Defined in:
- lib/rdf/raptor/ffi.rb
Overview
FFI reader implementation.
Constant Summary collapse
- ERROR_HANDLER =
Proc.new do |user_data, locator, | line = V2.raptor_locator_line(locator) log_error(, lineno: line) end
- WARNING_HANDLER =
Proc.new do |user_data, locator, | line = V2.raptor_locator_line(locator) log_warn(, lineno: line) end
- GENID =
/^genid\d+$/
Instance Attribute Summary collapse
-
#parser ⇒ V2::Parser
readonly
The Raptor parser instance.
Instance Method Summary collapse
- #create_node(node_id) ⇒ RDF::Node
- #create_uri(uri_str) ⇒ RDF::URI
- #each_statement(**options) {|statement| ... } ⇒ Object (also: #each)
- #each_triple {|triple| ... } ⇒ Object
-
#initialize(input = $stdin, **options) {|reader| ... } ⇒ Reader
constructor
Initializes the FFI reader instance.
Constructor Details
#initialize(input = $stdin, **options) {|reader| ... } ⇒ Reader
Initializes the FFI reader instance.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rdf/raptor/ffi.rb', line 43 def initialize(input = $stdin, **, &block) @format = self.class.format.rapper_format @parser = V2::Parser.new(@format) @parser.error_handler = ERROR_HANDLER @parser.warning_handler = WARNING_HANDLER @parser.namespace_handler = Proc.new do |user_data, raptor_namespace| namespace = V2::Namespace.new(raptor_namespace) prefix(namespace.prefix, namespace.uri) if namespace.prefix_length > 0 end super end |
Instance Attribute Details
#parser ⇒ V2::Parser (readonly)
The Raptor parser instance.
71 72 73 |
# File 'lib/rdf/raptor/ffi.rb', line 71 def parser @parser end |
Instance Method Details
#create_node(node_id) ⇒ RDF::Node
139 140 141 142 |
# File 'lib/rdf/raptor/ffi.rb', line 139 def create_node(node_id) @nodes ||= {} @nodes[node_id] ||= RDF::Node.new(GENID === node_id ? nil : node_id) end |
#create_uri(uri_str) ⇒ RDF::URI
132 133 134 |
# File 'lib/rdf/raptor/ffi.rb', line 132 def create_uri(uri_str) RDF::URI.intern(uri_str) end |
#each_statement(**options) {|statement| ... } ⇒ Object Also known as: each
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rdf/raptor/ffi.rb', line 78 def each_statement(**, &block) if block_given? if [:raw] # this is up to an order of magnitude faster... parse(@input) do |parser, statement| block.call(V2::Statement.new(statement, self)) end else parse(@input) do |parser, statement| block.call(V2::Statement.new(statement, self).to_rdf) end end if validate? && log_statistics[:error] raise RDF::ReaderError, "Errors found during processing" end end enum_for(:each_statement, **) end |
#each_triple {|triple| ... } ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/rdf/raptor/ffi.rb', line 104 def each_triple(&block) if block_given? each_statement do |statement| block.call(*statement.to_triple) end end enum_for(:each_triple) end |