1 / 16

Using JavaScript in Linked Data Applications

Using JavaScript in Linked Data Applications. Oshani Seneviratne Oct 12, 2010. Why HTML and Javascript ?. It would: Make the application available widely, almost universally Allow the application to be delivered over HTTP

hallam
Télécharger la présentation

Using JavaScript in Linked Data Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using JavaScript in Linked Data Applications Oshani Seneviratne Oct 12, 2010

  2. Why HTML and Javascript? • It would: • Make the application available widely, almost universally • Allow the application to be delivered over HTTP • Run in the browser thus making use of the existing client side cache • Provide all the UI elements we need very easily

  3. Javascript Libraries • Rdflib + Widget Library • Written by Tabulator developers • Can be used to create user interfaces that use Semantic Web Data • Download from:http://dig.csail.mit.edu/2010/rdf-widgets/download.html • RDFQuery • Written by JeniTennison et al • Can be used to parse RDFa, query over facts and reason to produce more facts • Depends on jQuery • Download from:http://code.google.com/p/rdfquery • More Javascript libraries are available at: http://esw.w3.org/SemanticWebTools#JavaScript_Developers

  4. Same Origin Policy • Rule enforced in browsers for security • Javascript code running on a webpage cannot access any resources from other domains

  5. But there are some workarounds • You can: • Run your code in a trusted environment (standalone app, iPhone app, browser, browser extension, greasemonkey script) • Use a “proxy” server • Use browsers that support CORS (Firefox 3.5, Safari 4). However, the servers have to accept the headers sent by the browsers. • Use JSONP (JSON with Padding)

  6. Our Solution • Use a proxy server to provide JSONP translation of data available at any location on the Web. • TalisMetamorph web service (http://convert.test.talis.com) allows for converting between different RDF syntaxes • JSONP output format is available from the Metamorph service • Cross domain transfer of JSON is supported natively in libraries like jQuery

  7. Our Task • Look up a FOAF URI • Extract that person’s friends • Look at the friends’ FOAF files • See where they work • Use the workplace URI to query dbpedia for it’s location • Print a list of Tim’s friends, their workplaces and where the workplaces are located

  8. 1 Look up Tim’s FOAF URI varurl = 'http://convert.test.talis.com/?data-uri[]=http://www.w3.org/People/Berners-Lee/card#i&input=&output=jsonp&callback=?'; $.getJSON(url, function(data){ //Do something with the data });

  9. 2 Extract his friends vartim = "http://www.w3.org/People/Berners-Lee/card#i" var FOAF_KNOWS = “http://xmlns.com/foaf/0.1/knows” $.each(data[tim][”FOAF_KNOWS"], function{ //Process the friend data here. });

  10. 3 Look at the friends’ FOAF files • Same as 1. Use the metamorph service to load all the data of Tim’s friends. varurl = 'http://convert.test.talis.com/?data-uri[]=<friend_uri>&input=&output=jsonp&callback=?'; $.getJSON(url, function(data){ //Do something with the data });

  11. 4 See where the friends work var WOKPLACE_HOMEPAGE = "http://xmlns.com/foaf/0.1/workplaceHomepage"; friend.workplaceHomepage= friend_data[friend.id][WOKPLACE_HOMEPAGE][0].value;

  12. 5 Query DBpedia PREFIX prop: <http://dbpedia.org/property/> PREFIX ont: <http://dbpedia.org/ontology/> PREFIX foaf: <http://xmlns/foaf/0.1/> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT DISTINCT ?label ?lat ?long WHERE { { {?resource prop:website <website_url> .} UNION{?resource foaf:homepage <website_url>.} } { {?resource ont:location ?location. OPTIONAL { ?location geo:lat ?lat. ?location geo:long ?long.} OPTIONAL {?location rdfs:label ?label.} } UNION {?subject prop:employer ?resource} UNION {?subject prop:institution ?resource} UNION {?subject prop:workInstitution ?resource} UNION {?subject prop:workInstitutions ?resource} UNION {?subject prop:workplaces ?resource} UNION {?subject ont:occupation ?resource} OPTIONAL { ?resource geo:lat ?lat. ?resource geo:long ?long.} OPTIONAL {?resource rdfs:label ?label.}} FILTER langMatches( lang(?label), 'en')}

  13. 5.1 Sending the Query to dbpedia "http://dbpedia.org/sparql? default-graph-uri=http://dbpedia.org& should-sponge=soft& query=*query_goes_in_here*& format=application/json& callback=?"

  14. Demo • Available at: • http://dig.csail.mit.edu/2010/Courses/6.898/SWLibraries/javascript/demo/

  15. Tools that are helpful in debugging • Firebug • https://addons.mozilla.org/en-US/firefox/addon/1843 • JSON formatter • http://jsonformatter.curiousconcept.com/

  16. Quiz • Tim has alternate URIs specified in his FOAF file at http://www.w3.org/People/Berners-Lee/card#i. How can you modify this code to look up the workplaces of friends specified in those FOAF uris as well? • How do you find whether people in Tim’s FOAF file are in the same group (foaf:group) as Tim?

More Related