Class: RDF::N3::Reader

Inherits:
Reader show all
Includes:
Meta, Parser, Util::Logger
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb

Overview

TODO:

A Notation-3/Turtle parser in Ruby

N3 Parser, based in librdf version of predictiveParser.py Separate pass to create branch_table from n3-selectors.n3

  • Formulae as RDF::Query representations
  • Formula expansion similar to SPARQL Construct

Constant Summary collapse

N3_KEYWORDS =
%w(a is of has keywords prefix base true false forSome forAny)

Constants included from Parser

Parser::NOT_NAME_CHARS, Parser::NOT_QNAME_CHARS, Parser::R_MLSTRING, Parser::R_WHITESPACE, Parser::SINGLE_CHARACTER_SELECTORS, Parser::START

Constants included from Meta

Meta::BARENAME_START, Meta::BARENAME_TAIL, Meta::BRANCHES, Meta::REGEXPS

Instance Attribute Summary

Attributes inherited from Reader

#options

Instance Method Summary collapse

Methods included from Parser

#abbr, #buffer, #consume, #dump_stack, #error, #get_token, #parse, #readline, #test, #token, #whitespace

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 inherited from Reader

#base_uri, #canonicalize?, #close, each, #encoding, #fail_object, #fail_predicate, #fail_subject, for, format, #intern?, #lineno, open, options, #prefix, #prefixes, #prefixes=, #read_statement, #read_triple, #rewind, #to_sym, to_sym, #valid?, #validate?

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Enumerable

add_entailment, #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_names, #has_graph?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_term?, #has_triple?, #invalid?, #method_missing, #objects, #predicates, #project_graph, #quads, #respond_to_missing?, #statements, #subjects, #supports?, #terms, #to_a, #to_h, #to_set, #triples, #valid?, #validate!

Methods included from Countable

#count, #empty?

Methods included from Isomorphic

#bijection_to, #isomorphic_with?

Methods included from Readable

#readable?

Constructor Details

#initialize(input = $stdin, options = {}) {|reader| ... } ⇒ reader

Initializes the N3 reader instance.

Parameters:

  • input (IO, File, String) (defaults to: $stdin)

    the input stream to read

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :base_uri (#to_s) — default: nil

    the base URI to use when resolving relative URIs (not supported by all readers)

  • :validate (Boolean) — default: false

    whether to validate the parsed statements and values

  • :canonicalize (Boolean) — default: false

    whether to canonicalize parsed literals

  • :intern (Boolean) — default: true

    whether to intern all parsed URIs

  • :prefixes (Hash) — default: Hash.new

    the prefix mappings to use (not supported by all readers)

Yields:

  • (reader)

    self

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Raises:

  • (Error)

    :: Raises RDF::ReaderError if validating and an error is found



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 47

def initialize(input = $stdin, options = {}, &block)
  super do
    input.rewind if input.respond_to?(:rewind)
    @input = input.respond_to?(:read) ? input : StringIO.new(input.to_s)
    @lineno = 0
    readline  # Prime the pump
    
    @memo = {}
    @keyword_mode = false
    @keywords = %w(a is of this has)
    @productions = []
    @prod_data = []

    @branches = BRANCHES # Get from meta class
    @regexps = REGEXPS # Get from meta class

    @formulae = []      # Nodes used as Formluae graph names
    @formulae_nodes = {}
    @variables = {}    # variable definitions along with defining formula

    if options[:base_uri]
      log_debug("@uri") { base_uri.inspect}
      namespace(nil, uri("#{base_uri}#"))
    end
    log_debug("validate") {validate?.inspect}
    log_debug("canonicalize") {canonicalize?.inspect}
    log_debug("intern") {intern?.inspect}

    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 Method Details

#booleanToken(prod, tok) ⇒ Object (protected)



153
154
155
156
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 153

def booleanToken(prod, tok)
  lit = RDF::Literal.new(tok.delete("@"), datatype: RDF::XSD.boolean, validate: validate?, canonicalize: canonicalize?)
  add_prod_data(:literal, lit)
end

#declarationFinishObject (protected)



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 175

def declarationFinish
  decl = @prod_data.pop
  case decl[:prod]
  when "@prefix"
    uri = process_uri(decl[:explicituri])
    namespace(decl[:prefix], uri)
  when "@base"
    # Base, set or update document URI
    uri = decl[:explicituri]
    options[:base_uri] = process_uri(uri)
    
    # The empty prefix "" is by default , bound to "#" -- the local namespace of the file.
    # The parser behaves as though there were a
    #   @prefix : <#>.
    # just before the file.
    # This means that <#foo> can be written :foo and using @keywords one can reduce that to foo.
    
    namespace(nil, uri.match(/[\/\#]$/) ? base_uri : process_uri("#{uri}#"))
    log_debug("declarationFinish[@base]") {"@base=#{base_uri}"}
  when "@keywords"
    log_debug("declarationFinish[@keywords]") {@keywords.inspect}
    # Keywords are handled in tokenizer and maintained in @keywords array
    if (@keywords & N3_KEYWORDS) != @keywords
      error("Undefined keywords used: #{(@keywords - N3_KEYWORDS).to_sentence}") if validate?
    end
    @userkeys = true
  else
    error("declarationFinish: FIXME #{decl.inspect}")
  end
end

#declarationStart(prod) ⇒ Object (protected)



158
159
160
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 158

def declarationStart(prod)
  @prod_data << {}
end

#declarationToken(prod, tok) ⇒ Object (protected)



162
163
164
165
166
167
168
169
170
171
172
173
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 162

def declarationToken(prod, tok)
  case prod
  when "@prefix", "@base", "@keywords"
    add_prod_data(:prod, prod)
  when "prefix"
    add_prod_data(:prefix, tok[0..-2])
  when "explicituri"
    add_prod_data(:explicituri, tok[1..-2])
  else
    add_prod_data(prod.to_sym, tok)
  end
end

#documentStart(prod) ⇒ Object (protected)

Document start, instantiate



207
208
209
210
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 207

def documentStart(prod)
  @formulae.push(nil)
  @prod_data << {}
end

#dtlangToken(prod, tok) ⇒ Object (protected)



212
213
214
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 212

def dtlangToken(prod, tok)
  add_prod_data(:langcode, tok) if prod == "langcode"
end

#each_statement {|statement| ... }

This method returns an undefined value.

Iterates the given block for each RDF statement in the input.

Yields:

  • (statement)

Yield Parameters:



94
95
96
97
98
99
100
101
102
103
104
105
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 94

def each_statement(&block)
  if block_given?
    @callback = block

    parse(START.to_sym)

    if validate? && log_statistics[:error]
      raise RDF::ReaderError, "Errors found during processing"
    end
  end
  enum_for(:each_triple)
end

#each_triple {|subject, predicate, object| ... }

This method returns an undefined value.

Iterates the given block for each RDF triple in the input.

Yields:

  • (subject, predicate, object)

Yield Parameters:



115
116
117
118
119
120
121
122
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 115

def each_triple(&block)
  if block_given?
    each_statement do |statement|
      block.call(*statement.to_triple)
    end
  end
  enum_for(:each_triple)
end

#existentialFinishObject (protected)

Apart from the set of statements, a formula also has a set of URIs of symbols which are universally quantified, and a set of URIs of symbols which are existentially quantified. Variables are then in general symbols which have been quantified.

Here we allocate a variable (making up a name) and record with the defining formula. Quantification is done when the formula is completed against all in-scope variables



226
227
228
229
230
231
232
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 226

def existentialFinish
  pd = @prod_data.pop
  forSome = Array(pd[:symbol])
  forSome.each do |term|
    @variables[term.to_s] = {formula: @formulae.last, var: RDF::Node.new(term.to_s.split(/[\/#]/).last)}
  end
end

#existentialStart(prod) ⇒ Object (protected)



216
217
218
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 216

def existentialStart(prod)
  @prod_data << {}
end

#expressionFinishObject (protected)

Process path items, and push on the last object for parent processing



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 239

def expressionFinish
  expression = @prod_data.pop
  
  # If we're in teh middle of a pathtail, append
  if @prod_data.last[:pathtail] && expression[:pathitem] && expression[:pathtail]
    path_list = [expression[:pathitem]] + expression[:pathtail]
    log_debug("expressionFinish(pathtail)") {"set pathtail to #{path_list.inspect}"}
    @prod_data.last[:pathtail] = path_list

    dir_list = [expression[:direction]] if expression[:direction]
    dir_list += expression[:directiontail] if expression[:directiontail]
    @prod_data.last[:directiontail] = dir_list if dir_list
  elsif expression[:pathitem] && expression[:pathtail]
    add_prod_data(:expression, process_path(expression))
  elsif expression[:pathitem]
    add_prod_data(:expression, expression[:pathitem])
  else
    error("expressionFinish: FIXME #{expression.inspect}")
  end
end

#expressionStart(prod) ⇒ Object (protected)



234
235
236
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 234

def expressionStart(prod)
  @prod_data << {}
end

#inspectObject



84
85
86
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 84

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, base_uri.to_s)
end

#literalFinishObject (protected)



269
270
271
272
273
274
275
276
277
278
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 269

def literalFinish
  lit = @prod_data.pop
  content = RDF::NTriples.unescape(lit[:string])
  language = lit[:langcode] if lit[:langcode]
  language = language.downcase if language && canonicalize?
  datatype = lit[:symbol]
  
  lit = RDF::Literal.new(content, language: language, datatype: datatype, validate: validate?, canonicalize: canonicalize?)
  add_prod_data(:literal, lit)
end

#literalStart(prod) ⇒ Object (protected)



260
261
262
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 260

def literalStart(prod)
  @prod_data << {}
end

#literalToken(prod, tok) ⇒ Object (protected)



264
265
266
267
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 264

def literalToken(prod, tok)
  tok = tok[0, 3] == '"""' ? tok[3..-4] : tok[1..-2]
  add_prod_data(:string, tok)
end

#objectFinishObject (protected)



284
285
286
287
288
289
290
291
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 284

def objectFinish
  object = @prod_data.pop
  if object[:expression]
    add_prod_data(:object, object[:expression])
  else
    error("objectFinish: FIXME #{object.inspect}")
  end
end

#objectStart(prod) ⇒ Object (protected)



280
281
282
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 280

def objectStart(prod)
  @prod_data << {}
end

#onFinishObject (protected)

End of production



134
135
136
137
138
139
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 134

def onFinish
  prod = @productions.pop()
  handler = "#{prod}Finish".to_sym
  log_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}: #{@prod_data.last.inspect}"}
  send(handler) if respond_to?(handler, true)
end

#onStart(prod) ⇒ Object (protected)

Start of production



126
127
128
129
130
131
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 126

def onStart(prod)
  handler = "#{prod}Start".to_sym
  log_debug("#{handler}(#{respond_to?(handler, true)})", prod)
  @productions << prod
  send(handler, prod) if respond_to?(handler, true)
end

#onToken(prod, tok) ⇒ Object (protected)

Process of a token



142
143
144
145
146
147
148
149
150
151
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 142

def onToken(prod, tok)
  unless @productions.empty?
    parentProd = @productions.last
    handler = "#{parentProd}Token".to_sym
    log_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
    send(handler, prod, tok) if respond_to?(handler, true)
  else
    error("Token has no parent production")
  end
end

#pathitemFinishObject (protected)



340
341
342
343
344
345
346
347
348
349
350
351
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 340

def pathitemFinish
  pathitem = @prod_data.pop
  if pathitem[:pathlist]
    error("pathitemFinish(pathlist): FIXME #{pathitem.inspect}")
  elsif pathitem[:propertylist]
    error("pathitemFinish(propertylist): FIXME #{pathitem.inspect}")
  elsif pathitem[:symbol] || pathitem[:literal]
    add_prod_data(:pathitem, pathitem[:symbol] || pathitem[:literal])
  else
    error("pathitemFinish: FIXME #{pathitem.inspect}")
  end
end

#pathitemStart(prod) ⇒ Object (protected)



293
294
295
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 293

def pathitemStart(prod)
  @prod_data << {}
end

#pathitemToken(prod, tok) ⇒ Object (protected)



297
298
299
300
301
302
303
304
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
330
331
332
333
334
335
336
337
338
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 297

def pathitemToken(prod, tok)
  case prod
  when "numericliteral"
    nl = RDF::NTriples.unescape(tok)
    datatype = case nl
    when /e/i then RDF::XSD.double
    when /\./ then RDF::XSD.decimal
    else RDF::XSD.integer
    end
    
    lit = RDF::Literal.new(nl, datatype: datatype, validate: validate?, canonicalize: canonicalize?)
    add_prod_data(:literal, lit)
  when "quickvariable"
    # There is a also a shorthand syntax ?x which is the same as :x except that it implies that x is
    # universally quantified not in the formula but in its parent formula
    uri = process_qname(tok.sub('?', ':'))
    @variables[uri.to_s] = { formula: @formulae[-2], var: univar(uri) }
    add_prod_data(:symbol, uri)
  when "boolean"
    lit = RDF::Literal.new(tok.delete("@"), datatype: RDF::XSD.boolean, validate: validate?, canonicalize: canonicalize?)
    add_prod_data(:literal, lit)
  when "[", "("
    # Push on state for content of blank node
    @prod_data << {}
  when "]", ")"
    # Construct
    symbol = process_anonnode(@prod_data.pop)
    add_prod_data(:symbol, symbol)
  when "{"
    # A new formula, push on a node as a named graph
    node = RDF::Node.new
    @formulae << node
    @formulae_nodes[node] = true
  when "}"
    # Pop off the formula, and remove any variables defined in this graph
    formula = @formulae.pop
    @variables.delete_if {|k, v| v[:formula] == formula}
    add_prod_data(:symbol, formula)
  else
    error("pathitemToken(#{prod}, #{tok}): FIXME")
  end
end

#pathlistFinishObject (protected)



357
358
359
360
361
362
363
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 357

def pathlistFinish
  pathlist = @prod_data.pop
  # Flatten propertylist into an array
  expr = @prod_data.last.delete(:expression)
  add_prod_data(:pathlist, expr) if expr
  add_prod_data(:pathlist, pathlist[:pathlist]) if pathlist[:pathlist]
end

#pathlistStart(prod) ⇒ Object (protected)



353
354
355
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 353

def pathlistStart(prod)
  @prod_data << {pathlist: []}
end

#pathtailFinishObject (protected)



378
379
380
381
382
383
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 378

def pathtailFinish
  pathtail = @prod_data.pop
  add_prod_data(:pathtail, pathtail[:pathtail])
  add_prod_data(:direction, pathtail[:direction]) if pathtail[:direction]
  add_prod_data(:directiontail, pathtail[:directiontail]) if pathtail[:directiontail]
end

#pathtailStart(prod) ⇒ Object (protected)



365
366
367
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 365

def pathtailStart(prod)
  @prod_data << {pathtail: []}
end

#pathtailToken(prod, tok) ⇒ Object (protected)



369
370
371
372
373
374
375
376
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 369

def pathtailToken(prod, tok)
  case tok
  when "!", "."
    add_prod_data(:direction, :forward)
  when "^"
    add_prod_data(:direction, :reverse)
  end
end

#propertylistFinishObject (protected)



389
390
391
392
393
394
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 389

def propertylistFinish
  propertylist = @prod_data.pop
  # Flatten propertylist into an array
  ary = [propertylist, propertylist.delete(:propertylist)].flatten.compact
  @prod_data.last[:propertylist] = ary
end

#propertylistStart(prod) ⇒ Object (protected)



385
386
387
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 385

def propertylistStart(prod)
  @prod_data << {}
end

#simpleStatementFinishObject (protected)

Completion of Simple Statement, all productions include :subject, and :propertyList



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 401

def simpleStatementFinish
  statement = @prod_data.pop
  
  subject = statement[:subject]
  properties = Array(statement[:propertylist])
  properties.each do |p|
    predicate = p[:verb]
    next unless predicate
    log_debug("simpleStatementFinish(pred)") {predicate.to_s}
    error(%(Illegal statment: "#{predicate}" missing object)) unless p.has_key?(:object)
    objects = Array(p[:object])
    objects.each do |object|
      if p[:invert]
        add_triple("simpleStatementFinish", object, predicate, subject)
      else
        add_triple("simpleStatementFinish", subject, predicate, object)
      end
    end
  end
end

#simpleStatementStart(prod) ⇒ Object (protected)



396
397
398
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 396

def simpleStatementStart(prod)
  @prod_data << {}
end

#subjectFinishObject (protected)



426
427
428
429
430
431
432
433
434
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 426

def subjectFinish
  subject = @prod_data.pop
  
  if subject[:expression]
    add_prod_data(:subject, subject[:expression])
  else
    error("unknown expression type")
  end
end

#subjectStart(prod) ⇒ Object (protected)



422
423
424
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 422

def subjectStart(prod)
  @prod_data << {}
end

#symbolToken(prod, tok) ⇒ Object (protected)



436
437
438
439
440
441
442
443
444
445
446
447
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 436

def symbolToken(prod, tok)
  term = case prod
  when 'explicituri'
    process_uri(tok[1..-2])
  when 'qname'
    process_qname(tok)
  else
    error("symbolToken(#{prod}, #{tok}): FIXME #{term.inspect}")
  end
  
  add_prod_data(:symbol, term)
end

#universalFinishObject (protected)

Apart from the set of statements, a formula also has a set of URIs of symbols which are universally quantified, and a set of URIs of symbols which are existentially quantified. Variables are then in general symbols which have been quantified.

Here we allocate a variable (making up a name) and record with the defining formula. Quantification is done when the formula is completed against all in-scope variables



459
460
461
462
463
464
465
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 459

def universalFinish
  pd = @prod_data.pop
  forAll = Array(pd[:symbol])
  forAll.each do |term|
    @variables[term.to_s] = { formula: @formulae.last, var: univar(term) }
  end
end

#universalStart(prod) ⇒ Object (protected)



449
450
451
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 449

def universalStart(prod)
  @prod_data << {}
end

#verbFinishObject (protected)



493
494
495
496
497
498
499
500
501
502
503
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 493

def verbFinish
  verb = @prod_data.pop
  if verb[:expression]
    error("Literal may not be used as a predicate") if verb[:expression].is_a?(RDF::Literal)
    error("Formula may not be used as a peredicate") if @formulae_nodes.has_key?(verb[:expression])
    add_prod_data(:verb, verb[:expression])
    add_prod_data(:invert, true) if verb[:invert]
  else
    error("verbFinish: FIXME #{verb.inspect}")
  end
end

#verbStart(prod) ⇒ Object (protected)



467
468
469
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 467

def verbStart(prod)
  @prod_data << {}
end

#verbToken(prod, tok) ⇒ Object (protected)



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-f6621862bdfe/lib/rdf/n3/reader.rb', line 471

def verbToken(prod, tok)
  term = case prod
  when '<='
    add_prod_data(:expression, RDF::LOG.implies)
    add_prod_data(:invert, true)
  when '=>'
    add_prod_data(:expression, RDF::LOG.implies)
  when '='
    add_prod_data(:expression, RDF::OWL.sameAs)
  when '@a'
    add_prod_data(:expression, RDF.type)
  when '@has', "@of"
    # Syntactic sugar
  when '@is'
    add_prod_data(:invert, true)
  else
    error("verbToken(#{prod}, #{tok}): FIXME #{term.inspect}")
  end
  
  add_prod_data(:symbol, term)
end