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-client.rb | 2 +- lib/opentox.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/opentox-client.rb b/lib/opentox-client.rb index 7d9329d..e68fd7f 100644 --- a/lib/opentox-client.rb +++ b/lib/opentox-client.rb @@ -14,7 +14,7 @@ RDF::OT1 = RDF::Vocabulary.new 'http://www.opentox.org/api/1.1#' RDF::OTA = RDF::Vocabulary.new 'http://www.opentox.org/algorithmTypes.owl#' #CLASSES = ["Compound", "Feature", "Dataset", "Algorithm", "Model", "Validation", "Task", "ErrorReport", "Investigation"] -CLASSES = ["Compound", "Feature", "Dataset", "Algorithm", "Model", "Validation", "Task", "Investigation"] +CLASSES = ["Generic", "Compound", "Feature", "Dataset", "Algorithm", "Model", "Validation", "Task", "Investigation"] RDF_FORMATS = [:rdfxml,:ntriples,:turtle] $default_rdf = "application/rdf+xml" 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