Class: RDF::N3::Algebra::Log::N3String

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

Overview

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

Constant Summary collapse

NAME =
:logN3String
URI =
RDF::N3::Log.n3String

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ResourceOperator

#as_literal, #execute, #input_operand

Methods included from Builtin

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

Instance Method Details

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

Serializes the subject formula into an N3 string representation.

Parameters:

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'lib/rdf/n3/algebra/log/n3_string.rb', line 13

def resolve(resource, position: :subject)
  case position
  when :subject
    return nil unless resource.formula?
    as_literal(RDF::N3::Writer.buffer {|w| resource.each {|st| w << st}})
  when :object
    return nil unless resource.literal? || resource.variable?
    resource
  end
end

#valid?(subject, object) ⇒ Boolean

Subject must evaluate to a formula and object to a literal.

Parameters:

Returns:

  • (Boolean)


30
31
32
# File 'lib/rdf/n3/algebra/log/n3_string.rb', line 30

def valid?(subject, object)
  subject.formula? && (object.variable? || object.literal?)
end