Skip to content

Commit

Permalink
organize output for multiple providers
Browse files Browse the repository at this point in the history
  • Loading branch information
markwilkinson committed Dec 26, 2023
1 parent 623fc28 commit 7d92da7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
8 changes: 4 additions & 4 deletions VP/vp-interface/app/controllers/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ def set_routes(classes: allclasses)
get "/flair-gg-vp-server/force-refresh" do
warn "initializing refresh in routes"
VP.restart unless File.exist?("./cache/REFRESHING") # multiple browser calls are a problem!
@discoverables = VP.current_vp.get_resources.sort_by { |_k, v| v[:type] }.to_h # "./lib/metadata_functions"
@discoverables = VP.current_vp.get_resources # "./lib/metadata_functions"
erb :discovered_layout
end

get "/flair-gg-vp-server/resources" do
@discoverables = VP.current_vp.get_resources.sort_by { |_k, v| v[:type] }.to_h # "./lib/metadata_functions"
@discoverables = VP.current_vp.get_resources # "./lib/metadata_functions"
erb :discovered_layout
end

get "/flair-gg-vp-server/keyword-search" do
keyword = params["keyword"]
@discoverables = VP.current_vp.keyword_search_shell(keyword: keyword).sort_by { |_k, v| v[:type] }.to_h # "./lib/fdp"
@discoverables = VP.current_vp.keyword_search_shell(keyword: keyword) # "./lib/fdp"
erb :discovered_layout
end

get "/flair-gg-vp-server/ontology-search" do
term = params["uri"]
term = term.gsub(/\S+\:/, "") unless term =~ /^http/
@discoverables = VP.current_vp.ontology_search_shell(term: term).sort_by { |_k, v| v[:type] }.to_h # "./lib/fdp"
@discoverables = VP.current_vp.ontology_search_shell(term: term) # "./lib/fdp"
erb :discovered_layout
end

Expand Down
32 changes: 23 additions & 9 deletions VP/vp-interface/app/views/discovered_layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,30 @@
<h2>Virtual Platform Resources</h2>


<ol>
<% @discoverables.each_key do |url| %>
<% type = @discoverables[url][:type] %>
<% type = type.match(/[\#\/](\w+?)$/)[1].downcase %>
<% title = @discoverables[url][:title] %>
<li><img src="/images/<%= @discoverables[url][:icon] %>" width=35 height=35/> &nbsp;&nbsp;
Resource: <a href="<%= url %>" _target="_blank"> <%= title %> </a>(<%= type.capitalize %>)
</li>
<% @discoverables.each_key do |site| %>
<table>
<tr>
<td colspan=2>
<h3>SOURCE: <a href="http://<%= site %>" _target="_blank"><%= site %></a></h3>
</td>
</tr>
<% @discoverables[site].each do |resourcehash| %>
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<% resource = resourcehash[:resource] %>
<% type = resourcehash[:type] %>
<% type = type.match(/[\#\/](\w+?)$/)[1].downcase %>
<% title = resourcehash[:title] %>
<img src="/images/<%= resourcehash[:icon] %>" width=35 height=35/> &nbsp;&nbsp;
Resource: <a href="<%= resource %>" _target="_blank"> <%= title %> </a>(<%= type.capitalize %>)

</td>
</tr>
<% end %>
</table>
<br/><br/>
<% end %>
</ol>


<footer class="branding">
Expand Down
Binary file not shown.
58 changes: 38 additions & 20 deletions VP/vp-interface/lib/vp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ def find_discoverables

vpd = SPARQL.parse("
#{NAMESPACES}
SELECT ?s ?t ?title WHERE
{
VALUES ?connection { #{VPCONNECTION} }
VALUES ?discoverable { #{VPDISCOVERABLE} }
?s ?connection ?discoverable ;
dc:title ?title ;
a ?t .}")
#{NAMESPACES}
SELECT DISTINCT ?s ?t ?title ?contact WHERE
{
VALUES ?connection { #{VPCONNECTION} }
VALUES ?discoverable { #{VPDISCOVERABLE} }
?s ?connection ?discoverable ;
dc:title ?title ;
a ?t .
OPTIONAL{?s dcat:contactPoint ?c .
?c <http://www.w3.org/2006/vcard/ns#url> ?contact }.
}
")
discoverables = build_from_results(results: @graph.query(vpd))
warn discoverables
discoverables
Expand All @@ -103,19 +108,19 @@ def keyword_search(keyword: "")
vpd = SPARQL.parse("
#{NAMESPACES}
SELECT DISTINCT ?s ?t ?title WHERE
SELECT DISTINCT ?s ?t ?title ?contact WHERE
{
VALUES ?connection { #{VPCONNECTION} }
VALUES ?discoverable { #{VPDISCOVERABLE} }
?s ?connection ?discoverable ;
dc:title ?title ;
a ?t .
OPTIONAL{?s dcat:contactPoint ?c .
?c <http://www.w3.org/2006/vcard/ns#url> ?contact } .
{
# SELECT distinct ?s WHERE {
VALUES ?searchfields { dc:title dc:description dc:keyword }
?s ?searchfields ?kw
FILTER(CONTAINS(lcase(?kw), '#{keyword}'))
# }
}
}"
)
Expand All @@ -135,19 +140,19 @@ def ontology_search(uri: "")
#{NAMESPACES}
SELECT ?s ?t ?title WHERE
SELECT DISTINCT ?s ?t ?title ?contact WHERE
{
VALUES ?connection { #{VPCONNECTION} }
VALUES ?discoverable { #{VPDISCOVERABLE} }
?s ?connection ?discoverable ;
dc:title ?title ;
a ?t .
OPTIONAL{?s dcat:contactPoint ?c .
?c <http://www.w3.org/2006/vcard/ns#url> ?contact } .
{
# SELECT DISTINCT ?s WHERE {
?s dcat:theme ?theme .
FILTER(CONTAINS(str(?theme), '#{uri}'))
# }
}
}"
)
Expand All @@ -166,7 +171,7 @@ def verbose_annotations
words = []
vpd = SPARQL.parse("
#{NAMESPACES}
SELECT ?annot WHERE
SELECT DISTINCT ?annot WHERE
{ VALUES ?annotation { dcat:theme dcat:themeTaxonomy }
?s ?annotation ?annot .
}")
Expand All @@ -183,7 +188,7 @@ def verbose_annotations
warn "\n\nSWITCH TO KEYWORDS\n\n"
vpd = SPARQL.parse("
#{NAMESPACES}
select ?kw WHERE
select DISTINCT ?kw WHERE
{ VALUES ?searchfields { dcat:keyword }
?s ?searchfields ?kw .
}")
Expand Down Expand Up @@ -214,14 +219,27 @@ def match_type_to_icon(type:)

def build_from_results(results:)
discoverables = {}
warn "results are #{results}"
counter = 1
results.each do |result|
warn "result is #{result.inspect}"

next if result[:t].to_s =~ /\#Resource/

icon = match_type_to_icon(type: result[:t].to_s)
discoverables[result[:s].to_s] = { title: result[:title].to_s, type: result[:t].to_s, icon: icon }
contact = result[:contact].to_s
contact = "No Contact Provided (#{counter})" and counter += 1 unless contact
contact = contact.gsub(/\/\s*$/, "") # no diference between http://my.org/ and http://my.org
discoverables[contact] = [] unless discoverables[contact]
discoverables[contact] << { resource: result[:s].to_s, title: result[:title].to_s, type: result[:t].to_s, icon: icon }
end
discoverables
sort_discoverables(discoverables: discoverables)
end

def sort_discoverables(discoverables:)
discoverables.each_key do |provider| # discoverables["banco"] = [{resource: http, title: "hello", type: "dataset", icon: ico, contact: "banco"}, {resource: http ...}]
sorted = discoverables[provider].sort_by { |s| s[:type] }
discoverables[provider] = sorted
end
discoverables
end
end

0 comments on commit 7d92da7

Please sign in to comment.