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
32
33
# 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)
  if File.exists?(File.join(dir, "introduction.html"))         
    return Schema.new(model, File.join(dir, "introduction.html"))
  elsif File.exists?( File.join(dir, "introduction.md"))
    return Schema.new(model, File.join(dir, "introduction.md"))
  else
    return Schema.new(model)
  end            
end

Instance Method Details

#initObject



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

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



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

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



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

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



85
86
87
88
# File 'lib/dowl/schema.rb', line 85

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

#list_datatype_propertiesObject



76
77
78
# File 'lib/dowl/schema.rb', line 76

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

#list_object_propertiesObject



80
81
82
# File 'lib/dowl/schema.rb', line 80

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

#list_propertiesObject



72
73
74
# File 'lib/dowl/schema.rb', line 72

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

#ontologyObject



47
48
49
# File 'lib/dowl/schema.rb', line 47

def ontology()
  return @ontology  
end

#propertiesObject



68
69
70
# File 'lib/dowl/schema.rb', line 68

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