Changeset 35116


Ignore:
Timestamp:
2021-04-24T15:12:31+12:00 (3 years ago)
Author:
davidb
Message:

Adding in a 'pick a random song' feature with an underlying SPARQL query

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/transform/pages/about.xsl

    r35102 r35116  
    161161      </p>
    162162
     163      <xsl:variable name="graphURI">https://so-we-must-think.space<xsl:value-of select="$siteURL"/><xsl:value-of select="$library_name"/>/collection/<xsl:value-of select="$collName"/></xsl:variable>   
     164
     165      <!--
     166           Kudos to:
     167            https://byabbe.se/2020/09/17/getting-random-results-in-sparql
     168      -->
     169      <div id="select-random-entrant-sparqlquery" style="display: none;">
     170PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
     171PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
     172PREFIX gsdlextracted: &lt;http://greenstone.org/gsdlextracted#&gt;
     173
     174SELECT ?random ?esc_entrant_uri ?country ?year WHERE {
     175  GRAPH &lt;<xsl:value-of select="$graphURI"/>&gt;  {
     176    ?esc_entrant_uri gsdlextracted:Year ?year.
     177    ?esc_entrant_uri gsdlextracted:Country ?country.
     178    BIND(SHA512(CONCAT(STR(RAND()), STR(?esc_entrant_uri))) AS ?random).
     179  }
     180}
     181ORDER BY ?random
     182      </div>
     183      <div id="select-random-entrant-div" style="display: none;">
     184        Or how about picking a song ...
     185        <ul>
     186          <li><a id="select-random-entrant-a">... at random</a></li>
     187        </ul>
     188      </div>
     189      <gsf:script>
     190        $(document).ready(function() {
     191          var endpoint_url="//sowemustthink.space/greenstone3-lod3/greenstone/query";
     192          var sparql_query = $('#select-random-entrant-sparqlquery').text();
     193          $.ajax({
     194            type: "POST",
     195            url: endpoint_url,
     196            data: { query: sparql_query, output: "json" },
     197            success: function(json_data) {
     198          var rand_result = json_data.results.bindings[0];
     199          var esc_entrant_uri = rand_result.esc_entrant_uri.value;
     200          $('#select-random-entrant-a').attr("href",esc_entrant_uri);
     201          $('#select-random-entrant-div').show();
     202        },
     203            dataType: "json"
     204          });
     205        });
     206      </gsf:script>
    163207
    164208      <h2>Data Analysis and Visualization</h2>
     
    180224      </gsf:script>
    181225
    182       <xsl:variable name="graphURI">https://so-we-must-think.space<xsl:value-of select="$siteURL"/><xsl:value-of select="$library_name"/>/collection/<xsl:value-of select="$collName"/></xsl:variable>   
    183226      <div id="sgvizler2-country-count"
    184227           data-sgvizler-endpoint="//sowemustthink.space/greenstone3-lod3/greenstone/query"
     
    528571
    529572        <p>
    530               Despite our best intentions work soley with
     573              Despite our best intentions work solely with
    531574              machine-readable data—primarily as you have seen in the
    532575              form of Linked Open Data, but also utilizing a
     
    570613          in a given year does, however, appear in the
    571614          article page for the contest in that year.  In fact
    572           it's in the same table we targetted to extract out
    573           draw position and placement.  We therefore
     615          it's in the same table we targeted to extract out
     616          the draw position and placement.  We therefore
    574617          wrote a further page-scraping program to compare
    575618          the countries in that table with the countries
Note: See TracChangeset for help on using the changeset viewer.