Class: RDF::AllegroGraph::Query::FunctorExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/allegro_graph/query/functor_expression.rb

Overview

A functor expression in a Prolog query (other than an ordinary pattern).

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *arguments) ⇒ FunctorExpression

Construct a new functor.

Parameters:

  • name (String)
  • arguments (Array<Symbol,RDF::Value,value>)

    The arguments to the functor, which may be either variables, RDF::Value objects, or Ruby values that we can convert to literals.


21
22
23
24
25
26
27
28
29
30
# File 'lib/rdf/allegro_graph/query/functor_expression.rb', line 21

def initialize(name, *arguments)
  @name = name
  @arguments = arguments.map do |arg|
    case arg
    when Symbol then RDF::Query::Variable.new(arg)
    when PrologLiteral, RDF::Value then arg
    else RDF::Literal.new(arg)
    end
  end
end

Instance Attribute Details

#argumentsObject (readonly)

The arguments passed to this functor.


13
14
15
# File 'lib/rdf/allegro_graph/query/functor_expression.rb', line 13

def arguments
  @arguments
end

#nameObject (readonly)

The name of this functor.


10
11
12
# File 'lib/rdf/allegro_graph/query/functor_expression.rb', line 10

def name
  @name
end

Instance Method Details

#variablesHash<Symbol,RDF::Query::Variable>

Return a hash table of all variables used in this functor. This is intended to be duck-type compatible with the same method in RDF::Query::Pattern.

Returns:

  • (Hash<Symbol,RDF::Query::Variable>)

See Also:

  • Query::Pattern#variables

38
39
40
41
42
43
44
# File 'lib/rdf/allegro_graph/query/functor_expression.rb', line 38

def variables
  result = {}
  @arguments.each do |arg|
    result.merge!(arg.variables) if arg.is_a?(RDF::Query::Variable)
  end
  result
end