myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3736] branches/packs/app: added the ability to b


From: noreply
Subject: [myexperiment-hackers] [3736] branches/packs/app: added the ability to browse specific resources within an item
Date: Tue, 1 Oct 2013 09:58:02 +0000 (UTC)

Revision
3736
Author
dgc
Date
2013-10-01 09:58:01 +0000 (Tue, 01 Oct 2013)

Log Message

added the ability to browse specific resources within an item

Modified Paths

Added Paths

Diff

Modified: branches/packs/app/controllers/items_controller.rb (3735 => 3736)


--- branches/packs/app/controllers/items_controller.rb	2013-09-30 15:58:47 UTC (rev 3735)
+++ branches/packs/app/controllers/items_controller.rb	2013-10-01 09:58:01 UTC (rev 3736)
@@ -36,6 +36,18 @@
 
     @statements = merge_graphs(@annotations.map { |annotation| annotation[:graph] })
 
+    # Show a custom view if a view parameter is given
+
+    if params[:view]
+      @view_type = @statements.query([RDF::URI(params[:view]), RDF.type, nil]).first_object
+
+      @resource_uri = polymorphic_path(address@hidden, :items]) + "/" + @item.ore_path
+      @view_uri = RDF::URI(params[:view])
+
+      render :workflow_run
+      return
+    end
+
     unless @item.is_folder
       @title = @statements.query(address@hidden, RDF::DC.title, nil]).first_value || @item.folder_entry.entry_name
       @description = @statements.query(address@hidden, RDF::DC.description, nil]).first_value

Modified: branches/packs/app/helpers/research_objects_helper.rb (3735 => 3736)


--- branches/packs/app/helpers/research_objects_helper.rb	2013-09-30 15:58:47 UTC (rev 3735)
+++ branches/packs/app/helpers/research_objects_helper.rb	2013-10-01 09:58:01 UTC (rev 3736)
@@ -9,21 +9,42 @@
 module ResearchObjectsHelper
 
   NAMESPACES = {
-      "http://purl.org/dc/terms/"              => "dct",
-      "http://www.openarchives.org/ore/terms/" => "ore",
-      "http://purl.org/ao/"                    => "ao",
-      "http://purl.org/wf4ever/ro#"            => "ro",
-      "http://www.w3.org/ns/prov#"             => "prov",
-      "http://xmlns.com/foaf/0.1/"             => "foaf",
-      "http://www.w3.org/ns/oa#"               => "oa",
-      "http://purl.org/pav/"                   => "pav",
-      "http://purl.org/wf4ever/bundle#"        => "bundle",
-      "http://purl.org/dc/elements/1.1/"       => "dce",
-      "http://purl.org/wf4ever/roterms#"       => "roterms"
+      "http://www.w3.org/1999/02/22-rdf-syntax-ns#" => "rdf",
+      "http://www.w3.org/2000/01/rdf-schema#"       => "rdfs",
+      "http://purl.org/dc/terms/"                   => "dct",
+      "http://www.openarchives.org/ore/terms/"      => "ore",
+      "http://purl.org/ao/"                         => "ao",
+      "http://purl.org/wf4ever/ro#"                 => "ro",
+      "http://www.w3.org/ns/prov#"                  => "prov",
+      "http://xmlns.com/foaf/0.1/"                  => "foaf",
+      "http://www.w3.org/ns/oa#"                    => "oa",
+      "http://purl.org/pav/"                        => "pav",
+      "http://purl.org/wf4ever/bundle#"             => "bundle",
+      "http://purl.org/dc/elements/1.1/"            => "dce",
+      "http://purl.org/wf4ever/roterms#"            => "roterms",
+      "http://purl.org/wf4ever/wfprov#"             => "wfprov",
+      "http://purl.org/wf4ever/wfdesc#"             => "wfdesc",
+      "http://purl.org/wf4ever/wf4ever#"            => "wf4ever",
+      "http://ns.taverna.org.uk/2012/tavernaprov/"  => "tavernaprov",
+      "http://www.w3.org/2011/content#"             => "content",
+      "http://www.w3.org/2002/07/owl#"              => "owl"
+
   }
 
   private
 
+  def shorten_uri(uri)
+    uri = uri.to_s
+
+    NAMESPACES.each do |namespace, prefix|
+      if uri.starts_with?(namespace)
+        return "#{prefix}:#{uri[namespace.length..-1]}"
+      end
+    end
+
+    uri
+  end
+
   def pretty_rdf_xml(text)
 
     descriptions = { }
@@ -227,7 +248,7 @@
 
   RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
 
-  def render_rdf_xml(graph)
+  def render_rdf_xml(graph, opts = {})
 
     document = LibXML::XML::Document.new
 
@@ -241,7 +262,7 @@
       if subject.anonymous?
         description["rdf:nodeID"] = subject.id
       else
-        description["rdf:about"] = subject.to_s
+        description["rdf:about"] = relative_uri(subject.to_s, opts[:base_uri])
       end
 
       # Split the predicate URI into a namespace and a term.
@@ -270,7 +291,7 @@
         if object.anonymous?
           statement['rdf:nodeID'] = object.id
         else
-          statement['rdf:resource'] = object.to_s
+          statement['rdf:resource'] = relative_uri(object.to_s, opts[:base_uri])
         end
 
       end
@@ -282,11 +303,11 @@
     document.to_s
   end
 
-  def render_rdf(graph, format = :rdfxml)
-    if format == :rdfxml
-      render_rdf_xml(graph)
+  def render_rdf(graph, opts = {})
+    if opts[:format] == :rdfxml || opts[:format].nil?
+      render_rdf_xml(graph, opts)
     else
-      RDF::Writer.for(format).buffer { |writer| writer << graph }
+      RDF::Writer.for(opts[:format]).buffer { |writer| writer << graph }
     end
   end
 

Added: branches/packs/app/views/items/workflow_run.html.erb (0 => 3736)


--- branches/packs/app/views/items/workflow_run.html.erb	                        (rev 0)
+++ branches/packs/app/views/items/workflow_run.html.erb	2013-10-01 09:58:01 UTC (rev 3736)
@@ -0,0 +1,135 @@
+<h1>Workflow Run</h1>
+
+<% workflow_run = @view_uri %>
+
+<p>View URI: <%=h @view_uri.to_s -%></p>
+<p>View type: <%=h @view_type.to_s -%></p>
+
+<% label = @statements.query([workflow_run, RDF::RDFS.label, nil]).first_literal %>
+<% start_time = @statements.query([workflow_run, RDF::URI("http://www.w3.org/ns/prov#startedAtTime"), nil]).first_object %>
+<% end_time   = @statements.query([workflow_run, RDF::URI("http://www.w3.org/ns/prov#endedAtTime"), nil]).first_object %>
+
+<h3><%=h label -%></h3>
+
+<ul>
+  <% if start_time %>
+    <li>Started at <%= datetime(DateTime.parse(start_time.to_s)) -%>.</li>
+  <% end %>
+  <% if end_time %>
+    <li>Ended at <%= datetime(DateTime.parse(end_time.to_s)) -%>.</li>
+  <% end %>
+  <% if start_time && end_time %>
+    <li>Time elapsed: <%= sprintf("%.2f", (DateTime.parse(end_time.to_s).to_time - DateTime.parse(start_time.to_s).to_time).to_f * 100000) -%> seconds.</li>
+  <% end %>
+</ul>
+
+<% inputs = @statements.query([workflow_run, RDF::URI("http://purl.org/wf4ever/wfprov#usedInput"), nil]).objects %>
+
+<% if inputs.count > 0 %>
+  <h3>Inputs</h3>
+  <table class="simple">
+    <tr>
+      <th>Label</th>
+      <th>Zip entry</th>
+    </tr>
+  <% inputs.each do |input| %>
+    <% local_path = @statements.query([input, RDF::URI("http://ns.taverna.org.uk/2012/tavernaprov/content"), nil]).first_object %>
+    <% sha1 = @statements.query([local_path, RDF::URI("http://ns.taverna.org.uk/2012/tavernaprov/sha1"), nil]).first_literal %>
+    <% b1 = @statements.query([nil, RDF::URI("http://www.w3.org/ns/prov#entity"), input]).first_subject %>
+    <% role = @statements.query([b1, RDF::URI("http://www.w3.org/ns/prov#hadRole"), nil]).first_object %>
+    <% label = @statements.query([role, RDF::RDFS.label, nil]).first_literal %>
+      <tr>
+        <td><%=h label -%></td>
+        <td><%=h local_path -%></td>
+      </tr>
+  <% end %>
+  </table>
+<% end %>
+
+<% outputs = @statements.query([nil, RDF::URI("http://purl.org/wf4ever/wfprov#wasOutputFrom"), workflow_run]).subjects %>
+
+<% if outputs.count > 0 %>
+  <h3>Outputs</h3>
+  <table class="simple">
+    <tr>
+      <th>Label</th>
+      <th>Size</th>
+    </tr>
+    <% outputs.each do |output| %>
+      <% zip_entry = @statements.query([output, RDF::URI("http://ns.taverna.org.uk/2012/tavernaprov/content"), nil]).first_object %>
+      <% param = @statements.query([output, RDF::URI("http://purl.org/wf4ever/wfprov#describedByParameter"), nil]).first_object %>
+      <% label = @statements.query([param, RDF::RDFS.label, nil]).first_literal %>
+      <% sha1 = @statements.query([zip_entry, RDF::URI("http://ns.taverna.org.uk/2012/tavernaprov/sha1"), nil]).first_literal %>
+      <% size = @statements.query([zip_entry, RDF::URI("http://ns.taverna.org.uk/2012/tavernaprov/byteCount"), nil]).first_literal %>
+      <tr>
+        <td><%=h label -%></td>
+        <td><%=h size -%></td>
+      </tr>
+    <% end %>
+  </table>
+<% end %>
+    
+<% if Rails.env == "development" %>
+
+<h2>Debug</h2>
+
+  <div id="tabsContainer" class="tabsContainer"></div>
+
+  <div class="tabContainer">
+    <div class="tabTitle">Resource as subject</div>
+    <div class="tabContent">
+      <table class="simple" style="font-size: 80%">
+        <% @statements.query(address@hidden, nil, nil]).each do |s, p, o| %>
+          <tr>
+            <td><%=h shorten_uri(p.to_s) -%></td>
+            <td>
+              <% if o.resource? %>
+                <%= link_to(o.to_s, url_with_params(@resource_uri, :view => o.to_s)) -%></td>
+              <% else %>
+                <%=h o.to_s -%></td>
+              <% end %>
+            </td>
+          </tr>
+        <% end %>
+      </table>
+    </div>
+  </div>
+
+  <div class="tabContainer">
+    <div class="tabTitle">Resource as object</div>
+    <div class="tabContent">
+      <table class="simple" style="font-size: 80%">
+        <% @statements.query([nil, nil, @view_uri]).each do |s, p, o| %>
+          <tr>
+            <td>
+              <% if s.resource? %>
+                <%= link_to(s.to_s, url_with_params(@resource_uri, :view => s.to_s)) -%></td>
+              <% else %>
+                <%=h s.to_s -%></td>
+              <% end %>
+            <td><%=h shorten_uri(p.to_s) -%></td>
+          </tr>
+        <% end %>
+      </table>
+    </div>
+  </div>
+
+  <div class="tabContainer">
+    <div class="tabTitle">Possible views</div>
+    <div class="tabContent">
+      <table class="simple" style="font-size: 80%">
+        <tr>
+          <th>URI</th>
+          <th>RDF type</th>
+        </tr>
+        <% @statements.query([nil, RDF.type, nil]).each do |s, p, o| %>
+          <tr>
+            <td><%= link_to(s.to_s, url_with_params(@resource_uri, :view => s.to_s)) -%></td>
+            <td><%=h shorten_uri(o.to_s) -%></td>
+          </tr>
+        <% end %>
+      </table>
+    </div>
+  </div>
+
+<% end %>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]