Class: DOWL::Schema

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

Overview

Utility class providing access to information about the schema, e.g. its description, lists of classes, etc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, introduction = nil) ⇒ Schema

Returns a new instance of Schema.



12
13
14
15
16
# File 'lib/dowl/schema.rb', line 12

def initialize(model, introduction=nil)
    @model = model
    @introduction = introduction
    init()
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



10
11
12
# File 'lib/dowl/schema.rb', line 10

def classes
  @classes
end

#datatype_propertiesObject (readonly)

Returns the value of attribute datatype_properties.



8
9
10
# File 'lib/dowl/schema.rb', line 8

def datatype_properties
  @datatype_properties
end

#introductionObject (readonly)

Returns the value of attribute introduction.



7
8
9
# File 'lib/dowl/schema.rb', line 7

def introduction
  @introduction
end

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/dowl/schema.rb', line 6

def model
  @model
end

#object_propertiesObject (readonly)

Returns the value of attribute object_properties.



9
10
11
# File 'lib/dowl/schema.rb', line 9

def object_properties
  @object_properties
end

Class Method Details

.create_from_file(file = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dowl/schema.rb', line 18

def Schema.create_from_file(file=nil)
  if file == nil
    raise "Filename should be provided"
  end
  model = RDF::Graph.new(file)
  model.load!
  
  dir = File.dirname(file)
  introduction = File.join(dir, "introduction.html")
  if File.exists?(introduction)
    return Schema.new(model, introduction)
  end      
  return Schema.new(model)
end

Instance Method Details

#initObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dowl/schema.rb', line 33

def init()
  @classes = Hash.new
  init_classes( DOWL::Namespaces::OWL.Class )
  init_classes( DOWL::Namespaces::RDFS.Class )
  ontology = @model.first_subject( RDF::Query::Pattern.new( nil, RDF.type, DOWL::Namespaces::OWL.Ontology ) )
  if ontology
    @ontology = Ontology.new(ontology, self)
  end
  @datatype_properties = init_properties( DOWL::Namespaces::OWL.DatatypeProperty)      
  @object_properties = init_properties( DOWL::Namespaces::OWL.ObjectProperty)
end

#init_classes(type) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/dowl/schema.rb', line 49

def init_classes(type)
  @model.query( RDF::Query::Pattern.new( nil, RDF.type, type ) ) do |statement|
    if !statement.subject.anonymous?
        cls = DOWL::Class.new(statement.subject, self)
        @classes[ statement.subject.to_s ] = cls                    
    end
  end      
end

#init_properties(type) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/dowl/schema.rb', line 58

def init_properties(type)
  properties = Hash.new
  @model.query( RDF::Query::Pattern.new( nil, RDF.type, type ) ) do |statement|
    properties[ statement.subject.to_s] = DOWL::Property.new(statement.subject, self)
  end      
  return properties      
end

#list_classesObject

Return sorted, nested array



83
84
85
86
# File 'lib/dowl/schema.rb', line 83

def list_classes()
  sorted = classes().sort { |x,y| x[1] <=> y[1] }
  return sorted      
end

#list_datatype_propertiesObject



74
75
76
# File 'lib/dowl/schema.rb', line 74

def list_datatype_properties()
  return datatype_properties().sort { |x,y| x[1] <=> y[1] }
end

#list_object_propertiesObject



78
79
80
# File 'lib/dowl/schema.rb', line 78

def list_object_properties()
  return object_properties().sort { |x,y| x[1] <=> y[1] }
end

#list_propertiesObject



70
71
72
# File 'lib/dowl/schema.rb', line 70

def list_properties()
  return properties().sort { |x,y| x[1] <=> y[1] }          
end

#ontologyObject



45
46
47
# File 'lib/dowl/schema.rb', line 45

def ontology()
  return @ontology  
end

#propertiesObject



66
67
68
# File 'lib/dowl/schema.rb', line 66

def properties()
  return @datatype_properties.merge( @object_properties )     
end