Module: RDF::Term

Includes:
Comparable, Value, SPARQL::Algebra::Expression
Included in:
Literal, N3::Algebra::Formula, N3::List, Query::Variable, Resource
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/refinements.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/extensions.rb

Overview

Extensions for RDF::Term.

Constant Summary

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Constants included from Util::Logger

Util::Logger::IOWrapper

Instance Method Summary collapse

Methods included from SPARQL::Algebra::Expression

cast, #constant?, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

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 Value

#anonymous?, #canonicalize, #canonicalize!, #constant?, #formula?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #to_ndvar, #to_nquads, #to_ntriples, #to_rdf, #type_error, #uri?, #valid?, #validate!, #variable?

Instance Method Details

#<=>(other) ⇒ Integer

This method is abstract.

Compares self to other for sorting purposes.

Subclasses should override this to provide a more meaningful implementation than the default which simply performs a string comparison based on #to_s.

Parameters:

Returns:

Since:

  • 0.3.0



23
24
25
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 23

def <=>(other)
  self.to_s <=> other.to_s
end

#==(other) ⇒ Integer

This method is abstract.

Compares self to other to implement RDFterm-equal.

Subclasses should override this to provide a more meaningful implementation than the default which simply performs a string comparison based on #to_s.

Parameters:

Returns:

See Also:

Since:

  • 0.3.0



39
40
41
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 39

def ==(other)
  super
end

#aggregate?Boolean

Returns:

  • (Boolean)


260
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/extensions.rb', line 260

def aggregate?; false; end

#as_datetimeRDF::Literal::DateTime

Parse the value as a dateTime literal, or return now.

Returns:

Since:

  • 0.3.0



78
79
80
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/extensions.rb', line 78

def as_datetime
  RDF::Literal::DateTime.new(DateTime.now)
end

#as_numberRDF::Literal::Numeric

Parse the value as a numeric literal, or return 0.

Returns:

Since:

  • 0.3.0



70
71
72
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/extensions.rb', line 70

def as_number
  RDF::Literal(0)
end

#compatible?(other) ⇒ Boolean

Term compatibility according to SPARQL

Returns:

  • (Boolean)

See Also:

Since:

  • 2.0



106
107
108
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 106

def compatible?(other)
  false
end

#eql?(other) ⇒ Integer

This method is abstract.

Determins if self is the same term as other.

Subclasses should override this to provide a more meaningful implementation than the default which simply performs a string comparison based on #to_s.

Parameters:

Returns:

See Also:

Since:

  • 0.3.0



55
56
57
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 55

def eql?(other)
  super
end

#escape(string) ⇒ String (protected)

Escape a term using escapes. This should be implemented as appropriate for the given type of term.

Parameters:

Returns:

Raises:

  • (NotImplementedError)

Since:

  • 0.3.0



116
117
118
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 116

def escape(string)
  raise NotImplementedError, "#{self.class}#escape"
end

#evaluate(bindings, **options) ⇒ RDF::Term

Parameters:

Returns:



12
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/refinements.rb', line 12

def evaluate(bindings, formulae: nil, **options); end

#ndvarsArray<RDF::Query::Variable>

Return the non-destinguished variables contained within this operator



265
266
267
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/extensions.rb', line 265

def ndvars
  vars.reject(&:distinguished?)
end

#optimize(**options) ⇒ RDF::Term

A duplicate of this term.

Returns:

See Also:



281
282
283
284
285
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/extensions.rb', line 281

def optimize(**options)
  optimized = self.deep_dup
  #optimized.lexical = nil if optimized.respond_to?(:lexical=)
  #optimized
end

#sameTerm?(other) ⇒ Boolean

Is this the same term? Like #eql?, but no variable matching

Returns:

  • (Boolean)

Since:

  • 0.3.0



62
63
64
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/extensions.rb', line 62

def sameTerm?(other)
  eql?(other)
end

#term?Boolean #term?(name) ⇒ Boolean

Overloads:

  • #term?Boolean

    Returns true if self is a RDF::Term.

    Returns:

    • (Boolean)
  • #term?(name) ⇒ Boolean

    Returns true if self contains the given RDF subject term.

    Parameters:

    Returns:

    • (Boolean)

Since:

  • 0.3.0



69
70
71
72
73
74
75
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 69

def term?(*args)
  case args.length
  when 0 then true
  when 1 then false
  else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
  end
end

#termsArray<RDF::Value>

Returns an array including just itself.

Returns:

Since:

  • 0.3.0



89
90
91
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 89

def terms
  [self]
end

#to_baseSring

Returns the base representation of this term.

Returns:

  • (Sring)

Since:

  • 0.3.0



97
98
99
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 97

def to_base
  RDF::NTriples.serialize(self).freeze
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this term.

Returns:



292
293
294
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/extensions.rb', line 292

def to_sparql(**options)
  to_sxp(**options)
end

#to_termRDF::Value

Returns itself.

Returns:

Since:

  • 0.3.0



81
82
83
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/term.rb', line 81

def to_term
  self
end

#varsArray<RDF::Query::Variable>

Return the variables contained within this operator



272
273
274
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/extensions.rb', line 272

def vars
  variable? ? [self] : []
end