From d657955ef09c69ce66e2eda3a03dbf4b87461915 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 14 Mar 2012 10:15:36 +0000 Subject: Fallback for OpenTox class if URI is ambiguous --- lib/opentox.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/opentox.rb') 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 -- cgit v1.2.3