Thot APIs
Central to data sharing, (Application Programming interfaces (APIs) are entry points developed by projects to make accessible their data to external parties. As for Project Thot, APIs have been built in order to make Thot thesauri and concepts very accessible and easy to use. For instance, pointing to a specific URL will retrieve the full set of concepts of a thesaurus as sorted data, or will display preferred label or date ranges attached to a concept, as explained below:
Available services and how to access them
Service | Data type | URL structure after http://thot.philo.ulg.ac.be/ | Example |
---|---|---|---|
Get skos:Concept | RDF | api/rdf/concept/ + thot-concept | http://thot.philo.ulg.ac.be/api/rdf/concept/thot-23 |
Get skos:prefLabel | txt | api/txt/preflabel/ + thot-concept/ + lang | http://thot.philo.ulg.ac.be/api/txt/preflabel/thot-23/fr will return "Copte fayoumique" |
Get date range (date thesaurus only) | txt | api/txt/get-dateRange/ + thot-concept | http://thot.philo.ulg.ac.be/api/txt/get-dateRange/thot-465 will return "450-400 BC" |
Get start of date range | txt | api/txt/get-dateStart/ + thot-concept | http://thot.philo.ulg.ac.be/api/txt/get-dateStart/thot-465 will return "-450" |
Get end of date range | txt | api/txt/get-dateEnd/ + thot-concept | http://thot.philo.ulg.ac.be/api/txt/get-dateEnd/thot-465 will return "-400" |
Get a specific thesaurus in English | JSon | api/json/thesaurus/ + thesaurus name | http://thot.philo.ulg.ac.be/api/json/thesaurus/scripts |
Get a specific thesaurus in a specific | JSon | api/json/get-thesaurus/ + thesaurus name + "/" + ISO language code | http://thot.philo.ulg.ac.be/api/json/get-thesaurus/scripts/fr (see use case below) |
Available data types and languages
The current data type are as follows:
- JSon
- XML/RDF
- Plain text
Current languages are English (en), French (fr), German (de). To get the xml value attached to a concept (see here), use 'xml' as language name.
Retrieve and display data from Thot
Load data with Ajax and display it in your HTML page
Using ajax, you can retrieve values attached to a Thot concept and diplay them in your webpage. For instance, let's suppose you have a database of funeral texts from the New Kingdom. One of your record is dated to Amenhotep II reign. The only piece of information you have to store is that this record is related to thot-374, the concept that corresponds to that king. Using the API, you will be able to automatically display name (the German form in the example below), a date range and mumerical values corresponding to this range
- Reign:
- Date range:
- Earliest date:
- Lastest date:
HTML
<ul> <li>Reign: <span id="kingName" /> </li> <li>Date range: <span id="dateRange" /></li> <li>Earliest date: <span id="dateStart"/></li> <li>Lastest date: <span id="dateEnd"/></li> </ul>
JScript and Ajax function
<script type="text/javascript"> $(document).ready(function (){ $.ajax({ method: "GET", url:"http://thot.philo.ulg.ac.be/api/txt/get-dateRange/thot-374", dataType: "text", success:function(data) { $("#dateRange").text(data); } }); $.ajax({ method: "GET", url:"http://thot.philo.ulg.ac.be/api/txt/preflabel/thot-374/de", dataType: "text", success:function(data) { $("#kingName").text(data); } }); $.ajax({ method: "GET", url:"http://thot.philo.ulg.ac.be/api/txt/get-dateStart/thot-374", dataType: "text", success:function(data) { $("#dateStart").text(data); } }); $.ajax({ method: "GET", url:"http://thot.philo.ulg.ac.be/api/txt/get-dateEnd/thot-374", dataType: "text", success:function(data) { $("#dateEnd").text(data); } }); }); </script>
Thot thesauri in JSon
Thot thesauri are available as JSon data through the following requests (http://thot.philo.ulg.ac.be/api/json/ + thesaurus shortname):
- Languages: http://thot.philo.ulg.ac.be/api/json/languages
- Scripts: http://thot.philo.ulg.ac.be/api/json/thesaurus/scripts
Example of use of Thot thesauri in a form
Thot thesaurus can be displayed as a tree in a form, for instance by implementing Fancytree JQuery library (https://github.com/mar10/fancytree).
HTML form:
<form action="" method="POST"> <fieldset name="script"> <legend>Select a value</legend> <div id="tree" name="selNodes"/> </fieldset> <br/> <input type="submit" value="Simulate a submission"/> </form>
JScript:
<script type="text/javascript"> $(document).ready(function () { $("form").submit(function() { $("#tree").fancytree("getTree").generateFormElements(); alert("POST data:\n" + jQuery.param($(this).serializeArray())); return false; }); $("#tree").fancytree({ extensions: ["glyph", "wide"], minExpandLevel: 2, source: { url: "http://thot.philo.ulg.ac.be/api/json/get-thesaurus/scripts/fr" } }); }); </script>