Class: RDF::Microdata::Reader
- Includes:
- Expansion, Util::Logger
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader/nokogiri.rb
Overview
An Microdata parser in Ruby
Based on processing rules, amended with the following:
Defined Under Namespace
Modules: Nokogiri
Constant Summary collapse
- URL_PROPERTY_ELEMENTS =
%w(a area audio embed iframe img link object source track video)
Constants included from Util::Logger
Instance Attribute Summary collapse
-
#implementation ⇒ Module
readonly
Returns the HTML implementation module for this reader instance.
-
#memory ⇒ Hash{Object => RDF::Resource}
readonly
Maps RDF elements (items) to resources.
Attributes inherited from Reader
Attributes included from Enumerable
Class Method Summary collapse
-
.options ⇒ Object
Reader options.
Instance Method Summary collapse
-
#base_uri ⇒ Hash{Symbol => RDF::URI}
Returns the base URI determined by this reader.
-
#each_statement {|statement| ... }
Iterates the given block for each RDF statement in the input.
-
#each_triple {|subject, predicate, object| ... }
Iterates the given block for each RDF triple in the input.
-
#initialize(input = $stdin, **options) {|reader| ... } ⇒ reader
constructor
Initializes the Microdata reader instance.
Methods included from Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Methods included from Expansion
Methods inherited from Reader
#canonicalize?, #close, each, #each_pg_statement, #encoding, #fail_object, #fail_predicate, #fail_subject, for, format, #intern?, #lineno, open, #prefix, #prefixes, #prefixes=, #read_statement, #read_triple, #rewind, #to_sym, to_sym, #valid?, #validate?
Methods included from Util::Aliasing::LateBound
Methods included from Enumerable
add_entailment, #canonicalize, #canonicalize!, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_subject, #each_term, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #method_missing, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #respond_to_missing?, #statement?, #statements, #subject?, #subjects, #supports?, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!
Methods included from Isomorphic
#bijection_to, #isomorphic_with?
Methods included from Countable
Methods included from Readable
Constructor Details
#initialize(input = $stdin, **options) {|reader| ... } ⇒ reader
Initializes the Microdata reader instance.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 97 def initialize(input = $stdin, **, &block) super do @library = :nokogiri require "rdf/microdata/reader/#{@library}" @implementation = Nokogiri self.extend(@implementation) input.rewind if input.respond_to?(:rewind) initialize_html(input, **) rescue log_fatal($!., exception: RDF::ReaderError) log_error("Empty document") if root.nil? log_error(doc_errors.map(&:message).uniq.join("\n")) if !doc_errors.empty? log_debug('', "library = #{@library}") # Load registry begin registry_uri = [:registry] || RDF::Microdata::DEFAULT_REGISTRY log_debug('', "registry = #{registry_uri.inspect}") Registry.load_registry(registry_uri) rescue JSON::ParserError => e log_fatal("Failed to parse registry: #{e.}", exception: RDF::ReaderError) if (root.nil? && validate?) end if block_given? case block.arity when 0 then instance_eval(&block) else block.call(self) end end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDF::Enumerable
Instance Attribute Details
#implementation ⇒ Module (readonly)
Returns the HTML implementation module for this reader instance.
23 24 25 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 23 def implementation @implementation end |
#memory ⇒ Hash{Object => RDF::Resource} (readonly)
Returns maps RDF elements (items) to resources.
26 27 28 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 26 def memory @memory end |
Class Method Details
.options ⇒ Object
Reader options
43 44 45 46 47 48 49 50 51 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 43 def self. super + [ RDF::CLI::Option.new( symbol: :rdfa, datatype: TrueClass, on: ["--rdfa"], description: "Transform and parse as RDFa.") {true}, ] end |
Instance Method Details
#base_uri ⇒ Hash{Symbol => RDF::URI}
Returns the base URI determined by this reader.
36 37 38 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 36 def base_uri @options[:base_uri] end |
#each_statement {|statement| ... }
This method returns an undefined value.
Iterates the given block for each RDF statement in the input.
Reads to graph and performs expansion if required.
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 139 def each_statement(&block) if block_given? @callback = block # parse parse_whole_document(@doc, base_uri) if validate? && log_statistics[:error] raise RDF::ReaderError, "Errors found during processing" end end enum_for(:each_statement) end |
#each_triple {|subject, predicate, object| ... }
This method returns an undefined value.
Iterates the given block for each RDF triple in the input.
161 162 163 164 165 166 167 168 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-microdata-73e8bfd8e661/lib/rdf/microdata/reader.rb', line 161 def each_triple(&block) if block_given? each_statement do |statement| block.call(*statement.to_triple) end end enum_for(:each_triple) end |