WD Litteraturbanken

Fills a select box with values from the query service

by Magnus Sälgö

HTML

<script src="https://cdn.rawgit.com/wikimedia/wikidata-query-gui/master/wikibase/queryService/api/Sparql.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.5.2/animate.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<h2>Integration with Wikipedia:<br />
Prototype to test textsearching Wikipedia articles using "Litteraturbanken/The Swedish Literature Bank" <a href="https://www.wikidata.org/wiki/Property_talk:P5101" target=_blank>P5101</a>
</h2>
<div id="explain">
What knows Swedish Wikipedia about authors The Swedish Literature Bank? <br />
Below all authors found in The Swedish Literature Bank in Sweden connected to Wikidata are presented in the listbox. When selecting one a Wikipedia search is done and the result is displayed as "snippets" ==> the search engine explains why this Wikipedia article is of interest... if you have questions dont hesitate to contact Magnus Sälgö +46-70-5937579</div>  <br />See also<br /><br />
<table border=0 width=600px><tr><td><ll class="list">
  <li><a href="https://sv.wikipedia.org/wiki/Anv%C3%A4ndare:Salgo60/Listeria/LItteraturbanken">Wikipedia Litteraturbanken Listeria list</a></li>
  <li><a href="https://www.mediawiki.org/wiki/API:Search">API:Search</a></li>
  <li><a href="https://www.mediawiki.org/wiki/Page_Previews">Page Previews</a></li>
  <li><a href="https://minancestry.blogspot.com/2018/09/page-preview-wikipedia.html">Blogpost about show Wiki content</a></li><li><a href="http://minancestry.blogspot.com/2018/04/wikidata-egenskap-for-litteraturbanken.html" target=_blank>Blogpost</a> about SBL in Wikidata</li>
</ll>
</ll></td><td valign="top"><ll><li><a target=_blank href="https://jsfiddle.net/salgo60/wkrug0bL/embedded/result/">Same but for SKBL</a></li><li><a href="https://tools.wmflabs.org/mix-n-match/#/catalog/1223" target=_blank">Matching page SLB <-> Wikidata</a></li><li><a href="http://tinyurl.com/y9bpna3q" target=_blank>SPARQL search</a>...

CSS

body {
   color: #444;
   background: #e2ffff;
   /* fallback for old browsers */
   background: -webkit-linear-gradient(to left, #9ab800, #e2ffff);
   /* Chrome 10-25, Safari 5.1-6 */
   background: linear-gradient(to left, #9ab800, #e2ffff);
   /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
   font-family: 'Dosis', sans-serif;
   background-repeat: no-repeat;
   background-size: cover;
   min-height: 100vh;
   font-size: 16px;
 }

 a {
   color: #444;
   cursor: pointer;
 }

 a:hover {
   color: #555;
   text-decoration: none;
 }
#URL {
   margin-top: 20px;
   padding: 0 5%;
   color: darkblue;
}

#Hits {
   margin-top: 20px;
   padding: 0 5%;
   color: #437746;
   font-size: 30px;
}

.more {
   color: darkgreen;
} 
#output {
   margin-top: 40px;
   padding: 0 5%;
 }

 
.list a {
  text-decoration: none;
}
 
li a:hover {
  background: lightgreen;
}

h2 a:hover {
  background: lightgreen;
}


 #text {
   padding: 10px 20px;
   border-top-left-radius: 30px;
   border-bottom-left-radius: 30px;
   border: 0px solid;
   width: 50%;
 }

 #text:focus {
   box-shadow: 1px 3px 40px 5px #536970;
   outline: none;
 }
 #not-found p {
   font-size: 20px;
  }

.result {
  padding: 0.5% 2%;
  background: #fff;
  margin: 1.5%;
  border-left: 7px solid #536976;
}

.result h2 {
  color: #536976;
}
  

 button {
   background: #536976;
   color: #fff;
   padding: 10px 20px;
   border: 1px solid #536976;
   border-radius: 30px;
   margin-left: -55px;
 }


 .currParish {
    background-color: aliceblue;
    margin: 8px;
    size: 12px;
    border-radius: 25px;
    border: 2px solid darkBlue;
    padding: 20px; 
    width: 500px;
    height:150px;    
 }

.searchmatch{
      color: #a0ccd2;
}
#explain
{
     color: darkgreen;
     font-family: "Times New Roman", Times, serif;     
}

JavaScript

$(function() {
	new WOW().init();


	var query = 'SELECT ?itemLabel WHERE { ?item wdt:P5101 ?LittBankid. SERVICE wikibase:label { bd:serviceParam wikibase:language "sv","en" }  } ORDER BY ?itemLabel' // Finds Authors

	var api = new wikibase.queryService.api.Sparql();
	api.query(query).done(function() {
 					var nrHits = api.getResultRawData().results.bindings.length;
		$("#Hits").html("Swedish Literature Bank Authors retrieved from Wikidata to the listbox = " + nrHits + " <div data-wow-duration='6s' data-wow-offset='10' class='wow bounceInUp more'>select an Author</div>");   $.each(api.getResultRawData().results.bindings, function(key, value) {
  		$('.parishList').append($('<option/>').text(value.itemLabel.value));
  	});
	});
});

	$( '.searchOptionList' ).change(function() {       
    var srcopt = '&srqiprofile=' + $('.searchOptionList').val();
    $("#URL").html(srcopt);

  });
	$( '.parishList' ).change(function() {       
    var input = $('.parishList').val();
    var srcopt = '&srqiprofile=classic';
    
//		srcopt = '&srqiprofile=' + $('.searchOptionList').val();
//    $("#URL").html(srcopt);
		var searchLimit = 400 // number of results in search 
    var url = `https://sv.wikipedia.org/w/api.php?action=query&list=search&srsearch=` + input + `&srlimit=` + searchLimit + `&format=json&prop=info&inprop=url` + srcopt;

    $.ajax({
      type: "GET",
      url: url,
      dataType: "jsonp",
      success: function(data) {
        let info = data.query.search;
        console.log(info);

        if (info.length === 0) {
          let notFound = "";
          notFound += `
            <div id="not-found" class="wow fadeIn text-center" data-wow-duration="0.5s">
              <p> No result for parameter </p>
            </div>
          `
          $("#output").html(notFound);
          $("#not-found").delay(5000).fadeOut(500);
        } else {
          let output = "";
          let numberofHits = "Number of hits in Swedish Wikipedia " + info.length + "...