PowerPoint PresentationSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53Slide 54Slide 55Slide 56Slide 57Slide 58Slide 59Slide 60Slide 61Slide 62Slide 63Slide 64Chapter 3 A Semantic Web Primer1SPARQLGrigoris AntoniouFrank van HarmelenChapter 3 A Semantic Web PrimerBrowsing info on the Semantic WebNavigating the Semantic Web via RDF browsers - OpenLink RDF Browser, Disco, and others - These browsers are very buggy, based on my experiences - Even if they worked well, it would be an unordered, Web-surfing-like method of discovering semantic infoChapter 3 A Semantic Web PrimerSearching the Semantic WebUse a Semantic Web Search Engine!These crawl the Web and Semantic Web looking for new ontologies (OWL, RDFS, etc.)Ontologies are indexed and made searchableOne can also search for specific properties and RDF triplesExamples: Swoogle, SWSE, Sindice, Watson and FalconsChapter 3 A Semantic Web PrimerQuerying for RDF on the Semantic WebNavigation and Searching for RDF on the Semantic Web is often not precise enough for a userUser often needs to query for specific RDF data over multiple triple stores, where subject, predicate or object of the triples of interest have a particular valueEnter SPARQL: SPARQL Protocol and RDF Query LanguageAbout SPARQLSPARQL is both an RDF query language and a protocolSPARQL defines the syntax of the query language, which is issued to retrieved triples from RDF storesSPARQL is also a protocol – it describes how a SPARQL client (like a Web browser) talks to a SPARQL processor (aka SPARQL endpoint)A SPARQL endpoint is a service that accepts a SPARQL query, processes it, and returns results depending on the query formChapter 3 A Semantic Web Primer6Why an RDF Query Language instead of an XML query language?XML at a lower level of abstraction than RDFThere are various ways of syntactically representing an RDF statement in XMLThus we would require several XPath queries, e.g.–//uni:lecturer/uni:title if uni:title element–//uni:lecturer/@uni:title if uni:title attribute–Both XML representations equivalent!SPARQL Basic QueriesSPARQL is based on matching graph patternsThe simplest graph pattern is the triple pattern :-like an RDF triple, but with the possibility of a variable instead of an RDF term in the subject, predicate, or object positionsVariables are called “bound variables”, and these are like the attribute names in SQL queriesResults returned are called “solutions”, and they are the bound variables associated with each triple that matched the queryChapter 3 A Semantic Web Primer8Using select-from-where As in SQL, SPARQL queries have a SELECT-FROM-WHERE structure:–SELECT specifies the projection: the subject, predicate and/or object of triples that are returned as results–FROM is used to specify the source being queried (optional)–WHERE imposes constraints on possible solutions in the form of graph pattern templates and boolean constraintsRetrieve all phone numbers of staff members:SELECT ?x ?yWHERE { ?x uni:phone ?y .}Here ?x and ?y are variables, and ?x uni:phone ?y represents a resource-property-value triple patternExamplesPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>SELECT ?cWHERE{?c rdf:type rdfs:Class .}Retrieves all triple patterns, where:-the property is rdf:type-the object is rdfs:ClassWhich means that it retrieves all classesExamples (2)Get all instances of a particular class (e.g. course) :(declaration of rdf, rdfs prefixes omitted for brevity)PREFIX uni: <http://www.mydomain.org/uni-ns#>SELECT ?iWHERE{?i rdf:type uni:course .}DBPedia SPARQL EndpointYou can practice SPARQL all you want at various public SPARQL endpoints!DBPedia’s SPARQL endpoint: http://dbpedia.org/sparqlEnter SPARQL queries using Turtle syntaxQuery for all locations named after George Washington-Note the @en language tag after “George Washington”-Notice that namespaces are NOT used in this query, so no PREFIX statements are necessaryRDF Graph Pattern of QueryQuery Results in HTML formatA couple of notesThe results of a SPARQL query are not necessarily ordered.A variable is bound to a URI, literal value or a blank nodeIf a query returns no solutions for a particular variable, then there are no bindings for that variableFoundational Query FormsSELECT queries – Like SQL select queries, SPARQL SELECT queries instruct endpoints to bind RDF terms to variables based on given graph patternCONSTRUCT queries – Allows one to create RDF graphs, as long as each triple specified is valid. One can transform RDF graphs from one form to anotherASK queries – Does a particular graph exist? Returns true or false resultChapter 3 A Semantic Web PrimerFoundational Query Forms (cont)DESCRIBE queries – Returns RDF graph determined solely by the query processor with limited query input from a client. The endpoint decides what precise RDF data is returned to the client. This query is useful when the client has only a vague familiarity with the data, and does not know exactly what RDF triples are presentSPARQL’s SELECT *To return all known variable bindings in a SPARQL query as output, use “SELECT *” as follows:Chapter 3 A Semantic Web Primer19Implicit Join Retrieve all lecturers and their phone numbers:SELECT ?x ?yWHERE{ ?x rdf:type uni:Lecturer ; uni:phone ?y . }Implicit join: We restrict the second pattern only to those triples, the resource of which is in the variable ?x– Here we use a syntax shorcut as well: a semicolon indicates that the following triple shares its subject with the previous oneImplicit join (2)The previous query is equivalent to writing:SELECT ?x ?yWHERE{?x rdf:type uni:Lecturer .?x uni:phone ?y .}Another Implicit Join Example# A punk rock examplePREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX dbprop: <http://dbpedia.org/property/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dbobject: <http://dbpedia.org/resource/> SELECT *WHERE {?person rdf:type ?class ; dbprop:alias ?label ;
View Full Document