Class: RdfToGraphviz

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf_to_graphviz.rb

Instance Method Summary collapse

Instance Method Details

#rdf_graph_to_dot(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rdf_to_graphviz.rb', line 17

def rdf_graph_to_dot(options = {})
  txt_dot = ""
  options[:rdf_graph] ||= @graph
  options[:digraph] ||= true
  if options[:digraph] == true
    txt_dot << "\ndigraph digraph_1 {"
  else
    txt_dot << "\ngraph graph_1 {"
  end

  options[:rdf_graph].each_statement do |statement|
    
    s = term_name(statement[0])
    o =  term_name(statement[2])

    txt_dot << "\n\"#{s}\"[color=red, shape=doublecircle];"
    if statement[2].literal?
      txt_dot << "\n\"#{o}\"[shape=rectangle];"
    else
      txt_dot << "\n\"#{o}\"[color=blue, shape=circle];"
    end
    txt_dot << "\n\"#{s}\" -> \"#{o}\" [label=\"#{statement[1].pname}\", color=red];"
    
  end
  txt_dot << "}"
end

#term_name(statement) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/rdf_to_graphviz.rb', line 6

def term_name(statement)
  if statement.literal?
    statement.to_s
  elsif statement.node?
    statement.to_s
  else
    statement.pname
  end
     
end