Class | OwllinkController |
In: |
app/controllers/owllink_controller.rb
|
Parent: | ApplicationController |
# File app/controllers/owllink_controller.rb, line 13 13: def connect 14: begin 15: Owllink.connect session 16: @request = "" 17: @reply = "" 18: self.describe 19: if @reply && !@reply.empty? 20: reply_doc = REXML::Document.new(@reply) 21: 22: reasoner_version = reply_doc.root.elements['/ResponseMessage/Description/ReasonerVersion'] 23: Owllink.set_name(session, "#{reply_doc.root.elements[1,'Description'].attributes['name']} #{reasoner_version.attributes['major']}.#{reasoner_version.attributes['minor']}.#{reasoner_version.attributes['build']}") 24: 25: owllink_version = reply_doc.root.elements['/ResponseMessage/Description/ProtocolVersion'] 26: Owllink.set_owllink_version(session, "#{owllink_version.attributes['major']}.#{owllink_version.attributes['minor']}") 27: 28: # check if abbreviatesIRIs is a Setting (an not a Property) 29: abbreviatesIRIs_setting = !(REXML::XPath.match reply_doc, "//Setting[@key='abbreviatesIRIs']").nil? 30: Owllink.set_abbreviates_setting(session,abbreviatesIRIs_setting) 31: 32: # check abbreviatesIRIs status (if not connected as this gives only the default!) 33: if !Owllink.connected? 34: if abbreviatesIRIs_setting 35: abbreviatesIRIs = (REXML::XPath.first reply_doc, "//Setting[@key='abbreviatesIRIs']/Literal/text()").value() == "true" 36: else 37: abbreviatesIRIs = (REXML::XPath.first reply_doc, "//Property[@key='abbreviatesIRIs']/Literal/text()").value() == "true" 38: end 39: Owllink.set_abbreviates_iris(session,abbreviatesIRIs) 40: end 41: 42: # check if <SupportedExtension identifier="http://www.owllink.org/ext/retraction"/> is part of the Description 43: retraction = REXML::XPath.match reply_doc, "//SupportedExtension[@identifier='http://www.owllink.org/ext/retraction']" 44: Owllink.set_supports_retraction(session,!retraction.nil? && !retraction.empty?) 45: end 46: rescue Exception => exc 47: logger.error("Exception: #{exc.message}") 48: flash[:notice] = "Exception: #{exc.message}" 49: redirect_to :action => 'index' 50: end 51: end
# File app/controllers/owllink_controller.rb, line 198 198: def describe 199: begin 200: @request = Owllink.request_message {|xml| xml.GetDescription} 201: @reply = Owllink.post_request(@request) 202: rescue Exception => exc 203: logger.error("Exception: #{exc.message}") 204: flash[:notice] = "Exception: #{exc.message}" 205: redirect_to :action => 'index' 206: end 207: end
# File app/controllers/owllink_controller.rb, line 53 53: def disconnect 54: begin 55: Owllink.disconnect(session) 56: Owllink.set_name(session,nil) 57: Owllink.set_owllink_version(session,nil) 58: unless @request && @reply 59: flash[:notice] = "Disconnected." 60: render :action => 'index' 61: end 62: rescue Exception => exc 63: logger.error("Exception: #{exc.message}") 64: flash[:notice] = "Exception: #{exc.message}" 65: redirect_to :action => 'index' 66: end 67: end
# File app/controllers/owllink_controller.rb, line 69 69: def init 70: begin 71: @request1 = Owllink.request_message(:namespaces => { 72: :owl => "http://www.w3.org/2002/07/owl#" 73: }) {|xml| 74: xml.CreateKB(:name => "#{Owllink.get_server_id session}") { 75: xml.Prefix(:name => "agent", :fullIRI => "http://www.iyouit.eu/agent.owl#") 76: xml.Prefix(:name => "time", :fullIRI => "http://www.iyouit.eu/time.owl#") 77: xml.Prefix(:name => "space", :fullIRI => "http://www.iyouit.eu/space.owl#") 78: xml.Prefix(:name => "situation", :fullIRI => "http://www.iyouit.eu/situation.owl#") 79: } 80: } 81: @reply1 = Owllink.post_request(@request1) 82: axioms = File.read("#{RAILS_ROOT}/lib/situation-owllink.xml").to_s 83: 84: reply1_doc = REXML::Document.new(@reply1) 85: kb = reply1_doc.root.elements[1,'KB'].attributes['kb'] 86: @request2 = Owllink.request_message(:namespaces => { 87: :owl => "http://www.w3.org/2002/07/owl#" 88: }) {|xml| 89: xml.Tell(:kb => kb) { 90: xml.text! "#axioms#" 91: } 92: } 93: @request2 = @request2.sub("#axioms#",axioms) 94: @reply2 = Owllink.post_request(@request2) 95: reply2_doc = REXML::Document.new(@reply2) 96: first_result = reply2_doc.root.elements['/ResponseMessage/*[1]'] 97: if first_result.name == "OK" 98: Owllink.set_kb(session,kb) 99: Owllink.set_initialized(session,true) 100: end 101: rescue Exception => exc 102: logger.error("Exception: #{exc.message}") 103: flash[:notice] = "Exception: #{exc.message}" 104: redirect_to :action => 'index' 105: end 106: end
# File app/controllers/owllink_controller.rb, line 114 114: def populate 115: begin 116: kb = Owllink.get_kb session 117: @request = Owllink.request_message(:namespaces => { 118: :owl => "http://www.w3.org/2002/07/owl#" 119: }) {|xml| 120: xml.GetSubClasses(:kb => kb, :direct => "false") { 121: xml.owl(:Class, :abbreviatedIRI => "space:Place""space:Place") 122: } 123: xml.GetSubClasses(:kb => kb, :direct => "false") { 124: xml.owl(:Class, :abbreviatedIRI => "time:Interval_thing""time:Interval_thing") 125: } 126: xml.GetSubObjectProperties(:kb => kb, :direct => "false") { 127: xml.owl(:ObjectProperty, :abbreviatedIRI => "agent:contact""agent:contact") 128: } 129: } 130: @reply = Owllink.post_request(@request) 131: reply_doc = REXML::Document.new(@reply) 132: reply_doc.elements.each("/ResponseMessage/*[1]/*/owl:Class") { |element| 133: abbrev_iri = element.attributes["abbreviatedIRI"] 134: if !abbrev_iri.nil? 135: place = abbrev_iri.split(':')[1] 136: else 137: place = element.attributes["IRI"].split('#')[1] 138: end 139: if !PlaceConcept.find_by_iri("space:" + place) 140: new_place = PlaceConcept.new 141: new_place.iri = "space:" + place 142: new_place.name = place.sub("_"," ").titleize 143: new_place.save 144: end 145: } 146: Rails.logger.info("log 2") 147: reply_doc.elements.each("/ResponseMessage/*[2]/*/owl:Class") { |element| 148: abbrev_iri = element.attributes["abbreviatedIRI"] 149: if !abbrev_iri.nil? 150: daytime = abbrev_iri.split(':')[1] 151: else 152: daytime = element.attributes["IRI"].split('#')[1] 153: end 154: if !DaytimeConcept.find_by_iri("space:" + daytime) 155: new_daytime = DaytimeConcept.new 156: new_daytime.iri = "space:" + daytime 157: new_daytime.name = daytime.sub("_"," ").titleize 158: new_daytime.save 159: end 160: } 161: Rails.logger.info("log 3") 162: reply_doc.elements.each("/ResponseMessage/*[3]/*/owl:ObjectProperty") { |element| 163: abbrev_iri = element.attributes["abbreviatedIRI"] 164: if !abbrev_iri.nil? 165: relation = abbrev_iri.split(':')[1] 166: else 167: relation = element.attributes["IRI"].split('#')[1] 168: end 169: if !Relation.find_by_iri("agent:" + relation) 170: new_relation = Relation.new 171: new_relation.iri = "agent:" + relation 172: new_relation.name = relation.sub("_"," ") 173: new_relation.save 174: end 175: } 176: rescue Exception => exc 177: logger.error("Exception: #{exc.message}") 178: flash[:notice] = "Exception: #{exc.message}" 179: redirect_to :action => 'index' 180: end 181: end
# File app/controllers/owllink_controller.rb, line 108 108: def release 109: unless @request && @reply 110: render :action => 'index' 111: end 112: end
# File app/controllers/owllink_controller.rb, line 183 183: def reset 184: begin 185: require 'active_record/fixtures' 186: Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')).each do |fixture_file| 187: Fixtures.create_fixtures("test/fixtures",File.basename(fixture_file, '.*')) 188: end 189: flash[:notice] = "DB initialized." 190: redirect_to :action => 'index' 191: rescue Exception => exc 192: logger.error("Exception: #{exc.message}") 193: flash[:notice] = "Exception: #{exc.message}" 194: redirect_to :action => 'index' 195: end 196: end
# File app/controllers/owllink_controller.rb, line 209 209: def set 210: begin 211: if Owllink.abbreviates_setting?(session) 212: abbreviatesIRIs = Owllink.abbreviates_iris?(session) 213: @request = Owllink.request_message {|xml| 214: xml.Set(:kb => Owllink.get_kb(session), :key => "abbreviatesIRIs") { 215: xml.Literal(abbreviatesIRIs ? "false" : "true") 216: } 217: } 218: @reply = Owllink.post_request(@request) 219: Owllink.set_abbreviates_iris(session,!abbreviatesIRIs) 220: end 221: rescue Exception => exc 222: logger.error("Exception: #{exc.message}") 223: flash[:notice] = "Exception: #{exc.message}" 224: redirect_to :action => 'index' 225: end 226: end
# File app/controllers/owllink_controller.rb, line 228 228: def settings 229: begin 230: @request = Owllink.request_message {|xml| xml.GetSettings(:kb => Owllink.get_kb(session))} 231: @reply = Owllink.post_request(@request) 232: rescue Exception => exc 233: logger.error("Exception: #{exc.message}") 234: flash[:notice] = "Exception: #{exc.message}" 235: redirect_to :action => 'index' 236: end 237: end
# File app/controllers/owllink_controller.rb, line 317 317: def bad_token 318: flash[:notice] = "Session has expired." 319: redirect_to :action => 'index' 320: end
# File app/controllers/owllink_controller.rb, line 265 265: def check_connected 266: begin 267: unless Owllink.connected?(session) 268: flash[:notice] = "Connect first!" 269: redirect_to :action => 'index' 270: end 271: rescue Exception => exc 272: logger.error("Exception: #{exc.message}") 273: flash[:notice] = "Exception: #{exc.message}" 274: redirect_to :action => 'index' 275: end 276: end
# File app/controllers/owllink_controller.rb, line 278 278: def check_initialized 279: begin 280: unless Owllink.initialized?(session) 281: flash[:notice] = "Initialize first!" 282: redirect_to :action => 'index' 283: end 284: rescue Exception => exc 285: logger.error("Exception: #{exc.message}") 286: flash[:notice] = "Exception: #{exc.message}" 287: redirect_to :action => 'index' 288: end 289: end
# File app/controllers/owllink_controller.rb, line 304 304: def check_not_connected 305: begin 306: if Owllink.connected?(session) 307: flash[:notice] = "Already connected." 308: redirect_to :action => 'index' 309: end 310: rescue Exception => exc 311: logger.error("Exception: #{exc.message}") 312: flash[:notice] = "Exception: #{exc.message}" 313: redirect_to :action => 'index' 314: end 315: end
# File app/controllers/owllink_controller.rb, line 291 291: def check_not_initialized 292: begin 293: if Owllink.initialized?(session) 294: flash[:notice] = "Already initialized." 295: redirect_to :action => 'index' 296: end 297: rescue Exception => exc 298: logger.error("Exception: #{exc.message}") 299: flash[:notice] = "Exception: #{exc.message}" 300: redirect_to :action => 'index' 301: end 302: end
# File app/controllers/owllink_controller.rb, line 242 242: def release_kb 243: begin 244: @request = nil 245: @reply = nil 246: if Owllink.initialized? session 247: kb = Owllink.get_kb session 248: if kb && !kb.empty? 249: @request = Owllink.request_message {|xml| 250: xml.ReleaseKB(:kb => kb) 251: } 252: @reply = Owllink.post_request(@request) 253: Owllink.set_kb(session,nil) 254: end 255: Owllink.set_initialized(session,false) 256: end 257: rescue Exception => exc 258: logger.error("Exception: #{exc.message}") 259: flash[:notice] = "Exception: #{exc.message}" 260: redirect_to :action => 'index' 261: end 262: end