Class: BEL::BELRDF::TermConverter

Inherits:
Object
  • Object
show all
Includes:
RDFConverter, BELParser::Language::Version2_0::Functions, BELParser::Quoting
Defined in:
lib/bel/translator/plugins/rdf2/term_converter.rb

Instance Method Summary collapse

Methods included from RDFConverter

#s

Constructor Details

#initialize(parameter_converter) ⇒ TermConverter



14
15
16
# File 'lib/bel/translator/plugins/rdf2/term_converter.rb', line 14

def initialize(parameter_converter)
  @parameter_converter = parameter_converter
end

Instance Method Details

#convert(term) ⇒ RDF::Graph

Convert a BELParser::Expression::Model::Term to RDF::Graph of RDF statements.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bel/translator/plugins/rdf2/term_converter.rb', line 23

def convert(term)
  path_part     = to_path_part(term)
  term_uri      = to_uri(path_part)
  tg            = RDF::Graph.new
  tg           << s(term_uri, RDF.type, BELV2_0.Term)

  term_class = FUNCTION_HASH[term.function]
  if term_class
    tg << s(term_uri, RDF.type, term_class)
  end

  term.arguments.each do |arg|
    case arg
    when BELParser::Expression::Model::Parameter
      param_uri, paramg = @parameter_converter.convert(arg)
      if param_uri
        tg << paramg
        tg << s(term_uri, BELV2_0.hasConcept, param_uri)
      end
    when BELParser::Expression::Model::Term
      if FUNCTION_HASH.key?(arg.function)
        path_part, iterm_uri, itermg = convert(arg)
        tg << itermg
        tg << s(term_uri, BELV2_0.hasChild, iterm_uri)
      end
      handle_special_inner(term, term_uri, arg, tg)
    end
  end

  [path_part, term_uri, tg]
end