Class: RDF::N3::Algebra::Log::ParsedAsN3

Inherits:
ResourceOperator
  • Object
show all
Defined in:
lib/rdf/n3/algebra/log/parsed_as_n3.rb

Overview

The subject string, parsed as N3, gives this formula.

Constant Summary collapse

NAME =
:logParsedAsN3
URI =
RDF::N3::Log.parsedAsN3

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ResourceOperator

#as_literal, #execute, #input_operand, #valid?

Methods included from Builtin

#each, #evaluate, #hash, #input_operand, #rank, #to_uri

Instance Method Details

#resolve(resource, position: :subject) ⇒ RDF::Term

Parses the subject into a new formula.

Returns nil if resource does not validate, given its position

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rdf/n3/algebra/log/parsed_as_n3.rb', line 15

def resolve(resource, position: :subject)
  case position
  when :subject
    return nil unless resource.literal?
    begin
      repo = RDF::N3::Repository.new
      repo << RDF::N3::Reader.new(resource.to_s, **@options.merge(list_terms: true,  logger: false))
      log_debug("logParsedAsN3") {SXP::Generator.string repo.statements.to_sxp_bin}
      content_hash = resource.hash # used as name of resulting formula
      form = RDF::N3::Algebra::Formula.from_enumerable(repo, graph_name: RDF::Node.intern(content_hash))
      log_info(NAME) {"form hash (#{resource}): #{form.hash}"}
      form
    rescue RDF::ReaderError
      nil
    end
  when :object
    return nil unless resource.literal? || resource.is_a?(RDF::Query::Variable)
    resource
  end
end