Class: RDF::N3::Algebra::Log::LangLit

Inherits:
RDF::N3::Algebra::ListOperator show all
Defined in:
lib/rdf/n3/algebra/log/langlit.rb

Overview

Takes a list of two strings creates a language-tagged literal.

Constant Summary collapse

NAME =
:langlit
URI =
RDF::N3::Log.langlit

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from RDF::N3::Algebra::ListOperator

#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

Reads the subject into the object.

Returns nil if resource does not validate, given its position

Parameters:

Returns:



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

def resolve(resource, position: :subject)
  case position
  when :subject
    RDF::Literal(as_literal(resource.first).to_s, language: resource.last.to_s.to_sym)
  when :object
    return nil unless resource.literal? || resource.variable?
    resource
  end
end

#validate(list) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rdf/n3/algebra/log/langlit.rb', line 25

def validate(list)
  if super(list)
    if list.length != 2
      log_error(NAME) {"operand is not a list with two elements: #{list.to_sxp}"}
      false
    elsif !list.last.to_s.match?(/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/)
      log_warn(NAME) {"second component of subject should be BCP47 language tag: #{list.last.to_sxp}"}
      false
    else
      true
    end
  else
    false
  end
end