1 //-------------------------------------------------------------------------------- 2 function name_in_gbif(namestring, element_id) { 3 4 $.getJSON('https://api.gbif.org/v1/species/match?name=' + encodeURIComponent(namestring) + '&kingdom=Animalia&verbose=true', 5 function(data){ 6 if (data.usageKey) { 7 var html = ''; 8 if (data.confidence > 90 && data.usageKey != 1) { 9 html = 'Taxonomic databases <a class="external gbif" href="https://gbif.org/species/' + data.usageKey + '" target="_new">' + data.usageKey + '</a>'; 10 11 gbif_types(data.usageKey, 'gbif_occurrences'); 12 13 gbif_to_wikidata(data.usageKey, 'match_taxon_external'); 14 15 } else { 16 html = 'No close match in GBIF'; 17 } 18 document.getElementById(element_id).innerHTML = html; 19 } 20 }); 21 } 22 23 //-------------------------------------------------------------------------------- 24 function gbif_to_wikidata(gbif, element_id) { 25 var sparql = `PREFIX wdt: <http://www.wikidata.org/prop/direct/> 26PREFIX wd: <http://www.wikidata.org/entity/> 27SELECT ?ncbi ?wiki ?species 28WHERE 29{ 30 # Wikidata 31 ?taxon wdt:P846 "GBIF" . 32 33 # NCBI 34 OPTIONAL { 35 ?taxon wdt:P685 ?ncbi . 36 } 37 38 # English language Wikipedia 39 OPTIONAL { 40 ?wikipedia_en schema:about ?taxon . 41 ?wikipedia_en schema:isPartOf <https://en.wikipedia.org/> . 42 BIND( REPLACE( STR(?wikipedia_en),"https://en.wikipedia.org/wiki/","" ) AS ?wiki). 43 } 44 45 # Wikispecies 46 OPTIONAL { 47 ?wikispecies schema:about ?taxon . 48 ?wikispecies schema:isPartOf <https://species.wikimedia.org/> . 49 BIND( REPLACE( STR(?wikispecies),"https://species.wikimedia.org/wiki/","" ) AS ?species). 50 } 51 52}`; 53 54 sparql = sparql.replace(/GBIF/, gbif); 55 56 console.log(sparql); 57 58 $.getJSON('https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=' + encodeURIComponent(sparql), 59 function(data){ 60 if (data.results.bindings.length > 0) { 61 var html = ''; 62 63 if (data.results.bindings[0].ncbi) { 64 html += '<a class="external ncbi" href="https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=' + data.results.bindings[0].ncbi.value + '" target="_new">' + data.results.bindings[0].ncbi.value + '</a><br />'; 65 } 66 67 if (data.results.bindings[0].wiki) { 68 dbpedia_summary(data.results.bindings[0].wiki.value, 'match_dbpedia'); 69 } 70 71 72 } else { 73 html = ''; 74 } 75 76 document.getElementById(element_id).innerHTML = html; 77 }); 78 79 } 80 81 82 83 //-------------------------------------------------------------------------------- 84 function dbpedia_summary(wikipedia, element_id) { 85 $.getJSON('dbpedia_proxy.php?query=' + encodeURIComponent('DESCRIBE <http://dbpedia.org/resource/' + wikipedia + '>'), 86 //$.getJSON('http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&query=DESCRIBE <http://dbpedia.org/resource/' + wikipedia + '>&format=application/json-ld', 87 function(data){ 88 if (data) { 89 var html = ''; 90 for (var i in data) { 91 if (data[i]['http://www.w3.org/2000/01/rdf-schema#comment']) { 92 for (var j in data[i]['http://www.w3.org/2000/01/rdf-schema#comment']) { 93 if (data[i]['http://www.w3.org/2000/01/rdf-schema#comment'][j].lang == 'en') { 94 html += '<div style="color: #999;font-size:0.8em;padding-top:10px;">' 95 + data[i]['http://www.w3.org/2000/01/rdf-schema#comment'][j].value 96 + ' ' 97 + '(from <a href="https://en.wikipedia.org/wiki/' + wikipedia + '" target="_new">Wikipedia</a>)' 98 + '</div>'; 99 } 100 } 101 } 102 } 103 document.getElementById(element_id).innerHTML = html; 104 } 105 } 106 ); 107 } 108 109 110 //-------------------------------------------------------------------------------- 111 function gbif_types(id, element_id) { 112 113 $.getJSON('https://api.gbif.org/v1/occurrence/search?taxonKey=' + id + '&typestatus=*', 114 function(data){ 115 if (data.results) { 116 117 if (data.results.length > 0) { 118 119 // GBIF will return occurrences for all taxa rooted on this node, so filter 120 var count = 0; 121 for (var i in data.results) { 122 if (data.results[i].speciesKey == id) { 123 count++; 124 } 125 } 126 if (count > 0) { 127 128 var html = '<h4>Type specimens in GBIF</h4>'; 129 130 html += '<ul>'; 131 132 for (var i in data.results) { 133 if (data.results[i].speciesKey == id) { 134 135 html += '<li>'; 136 137 html += '<a class="external gbif" href="https://gbif.org/occurrence/' + data.results[i].key + '" target="_new">' + data.results[i].key + '</a>'; 138 139 html += ' ' + data.results[i].typeStatus; 140 141 var terms = []; 142 143 if (data.results[i].year) { 144 terms.push(data.results[i].year); 145 } 146 147 if (data.results[i].recordedBy) { 148 terms.push('recorded by ' + data.results[i].recordedBy); 149 } 150 151 if (data.results[i].identifiedBy) { 152 terms.push('identified by ' + data.results[i].identifiedBy); 153 } 154 155 html += ' ' + terms.join(', '); 156 157 // images...? 158 if (data.results[i].media) { 159 for (var j in data.results[i].media) { 160 if (data.results[i].media[j].type == "StillImage") { 161 html += '<div>' 162 + '<img src="' 163 + 'http://exeg5le.cloudimg.io/crop/100x100/n/' 164 + data.results[i].media[j].identifier 165 + '" />' 166 + '</div>'; 167 } 168 } 169 } 170 171 html += '</li>'; 172 } 173 174 175 } 176 html += '</ul>'; 177 document.getElementById(element_id).innerHTML = html; 178 } 179 } 180 } 181 }); 182 183 184 185 186 187 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.