class RDF::Raptor::FFI::Reader
FFI
reader implementation.
Constants
- ERROR_HANDLER
- GENID
- WARNING_HANDLER
Attributes
The Raptor
parser instance.
@return [V2::Parser]
Public Class Methods
Initializes the FFI
reader instance.
@param [IO, File, RDF::URI, String] input @param [Hash{Symbol => Object}] options
any additional options (see `RDF::Reader#initialize`)
@option options [String, to_s] :base_uri (“file:///dev/stdin”) @yield [reader] ‘self` @yieldparam [RDF::Reader] reader @yieldreturn [void] ignored
# File lib/rdf/raptor/ffi.rb, line 43 def initialize(input = $stdin, **options, &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
Public Instance Methods
@param [String] node_id @return [RDF::Node]
# 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
@param [String] uri_str @return [RDF::URI]
# File lib/rdf/raptor/ffi.rb, line 132 def create_uri(uri_str) RDF::URI.intern(uri_str) end
@yield [statement] @yieldparam [RDF::Statement] statement @yieldreturn [void] ignored @see RDF::Reader#each_statement
# File lib/rdf/raptor/ffi.rb, line 78 def each_statement(**options, &block) if block_given? if options[: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, **options) end
@yield [triple] @yieldparam [Array(RDF::Resource, RDF::URI, RDF::Term)] triple @yieldreturn [void] ignored @see RDF::Reader#each_triple
# 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
@private @param [RDF::URI, File, Tempfile, IO, StringIO] input
the input stream
@yield [parser, statement]
each statement in the input stream
@yieldparam [FFI::Pointer] parser @yieldparam [FFI::Pointer] statement @yieldreturn [void] ignored @return [void]
# File lib/rdf/raptor/ffi.rb, line 123 def parse(input, &block) @parser.parse(input, **@options, &block) end