summaryrefslogtreecommitdiff
path: root/validate-owl.rb
blob: 2152e7d5a05601817ee100efb8ceb00e49e74e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def validate_owl(uri, subjectid=nil)
  if validator_available?
    owl = OpenTox::RestClientWrapper.get(uri,{:accept => "application/rdf+xml",:subjectid => subjectid}, nil, false)
    html = OpenTox::RestClientWrapper.post("http://www.mygrid.org.uk/OWL/Validator",{:rdf => owl, :level => "DL",:subjectid => subjectid})
    # assert_match(/YES/,html)
    # avoid verbose html output if validation fails
    owl_dl = false
    owl_dl = true if html =~ /YES/
    assert_equal true, owl_dl, "Invalid OWL-DL: #{uri}"
  else
    puts "http://www.mygrid.org.uk/OWL/Validator offline"
  end
end

def validator_available?
  uri = URI.parse "http://www.mygrid.org.uk/OWL/Validator"
  Net::HTTP.start(uri.host, uri.port) do |http| 
    begin
      http.read_timeout = 5
      http.head(uri.path).code == '200' 
    rescue Timeout::Error
      false
    end
  end
end