Class: OntologyGraph::ClassNode

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

Overview

Helper class that contains a node in the internal RDFS/OWL class graph

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ ClassNode

Create a new unconnected node with the given uri



9
10
11
12
13
# File 'lib/ontology_graph/class_node.rb', line 9

def initialize(uri)
  @uri = uri
  @subclasses = []
  @superclasses = []
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.



6
7
8
# File 'lib/ontology_graph/class_node.rb', line 6

def flags
  @flags
end

#subclassesObject

Returns the value of attribute subclasses.



6
7
8
# File 'lib/ontology_graph/class_node.rb', line 6

def subclasses
  @subclasses
end

#superclassesObject

Returns the value of attribute superclasses.



6
7
8
# File 'lib/ontology_graph/class_node.rb', line 6

def superclasses
  @superclasses
end

#uriObject

Returns the value of attribute uri.



6
7
8
# File 'lib/ontology_graph/class_node.rb', line 6

def uri
  @uri
end

Instance Method Details

#add_subclass(klass) ⇒ Object

Add the given class as a subclass



16
17
18
19
# File 'lib/ontology_graph/class_node.rb', line 16

def add_subclass(klass) 
  self.subclasses << klass
  klass.superclasses << self
end

#add_superclass(klass) ⇒ Object

Add the given class as a superclass



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

def add_superclass(klass)
  self.superclasses << klass
  klass.subclasses << self
end

#flag_usedObject

Flag this node as “used” (meaning that there are Resources having this class as it’s type)



29
30
31
# File 'lib/ontology_graph/class_node.rb', line 29

def flag_used
  @used = true
end

#inspectObject



67
68
69
# File 'lib/ontology_graph/class_node.rb', line 67

def inspect
  "<#{self.class.name}:#{self.object_id} @uri=\"#{uri}\" @subclasses = [#{subclasses.collect { |s| s.to_s}.join(', ')}] @superclasses = [#{superclasses.collect { |s| s.to_s}.join(', ')}] >"
end

#to_sObject



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

def to_s
  @uri
end

#to_uriObject



63
64
65
# File 'lib/ontology_graph/class_node.rb', line 63

def to_uri
  return N::SourceClass.new(@uri)
end

#used?Boolean

Indicates if the node is “used”, meaning if any resources have it as it’s type

Returns:

  • (Boolean)


35
36
37
# File 'lib/ontology_graph/class_node.rb', line 35

def used?
  @used
end

#weed_superclasses(root_path = []) ⇒ Object

Used to remove all “unreal superclasses”, that are created by inferencing. A superclass is “unreal” if it appears in the path to the root



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ontology_graph/class_node.rb', line 41

def weed_superclasses(root_path = [])
  superclasses.reject! do |sup|
    reject = false
    # Ignore the last element in the root path, wich points to the direct parent
    if(reject = root_path[0..-2].include?(sup))
      sup.subclasses.reject! { |cl| cl == self }
    end
    reject
  end
  # Clone the subclasses as some will be removed by the recursive calls
  full_subclasses = subclasses.clone
  full_subclasses.each { |sub| sub.weed_superclasses(root_path + [ self ]) }
end