summaryrefslogtreecommitdiff
path: root/lib/opentox.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-03-14 10:15:36 +0000
committerChristoph Helma <helma@in-silico.ch>2012-03-14 10:15:36 +0000
commitd657955ef09c69ce66e2eda3a03dbf4b87461915 (patch)
treed935d03e532a8a4e37c2fe4edade635d02639bd4 /lib/opentox.rb
parent625c88673e90053f898423dfc96bda1d6c0fa8eb (diff)
Fallback for OpenTox class if URI is ambiguous
Diffstat (limited to 'lib/opentox.rb')
-rw-r--r--lib/opentox.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 342b04e..944eda5 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -125,8 +125,12 @@ module OpenTox
# guess class from uri, this is potentially unsafe, but polling metadata from large uri lists is way too slow (and not all service provide RDF.type in their metadata)
result = CLASSES.collect{|s| s if uri =~ /#{s.downcase}/}.compact
- internal_server_error "Cannot determine class from URI: '#{uri}.\nCandidate classes are #{result.inspect}" unless result.size == 1
- klass = result.first
+ if result.size == 1
+ klass = result.first
+ else
+ klass = OpenTox::Generic.new(uri)[RDF.type]
+ internal_server_error "Cannot determine class from URI '#{uri} (Candidate classes are #{result.inspect}) or matadata." unless klass
+ end
# initialize with/without subjectid
subjectid ? eval("#{self}.new(\"#{uri}\", #{subjectid})") : eval("#{self}.new(\"#{uri}\")")
end