Class: OMF::SFA::Model::Ontology
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::SFA::Model::Ontology
- Defined in:
- lib/omf-sfa/model/ontology.rb
Constant Summary collapse
- LOCAL_PREFIX =
URL prefix which we serve from local directory
'http://geni-orca.renci.org/owl/'
- LOCAL_DIR =
"#{File.dirname(__FILE__)}/../../../owl/"
- @@uri2inst =
{}
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uri, is_file = false) ⇒ Ontology
constructor
A new instance of Ontology.
- #parse ⇒ Object
Constructor Details
#initialize(uri, is_file = false) ⇒ Ontology
Returns a new instance of Ontology.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/omf-sfa/model/ontology.rb', line 59 def initialize(uri, is_file = false) @uri = uri if is_file f = File.open(uri) @doc = Nokogiri::XML(f) do |config| config.strict.noent.noblanks end f.close else raise "don't know how to import '#{uri}'" end parse() end |
Class Method Details
.import(uri) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/omf-sfa/model/ontology.rb', line 42 def self.import(uri) unless onto = @@uri2inst[uri] info "Loading ontology '#{uri}'" if uri.kind_of?(String) && uri.start_with?(LOCAL_PREFIX) file_name = uri.gsub(LOCAL_PREFIX, LOCAL_DIR) begin onto = @@uri2inst[uri] = self.new(file_name, true) rescue Errno::ENOENT puts ">>>> Unknown ontology '#{uri}'" end else raise "don't know how to import '#{uri}'" end end onto end |
Instance Method Details
#parse ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/omf-sfa/model/ontology.rb', line 74 def parse() def_ns = @doc.namespaces["xmlns"] @doc.root.children.each do |el| case el.node_name when 'Ontology' parse_onotology(el) when 'Class' ModelClassDescription.create_from_xml(el) when 'comment' # ignore when 'ObjectProperty' ModelObjectPropertyDescription.create_from_xml(el) when 'DatatypeProperty' ModelDataPropertyDescription.create_from_xml(el) when 'AnnotationProperty' # ignore else warn "Unknown element '#{el.node_name}' in '#{@uri}'" end end # @doc.xpath('//owl:Class', 'owl' => OWL_NS).each do |cel| # debug ModelClassDescription.create_from_xml(cel) # #debug c.attribute_with_ns('about', RDF_NS) # #debug c.namespaces["xmlns"].inspect #def_ns # #debug c.inspect # #exit # end end |