Class: DOWL::Schema
- Inherits:
-
Object
- Object
- DOWL::Schema
- 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
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#datatype_properties ⇒ Object
readonly
Returns the value of attribute datatype_properties.
-
#introduction ⇒ Object
readonly
Returns the value of attribute introduction.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#object_properties ⇒ Object
readonly
Returns the value of attribute object_properties.
Class Method Summary collapse
Instance Method Summary collapse
- #init ⇒ Object
- #init_classes(type) ⇒ Object
- #init_properties(type) ⇒ Object
-
#initialize(model, introduction = nil) ⇒ Schema
constructor
A new instance of Schema.
-
#list_classes ⇒ Object
Return sorted, nested array.
- #list_datatype_properties ⇒ Object
- #list_object_properties ⇒ Object
- #list_properties ⇒ Object
- #ontology ⇒ Object
- #properties ⇒ Object
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
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
10 11 12 |
# File 'lib/dowl/schema.rb', line 10 def classes @classes end |
#datatype_properties ⇒ Object (readonly)
Returns the value of attribute datatype_properties.
8 9 10 |
# File 'lib/dowl/schema.rb', line 8 def datatype_properties @datatype_properties end |
#introduction ⇒ Object (readonly)
Returns the value of attribute introduction.
7 8 9 |
# File 'lib/dowl/schema.rb', line 7 def introduction @introduction end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/dowl/schema.rb', line 6 def model @model end |
#object_properties ⇒ Object (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
#init ⇒ Object
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_classes ⇒ Object
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_properties ⇒ Object
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_properties ⇒ Object
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_properties ⇒ Object
70 71 72 |
# File 'lib/dowl/schema.rb', line 70 def list_properties() return properties().sort { |x,y| x[1] <=> y[1] } end |
#ontology ⇒ Object
45 46 47 |
# File 'lib/dowl/schema.rb', line 45 def ontology() return @ontology end |
#properties ⇒ Object
66 67 68 |
# File 'lib/dowl/schema.rb', line 66 def properties() return @datatype_properties.merge( @object_properties ) end |