summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2012-10-11 15:18:17 +0200
committerAndreas Maunz <andreas@maunz.de>2012-10-11 15:18:17 +0200
commitd07753768f388be5008c0da9f4d0035920e8ec35 (patch)
tree2b28f1a70a4799106812bde61287933de7936e58
parentc0b7b4e0267ca61d195a7531c3e36e76b400bb5d (diff)
Library function for looking up features
-rw-r--r--lib/utils/html.rb3
-rw-r--r--lib/utils/shims/feature.rb18
-rw-r--r--webapp/compound.rb17
3 files changed, 22 insertions, 16 deletions
diff --git a/lib/utils/html.rb b/lib/utils/html.rb
index f470a7d..aa4fe25 100644
--- a/lib/utils/html.rb
+++ b/lib/utils/html.rb
@@ -7,7 +7,8 @@ class String
# encloses URI in text with with link tag
# @return [String] new text with marked links
def link_urls
- self.gsub(/(?i)http(s?):\/\/[^\r\n\s']*/, '<a href="\0">\0</a>')
+ regex = Regexp.new '(https?:\/\/[\S]+)([>"])'
+ self.gsub( regex, '<a href="\1">\1</a>\2' )
end
end
diff --git a/lib/utils/shims/feature.rb b/lib/utils/shims/feature.rb
index e8ce118..2ba8171 100644
--- a/lib/utils/shims/feature.rb
+++ b/lib/utils/shims/feature.rb
@@ -16,6 +16,24 @@ module OpenTox
f
end
+ # Load a feature given its title, create if not present, using metadata
+ # @param[String] title
+ # @return [OpenTox::Feature] Feature object with the full data
+ def self.find_by_title(title, metadata)
+ feature_uri = nil
+ sparql = "SELECT DISTINCT ?feature WHERE { ?feature <#{RDF.type}> <#{RDF::OT['feature'.capitalize]}>. ?feature <#{RDF::DC.title}> '#{title.to_s}' }"
+ feature_uri = OpenTox::Backend::FourStore.query(sparql,"text/uri-list").split("\n").first # is nil for non-existing feature
+ unless feature_uri
+ feature = OpenTox::Feature.new feature_uri, @subjectid
+ feature.title = title
+ feature.metadata = metadata
+ feature.put
+ else
+ feature = OpenTox::Feature.find(feature_uri, @subjectid)
+ end
+ feature
+ end
+
# Find out feature type
# Classification takes precedence
# @return [String] Feature type
diff --git a/webapp/compound.rb b/webapp/compound.rb
index 2ae0d40..a4c32d9 100644
--- a/webapp/compound.rb
+++ b/webapp/compound.rb
@@ -117,25 +117,12 @@ module OpenTox
end
end
- # Creator URI
- creator_uri = File.join url_for("/compound/#{inchi}/pc",:full), f
-
# Search feature by title
- feature_uri = nil
- sparql = "SELECT DISTINCT ?feature WHERE { ?feature <#{RDF.type}> <#{RDF::OT['feature'.capitalize]}>. ?feature <#{RDF::DC.title}> '#{f.to_s}' }"
- feature_uri = OpenTox::Backend::FourStore.query(sparql,"text/uri-list").split("\n").first # is nil for non-existing feature
- unless feature_uri
- feature = OpenTox::Feature.new feature_uri, @subjectid
- feature.title = f.to_s
- feature.metadata = {
+ metadata = {
RDF.type => [RDF::OT.Feature, RDF::OT.NumericFeature],
- RDF::DC.creator => creator_uri,
RDF::DC.description => description
}
- feature.put
- else
- feature = OpenTox::Feature.find(feature_uri, @subjectid)
- end
+ feature = OpenTox::Feature.find_by_title(f.to_s, metadata)
features << feature
end
}