Class: YOWL::Property

Inherits:
LabelledDocObject show all
Defined in:
lib/yowl/property.rb

Instance Attribute Summary

Attributes inherited from DocObject

#resource, #schema

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LabelledDocObject

#<=>, #comment, #commentOrLabel, #definition, #editorialNotes, #hasComment?, #hasDefinition?, #hasDifferentLabel?, #hasEditorialNotes?, #label, #status

Methods inherited from DocObject

#escaped_short_name, #escaped_uri, #get_literal, #hasOtherNamespace?, #hasUri?, #ns, #ontology, #repository, #short_name, #to_s, #uri

Constructor Details

#initialize(resource, schema) ⇒ Property

Returns a new instance of Property.



7
8
9
# File 'lib/yowl/property.rb', line 7

def initialize(resource, schema)
  super(resource, schema)
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) to another node (always representing a Property)



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/yowl/property.rb', line 170

def Property.newGraphVizEdge(graph_, domainNode_, rangeNode_, constraint_ = true)
  options = {
    :arrowhead => "empty", 
    :dir => "back",
    :label => "is a", 
    :arrowsize => 0.5,
    :penwidth => 0.5,
    :constraint => constraint_
  }
  if not constraint_
    options[:style] = :dashed
  end
  return graph_.add_edges(
    rangeNode_,
    domainNode_,
    options
  )
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.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/yowl/property.rb', line 94

def addAsGraphvizNode (graph_, nodes_, edges_)
  name = short_name
  if @schema.options.verbose
    puts "- Processing property #{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 = "#prop_#{short_name}"
  
  if name.include?(':')
    prefix = name.sub(/:\s*(.*)/, "")
    name = name.sub(/(.*)\s*:/, "")
    #
    # Can't get HTML labels to work
    #
    #node.label = "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"><TR><TD>#{name}</TD></TR><TR><TD><I>(#{prefix})</I></TD></TR></TABLE>"
    node.label = "#{name}\n(#{prefix})"
  else
    node.label = name
  end 
  if hasComment?
    node.tooltip = comment
  end
  nodes_[uri] = node
  return nodes_, edges_
end

#domainObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/yowl/property.rb', line 57

def domain()
  domains = []
  @schema.model.query(
    RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.domain)
  ) do |statement|
    domains << statement.object
  end  
  classes = []
  domains.each do |o|
    if o.resource?
      uri = o.to_s         
      if @schema.classes[uri]
        classes << @schema.classes[uri]
      else
        classes << uri
      end
    end
    #TODO union
  end
  return classes
end

#perPropertyDiagramAsSvgObject

Generate a diagram for each Property, the “per property diagram”



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/yowl/property.rb', line 130

def perPropertyDiagramAsSvg
  #if @schema.options.verbose
  #  puts "Generating SVG Per Property 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.embeddableSvg(g)
end

#rangeObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/yowl/property.rb', line 36

def range()
  ranges = []
  @schema.model.query(
    RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.range)
  ) do |statement|
    ranges << statement.object
  end  
  classes = []
  ranges.each do |o|
    if o.resource?
      uri = o.to_s        
      if @schema.classes[uri]
        classes << @schema.classes[uri]
      else
        classes << uri
      end
    end
  end
  return classes
end

#see_alsosObject



11
12
13
14
15
16
17
18
19
# File 'lib/yowl/property.rb', line 11

def see_alsos()
   links = []
   @schema.model.query(
     RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.seeAlso)
   ) do |statement|
     links << statement.object.to_s
   end       
   return links
end

#sub_propertiesObject



79
80
81
82
83
84
85
86
87
# File 'lib/yowl/property.rb', line 79

def sub_properties()
  list = []
  @schema.model.query(
    RDF::Query::Pattern.new(nil, YOWL::Namespaces::RDFS.subPropertyOf, @resource)
  ) do |statement|
    list << YOWL::Property.new(statement.subject, @schema)
  end
  return list
end

#sub_property_ofObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yowl/property.rb', line 21

def sub_property_of()
  parent = @schema.model.first_value(
    RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.subPropertyOf)
  )
  if parent
    uri = parent.to_s
    if @schema.properties[uri]
      return @schema.properties[uri]
    else
      return uri
    end
  end
  return nil
end