Class: YOWL::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Repository

Returns a new instance of Repository.



8
9
10
11
12
# File 'lib/yowl/repository.rb', line 8

def initialize(options)
  @options = options
  
  init_schemas()
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/yowl/repository.rb', line 6

def options
  @options
end

#schemasObject (readonly)

Returns the value of attribute schemas.



5
6
7
# File 'lib/yowl/repository.rb', line 5

def schemas
  @schemas
end

Instance Method Details

#getSchemaForImport(import_) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/yowl/repository.rb', line 39

def getSchemaForImport(import_)
  begin
    return @schemas[import_.uri]
  rescue => exception
    puts exception.backtrace
  end
end

#getSchemaNameForImport(import_) ⇒ Object



53
54
55
56
# File 'lib/yowl/repository.rb', line 53

def getSchemaNameForImport(import_)
  schema = getSchemaForImport(import_)
  return schema.nil? ? '' : schema.name
end

#knowsImport(import_) ⇒ Object



48
49
50
# File 'lib/yowl/repository.rb', line 48

def knowsImport(import_)
  return ! getSchemaForImport(import_).nil?
end

#ontologiesObject



31
32
33
34
35
36
# File 'lib/yowl/repository.rb', line 31

def ontologies()
  ontologies = @schemas.values.collect() { |schema|
    schema.ontology
  }
  return ontologies.sort { |x,y| x.short_name <=> y.short_name }
end

#ontologiesAsSvgObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/yowl/repository.rb', line 59

def ontologiesAsSvg
  if @options.verbose
    puts "Generating SVG for Ontology Import Diagram"
  end

  g = GraphvizUtility.setDefaults(GraphViz.new(:G, :type => :digraph))
    
  nodes = {}
  ontologies.each() do |ontology|
    nodeID = ontology.escaped_uri
    node = g.add_nodes(nodeID)
    node.URL = ontology.resourceNameHtml
    node.label = ontology.short_name
    node.tooltip = ontology.commentOrLabel
    nodes[nodeID] = node
  end
 
  ontologies.each() do |ontology|
    if @options.verbose
      puts "- Processing ontology #{ontology.escaped_uri}"
    end
    ontology.imports.each() do |import|
      importNode = nodes[import.name]
      if importNode
        if @options.verbose
          puts "  - Processing import #{import.name}"
        end
        g.add_edges(nodes[ontology.short_name], importNode)
      else
        if @options.verbose
          puts "  - Processing import #{import.name}, not found"
        end
      end
    end
  end

  #puts g.to_dot()
  return GraphvizUtility.embeddableSvg(g)
end