Skip to content

Commit

Permalink
Merge branch 'rest_api_revision'
Browse files Browse the repository at this point in the history
  • Loading branch information
palexander committed Oct 9, 2013
2 parents 6b16536 + 4ebe7f4 commit 061b84f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
46 changes: 29 additions & 17 deletions app/controllers/annotator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,41 @@ def create
#annotations = LinkedData::Client::HTTP.get(query)
LOG.add :debug, "Retrieved #{annotations.length} annotations: #{Time.now - start}s"
massage_annotated_classes(annotations, options) unless annotations.empty?
# Trying to generate highlighted match context in controller. More
# overhead on controller and more data transfer to the client.
# This is handled in bp_annotator.js, to move the processing load onto
# the client side in JS. (TODO: evaluate if JS handles UTF8.)
#annotations.each do |a|
# #annotation = a['annotations'].first
# #=> {"from"=>1, "to"=>8, "matchType"=>"PREF", "text"=>"MELANOMA"}
# a['annotations'].each do |annotation|
# position = [annotation['from'], annotation['to']]
# context = highlight_and_get_context(text_to_annotate, position)
# annotation['context'] = context
# end
#end
render :json => annotations
end


private


# TODO: Use this method to highlight matched classes in the annotation text. Currently done in JS on the client.
def highlight_and_get_context(text, position, words_to_keep = 4)
# Process the highlighted text
highlight = ["<span style='color: #006600; padding: 2px 0; font-weight: bold;'>", "", "</span>"]
highlight[1] = text.utf8_slice(position[0] - 1, position[1] - position[0] + 1)
# Use scan to split the text on spaces while keeping the spaces
scan_filter = Regexp.new(/[ ]+?[-\?'"\+\.,]+\w+|[ ]+?[-\?'"\+\.,]+\w+[-\?'"\+\.,]|\w+[-\?'"\+\.,]+|[ ]+?\w+/)
before = text.utf8_slice(0, position[0] - 1).match(/(\s+\S+|\S+\s+){0,4}$/).to_s
after = text.utf8_slice(position[1], ActiveSupport::Multibyte::Chars.new(text).length - position[1]).match(/^(\S+\s+\S+|\s+\S+|\S+\s+){0,4}/).to_s
# The process above will not keep a space right before the highlighted word, so let's keep it here if needed
# 32 is the character code for space
kept_space = text.utf8_slice(position[0] - 2) == " " ? " " : ""
# Put it all together
[before, kept_space, highlight.join, after].join
end

## This method can be used to highlight matched classes in the annotation text. Currently done in JS on the client.
#def highlight_and_get_context(text, position, words_to_keep = 4)
# # Process the highlighted text
# #highlight = ["<span style='color: #006600; padding: 2px 0; font-weight: bold;'>", "", "</span>"]
# highlight = ["<span class='annotator_context_highlight'>", "", "</span>"]
# highlight[1] = text.utf8_slice(position[0] - 1, position[1] - position[0] + 1)
# # Use scan to split the text on spaces while keeping the spaces
# #scan_filter = Regexp.new(/[ ]+?[-\?'"\+\.,]+\w+|[ ]+?[-\?'"\+\.,]+\w+[-\?'"\+\.,]|\w+[-\?'"\+\.,]+|[ ]+?\w+/)
# before = text.utf8_slice(0, position[0] - 1).match(/(\s+\S+|\S+\s+){0,4}$/).to_s
# after = text.utf8_slice(position[1], ActiveSupport::Multibyte::Chars.new(text).length - position[1]).match(/^(\S+\s+\S+|\s+\S+|\S+\s+){0,4}/).to_s
# # The process above will not keep a space right before the highlighted word, so let's keep it here if needed
# # 32 is the character code for space
# kept_space = text.utf8_slice(position[0] - 2) == " " ? " " : ""
# # Put it all together
# [before, kept_space, highlight.join, after].join
#end

end

8 changes: 4 additions & 4 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,16 @@ def show
redirect_to "/ontologies/#{params[:ontology]}#{params_string_for_redirect(params)}", :status => :moved_permanently
return
when "classes"
self.classes
self.classes rescue self.summary
return
when "mappings"
self.mappings
self.mappings rescue self.summary
return
when "notes"
self.notes
self.notes rescue self.summary
return
when "widgets"
self.widgets
self.widgets rescue self.summary
return
when "summary"
self.summary
Expand Down
7 changes: 3 additions & 4 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def count_links(ont_acronym, page_name='summary', count=0)
end

def classes_link(ontology, count)
count = 0 if ontology.summaryOnly
return "0" if (ontology.summaryOnly || count.nil? || count == 0)
return count_links(ontology.ontology.acronym, 'classes', count)
end

Expand All @@ -164,7 +164,7 @@ def download_link(submission)
end

def mappings_link(ontology, count)
count = 0 if ontology.summaryOnly
return "0" if (ontology.summaryOnly || count.nil? || count == 0)
return count_links(ontology.ontology.acronym, 'mappings', count)
end

Expand Down Expand Up @@ -215,10 +215,9 @@ def submission_status2string(sub)
# Link for private/public/licensed ontologies
def visibility_link(ontology)
ont_url = "/ontologies/#{ontology.acronym}" # 'ontology' is NOT a submission here
page_name = 'classes' # default ontology page view for visibility link
page_name = 'summary' # default ontology page view for visibility link
link_name = 'Public' # default ontology visibility
if ontology.summaryOnly
page_name = 'summary'
link_name = 'Summary Only'
elsif ontology.private?
link_name = 'Private'
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
\&nbsp;&nbsp;
%a{:href => "#", :onclick => "close_message(); return false;", :style => "font-size: small; color: darkGray;"} [close]
%div{:style => "padding:10px;margin:10px;"}
= t('home.intro').nil? || t('home.intro').empty? ? "<span style='font-size:2em'><b>Welcome to BioPortal!</b></span> For help using #{$SITE}, click on this icon: #{help_icon("/help#Home_Page")}" : t('home.intro')
= t('home.intro').nil? || t('home.intro').empty? ? "<span style='font-size:1.5em'><b>Welcome to BioPortal!</b> For help using #{$SITE}, click on this icon: #{help_icon("/help#Home_Page")}</span>" : t('home.intro')
%table{:width => "100%"}
%tr
%td{:valign => "top", :width => "33%"}
Expand Down
18 changes: 16 additions & 2 deletions app/views/ontologies/_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,34 @@
%tr
%th Visibility
%td= strip_links(visibility_link(@ontology))

- if !$PURL_ENABLED.nil? && $PURL_ENABLED && [email protected]
%tr
%th
= $SITE
PURL
= "#{$SITE} PURL".strip
%td
= auto_link(@ontology.purl, :all, :target => "_blank")

- if @ontology.viewing_restricted?
%tr
%th
Viewing Restriction
%td
= @ontology.viewingRestriction.capitalize

- if @ontology.respond_to?('viewOf')
- unless @ontology.viewOf.nil?
%tr
%th
View of Ontology
%td
- ont_parent_acronym = @ontology.viewOf.split('/').last
- if !$PURL_ENABLED.nil? && $PURL_ENABLED
- ont_url = @ontology.purl.sub(@ontology.acronym, ont_parent_acronym)
- else
- ont_url = @ontology.links['ui'].sub(@ontology.acronym, ont_parent_acronym)
= auto_link(ont_url, :all, :target => "_blank")

-# Get the latest submission (not necessarily the latest ready submission).
- sub = @submission_latest
- unless sub.nil? || (sub.respond_to?(:status) && sub.status == 404)
Expand Down
7 changes: 4 additions & 3 deletions public/javascripts/bp_annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,13 @@ function get_annotation_rows(annotation, text) {
var match_span = '<span style="color: rgb(153,153,153);">';
var match_markup_span = '<span style="color: rgb(35, 73, 121); font-weight: bold; padding: 2px 0px;">';
jQuery.each(annotation.annotations, function (i, a) {

// TODO: consider string truncation around the annotation markups.

text_match = text.substring(a.from - 1, a.to);
text_prefix = text.substring(0, a.from - 1);
text_suffix = text.substring(a.to);
// remove everything prior to the preceding three words (using space delimiters):
text_prefix = text_prefix.replace(/.* ((?:[^ ]* ){2}[^ ]*$)/, "... $1");
// remove the fourth space and everything following it:
text_suffix = text_suffix.replace(/^((?:[^ ]* ){3}[^ ]*) [\S\s]*/, "$1 ...");
text_markup = match_markup_span + text_match + "</span>";
text_markup = match_span + text_prefix + text_markup + text_suffix + "</span>";
//console.log('text markup: ' + text_markup);
Expand Down

0 comments on commit 061b84f

Please sign in to comment.