Class: YOWL::Class
- Inherits:
-
LabelledDocObject
- Object
- DocObject
- LabelledDocObject
- YOWL::Class
- Includes:
- Comparable
- Defined in:
- lib/yowl/class.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Return a collection of Associations representing ObjectProperties where the current class is one of the Domain classes.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#subClasses ⇒ Object
readonly
Returns the value of attribute subClasses.
Attributes inherited from DocObject
Class Method Summary collapse
-
.newGraphVizEdge(graph_, domainNode_, rangeNode_, constraint_ = true) ⇒ Object
Create the GraphVis Edge for all “is a” (rdf:type) associations from a node (representing a Class or Individual) to another node (always representing a Class).
- .withUri(resource, schema) ⇒ Object
Instance Method Summary collapse
-
#addAsGraphvizNode(graph_, nodes_, edges_) ⇒ Object
Add the current class as a GraphViz node to the given collection of nodes and to the given graph.
- #hasSubClasses? ⇒ Boolean
- #hasSuperClasses? ⇒ Boolean
- #hasSuperClassesInSchema? ⇒ Boolean
-
#perClassDiagramAsSvg ⇒ Object
Generate a diagram for each class, the “per class diagram”.
- #short_name ⇒ Object
- #super_classes ⇒ Object
Methods inherited from LabelledDocObject
#<=>, #comment, #commentOrLabel, #definition, #editorialNotes, #hasComment?, #hasDefinition?, #hasDifferentLabel?, #hasEditorialNotes?, #label, #see_alsos, #status
Methods inherited from DocObject
#escaped_short_name, #escaped_uri, #get_literal, #hasOtherNamespace?, #hasUri?, #ns, #ontology, #repository, #to_s, #uri
Instance Attribute Details
#associations ⇒ Object (readonly)
Return a collection of Associations representing ObjectProperties where the current class is one of the Domain classes.
138 139 140 |
# File 'lib/yowl/class.rb', line 138 def associations @associations end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/yowl/class.rb', line 7 def resource @resource end |
#subClasses ⇒ Object (readonly)
Returns the value of attribute subClasses.
8 9 10 |
# File 'lib/yowl/class.rb', line 8 def subClasses @subClasses end |
Class Method Details
.newGraphVizEdge(graph_, domainNode_, rangeNode_, constraint_ = true) ⇒ Object
Create the GraphVis Edge for all “is a” (rdf:type) associations from a node (representing a Class or Individual) to another node (always representing a Class)
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/yowl/class.rb', line 274 def Class.newGraphVizEdge(graph_, domainNode_, rangeNode_, constraint_ = true) = { :arrowhead => :empty, :arrowsize => 0.5, :dir => :back, :label => "is a", :labeldistance => 2, :penwidth => 0.5, :constraint => constraint_ } if not constraint_ [:style] = :dashed end return graph_.add_edges( rangeNode_, domainNode_, ) end |
.withUri(resource, schema) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/yowl/class.rb', line 20 def Class.withUri(resource, schema) if resource.anonymous? warn "WARNING: Ignoring class with uri #{resource.to_s}" return end klass = schema.classes[resource.to_s] if klass return klass end klass = Class.new(resource, schema) schema.classes[resource.to_s] = klass if schema..verbose puts "Created class #{klass.short_name}" end return klass end |
Instance Method Details
#addAsGraphvizNode(graph_, nodes_, edges_) ⇒ Object
Add the current class as a GraphViz node to the given collection of nodes and to the given graph. Return the collection of nodes.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/yowl/class.rb', line 190 def addAsGraphvizNode (graph_, nodes_, edges_) name = short_name if @schema..verbose puts "- Processing class #{name}" end # # No need to add a node twice # if nodes_.has_key? uri return nodes_, edges_ end node = graph_.add_nodes(escaped_uri) node.URL = "#class_#{short_name}" prefix = nil if name.include?(':') prefix = name.sub(/:\s*(.*)/, "") name = name.sub(/(.*)\s*:/, "") end name = name.split(/(?=[A-Z])/).join(' ') if prefix # # Can't get HTML labels to work # #name = "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"><TR><TD>#{name}</TD></TR><TR><TD><I>(#{prefix})</I></TD></TR></TABLE>" name = "#{name}\n(#{prefix})" end node.label = name if hasComment? node.tooltip = comment else if hasDefinition? node.tooltip = definition end end nodes_[uri] = node return nodes_, edges_ end |
#hasSubClasses? ⇒ Boolean
129 130 131 |
# File 'lib/yowl/class.rb', line 129 def hasSubClasses? return ! subClasses.empty?() end |
#hasSuperClasses? ⇒ Boolean
91 92 93 |
# File 'lib/yowl/class.rb', line 91 def hasSuperClasses? return ! super_classes.empty?() end |
#hasSuperClassesInSchema? ⇒ Boolean
96 97 98 99 100 101 102 103 |
# File 'lib/yowl/class.rb', line 96 def hasSuperClassesInSchema? super_classes.each() do |klass| if @schema.classes.include?(klass.uri) return true end end return false end |
#perClassDiagramAsSvg ⇒ Object
Generate a diagram for each class, the “per class diagram”
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/yowl/class.rb', line 234 def perClassDiagramAsSvg #if @schema.options.verbose # puts "Generating SVG Per Class Diagram for #{short_name}" #end g = GraphvizUtility.setDefaults(GraphViz.new(:G, :type => :digraph)) g[:rankdir] = "LR" g.node[:fixedsize] = false nodes = Hash.new edges = Hash.new nodes, edges = addAsGraphvizNode(g, nodes, edges) # # Do the "outbound" associations first # associations.each do |association| nodes, edges = association.rangeClass.addAsGraphvizNode(g, nodes, edges) nodes, edges = association.addAsGraphVizEdge(g, nodes, edges) end # # Then do the "inbound" associations # @schema.classes.values.to_set.each do |klass| klass.associations.each do |association| if self == association.rangeClass nodes, edges = association.rangeClass.addAsGraphvizNode(g, nodes, edges) nodes, edges = association.addAsGraphVizEdge(g, nodes, edges) end end end return GraphvizUtility.(g) end |
#short_name ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yowl/class.rb', line 38 def short_name() sn = super() if sn[0,7] == "http://" or sn[0,8] == "https://" if sn.include?('#') ns = sn.slice(/.*#/) else ns = sn.slice(/.*\//) end return sn[ns.length..-1] end return sn end |
#super_classes ⇒ Object
52 53 54 55 56 57 58 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 |
# File 'lib/yowl/class.rb', line 52 def super_classes() if not @super_classes.nil? return @super_classes end @super_classes = [] @schema.model.query( RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.subClassOf) ) do |statement| # # Only look at statements like these: # # <rdfs:subClassOf rdf:resource="<uri>"/> # # And ignore statements like these: # # <rdfs:subClassOf> # <owl:Restriction> # <owl:onProperty rdf:resource="<uri>"/> # <owl:allValuesFrom rdf:resource="<uri>"/> # </owl:Restriction> # </rdfs:subClassOf> # if statement.object.uri? superClass = Class.withUri(statement.object, @schema) if superClass if superClass != self @super_classes << superClass end else warn "WARNING: Could not find super class #{statement.object.to_s}" end end end return @super_classes end |