Module: RDF::SPARQL::Common

Included in:
Reader, Writer
Defined in:
lib/lib/common.rb

Instance Method Summary collapse

Instance Method Details

#distinct?Boolean

Check whether ‘distinct` flag was specified

Returns:

  • (Boolean)


92
93
94
# File 'lib/lib/common.rb', line 92

def distinct?
  @options[:distinct] == true
end

#each_statement {|statement| ... } ⇒ Reader

Yields each statement of SPARQL query

Yields:

  • (statement)

Yield Parameters:

  • (Statement)

Returns:



11
12
13
14
# File 'lib/lib/common.rb', line 11

def each_statement(&block)
  @graph.each_statement { |statement| block.call(statement) }
  self
end

#each_target {|variable| ... } ⇒ Reader

Yields each target variable in SPARQL query

Yields:

  • (variable)

Yield Parameters:

  • (Variable)

Returns:



33
34
35
36
# File 'lib/lib/common.rb', line 33

def each_target(&block)
  @targets.each { |target| block.call(target) }
  self
end

#each_triple {|triple| ... } ⇒ Reader

Yields each triple of SPARQL query

Yields:

  • (triple)

Yield Parameters:

  • (Array(Value))

Returns:



22
23
24
25
# File 'lib/lib/common.rb', line 22

def each_triple(&block)
  @graph.each_triple { |*triple| block.call(*triple) }
  self
end

#each_variable {|variable| ... } ⇒ Reader

Yields each variable in SPARQL query

Yields:

  • (variable)

Yield Parameters:

  • (Variable)

Returns:



44
45
46
47
# File 'lib/lib/common.rb', line 44

def each_variable(&block)
  variables.each { |variable| block.call(variable) }
  self
end

#reduced?Boolean

Check whether ‘reduced` flag was specified

Returns:

  • (Boolean)


100
101
102
# File 'lib/lib/common.rb', line 100

def reduced?
  @options[:reduced] == true
end

#statementsObject

-


59
60
61
# File 'lib/lib/common.rb', line 59

def statements
  @graph.statements
end

#targetsObject

-


52
53
54
# File 'lib/lib/common.rb', line 52

def targets
  @targets
end

#triplesObject

-


66
67
68
# File 'lib/lib/common.rb', line 66

def triples
  @graph.triples
end

#typeObject

-


84
85
86
# File 'lib/lib/common.rb', line 84

def type
  @type || @options[:type]
end

#variablesObject

-


73
74
75
76
77
78
79
# File 'lib/lib/common.rb', line 73

def variables
  Hash[@graph.map { |pattern|
    pattern.variables.values
  }.flatten.uniq.map { |variable|
    [variable.name, variable]
  }]
end