diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-02-21 13:52:00 +0100 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-02-21 13:52:00 +0100 |
commit | 80d49f60ac55cc2fb1c7974752e1e947fa3f3f70 (patch) | |
tree | 73ffdbcebfab9debc1dd17284fe6623f245a479e | |
parent | 1bac8bd64f9f703d7e20a65da0ffb05cb150e90f (diff) |
clean uri now works for https, rdf parsing issues: /features and ?feature_uris, missing subjectid
-rw-r--r-- | lib/dataset.rb | 2 | ||||
-rw-r--r-- | lib/helper.rb | 5 | ||||
-rw-r--r-- | lib/parser.rb | 43 | ||||
-rw-r--r-- | lib/rest_client_wrapper.rb | 3 |
4 files changed, 36 insertions, 17 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb index efab0a3..3f530e6 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -141,8 +141,10 @@ module OpenTox if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) copy YAML.load(RestClientWrapper.get(@uri, {:accept => "application/x-yaml", :subjectid => subjectid})) else + puts "loading all.." parser = Parser::Owl::Dataset.new(@uri, subjectid) copy parser.load_uri(subjectid) + puts "..done" end end diff --git a/lib/helper.rb b/lib/helper.rb index a1590d7..b30908c 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -32,8 +32,9 @@ helpers do uri = uri[0,uri.index("InChI=")] if uri.index("InChI=") out = URI.parse(uri) - out.path = out.path[0, out.path.length - (out.path.reverse.rindex(/\/{1}\d+\/{1}/))] if out.path.index(/\/{1}\d+\/{1}/) #cuts after /id/ for a&a - "#{out.scheme}:" + (out.port != 80 ? out.port : "") + "//#{out.host}#{out.path.chomp('/')}" + out.path = out.path[0, out.path.length - (out.path.reverse.rindex(/\/{1}\d+\/{1}/))] if out.path.index(/\/{1}\d+\/{1}/) #cuts after /id/ for a&a + port = (out.scheme=="http" && out.port==80)||(out.scheme=="https" && out.port==443) ? "" : ":#{out.port.to_s}" + "#{out.scheme}://#{out.host}#{port}#{out.path.chomp("/")}" #" end #unprotected uri for login diff --git a/lib/parser.rb b/lib/parser.rb index d2beeac..f1249ad 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -39,7 +39,14 @@ module OpenTox file = File.new(@uri) else file = Tempfile.new("ot-rdfxml") - uri = @dataset ? File.join(@uri,"metadata") : @uri + if @dataset + # do not concat /metadata to uri string, this would not work for dataset/R401577?max=3 + uri = URI::parse(@uri) + uri.path = File.join(uri.path,"metadata") + uri = uri.to_s + else + uri = @uri + end file.puts OpenTox::RestClientWrapper.get uri,{:subjectid => subjectid,:accept => "application/rdf+xml"},nil,false file.close to_delete = file.path @@ -163,26 +170,31 @@ module OpenTox data[triple[0]] = {:compound => "", :values => []} unless data[triple[0]] data[triple[0]][:compound] = triple[2] when /#{OT.feature}/i - feature[triple[0]] = triple[2] + feature[triple[0]] = triple[2] else end end File.delete(to_delete) if to_delete data.each do |id,entry| - entry[:values].each do |value_id| - split = feature_values[value_id].split(/\^\^/) - case split[-1] - when XSD.double, XSD.float - value = split.first.to_f - when XSD.boolean - value = split.first=~/(?i)true/ ? true : false - else - value = split.first + if entry[:values].size==0 + # no feature values add plain compounds + @dataset.add_compound(entry[:compound]) + else + entry[:values].each do |value_id| + split = feature_values[value_id].split(/\^\^/) + case split[-1] + when XSD.double, XSD.float + value = split.first.to_f + when XSD.boolean + value = split.first=~/(?i)true/ ? true : false + else + value = split.first + end + @dataset.add entry[:compound],feature[value_id],value end - @dataset.add entry[:compound],feature[value_id],value end end - load_features + load_features subjectid @dataset.metadata = load_metadata(subjectid) @dataset end @@ -194,7 +206,10 @@ module OpenTox file = File.new(@uri) else file = Tempfile.new("ot-rdfxml") - uri = File.join(@uri,"features") + # do not concat /features to uri string, this would not work for dataset/R401577?max=3 + uri = URI::parse(@uri) + uri.path = File.join(uri.path,"features") + uri = uri.to_s file.puts OpenTox::RestClientWrapper.get uri,{:subjectid => subjectid,:accept => "application/rdf+xml"},nil,false file.close to_delete = file.path diff --git a/lib/rest_client_wrapper.rb b/lib/rest_client_wrapper.rb index d3136c7..dac24dc 100644 --- a/lib/rest_client_wrapper.rb +++ b/lib/rest_client_wrapper.rb @@ -76,7 +76,8 @@ module OpenTox else result = resource.send(rest_call, headers) end - + #LOGGER.debug "result body size: #{result.body.size}" + # PENDING NTUA does return errors with 200 raise RestClient::ExceptionWithResponse.new(result) if uri=~/ntua/ and result.body =~ /about.*http:\/\/anonymous.org\/error/ |