160 likes | 300 Views
Introduction to Protégé for Absolute Beginners. University at Buffalo August 11 & 12. SPARQL Protocol and RDF Query Language. SPARQL – SPARQL Protocol and RDF Query Language. A query language that is able to retrieve and manipulate data stored in RDF format.
E N D
Introduction to Protégé for Absolute Beginners University at Buffalo August 11 & 12
SPARQL – SPARQL Protocol and RDF Query Language • A query language that is able to retrieve and manipulate data stored in RDF format. • On 15 January 2008, SPARQL 1.0 became an official W3C Recommendation • A new version of SPARQL, 1.1 is under review ending on August 21, 2012
The Structure of a Basic SPARQL Query • The select clause lists the information you want to see. • For example: player, token • The where clause is a set of statements that pulls the information • For example: player represented by token
Key Terms for Use in Queries • rdfs:subClassOf will return the direct subclasses of another class • rdfs:subClassOf* will return the recursive subclasses of another class • rdf:type will return or set the class/kind of an instance • Prefixes: PREFIX mnply:<http://www.cubrc.org/ontologies/MonopolyOntology#> PREFIX game1:<http://www.cubrc.org/ontologies/MonopolyOntologies/Game1#>
Example Queries • Return all players SELECT ?player WHERE { ?player rdf:typemnply:MonopolyPlayer . } • Return all players and their game tokens SELECT ?player ?token WHERE { ?player mnply:represented_by ?token . }
Example Queries • The previous query made impervious to changes by adding types SELECT ?player ?token WHERE { ?player rdf:typemnply:MonopolyPlayer . ?token rdf:typemnply:MonopolyToken . ?player mnply:represented_by ?token . } • Return all the events a given player participates in SELECT ?event WHERE { ?event rdf:typemnply:MonopolyEvent . ?event mnply:has_participant game1:MonopolyPlayer_1. }
Example Queries • Return all the dice rolls along with whether or not they were doubles SELECT ?roll ?double WHERE { ?roll rdf:typemnply:MonopolyRollOfDice . ?double mnply:assessed_at ?roll . ?double rdf:typemnply:MonopolyDoubles} . } • The above returned just the doubles, to get all the rolls use the OPTIONAL keyword SELECT ?roll ?double WHERE { ?roll rdf:typemnply:MonopolyRollOfDice . OPTIONAL {?double mnply:assessed_at ?roll . ?double rdf:typemnply:MonopolyDoubles} . }
Example Queries • Return all the locations of a player in “temporal” order SELECT ?ordval ?round ?turn ?location WHERE { ?attribute mnply:attribute_of game1:MonopolyPlayer_1 . ?attribute mnply:located_at ?location . ?attribute mnply:assessed_at ?turn . ?turn mnply:occurs_during ?round . ?round mnply:has_ordinal_value ?ordval . } ORDER BY ?ordval
Example Queries • What were the locations of all players at the end of Round 11? SELECT ?player ?round ?turn ?location WHERE { ?player rdf:typemnply:MonopolyPlayer . ?attribute mnply:attribute_of ?player . ?attribute mnply:located_at ?location . ?attribute mnply:assessed_at ?turn . ?turn mnply:occurs_during ?round . ?round mnply:has_ordinal_value 11 . }
Example Queries • What were player 1’s locations at the end of Rounds 11 and 20? SELECT ?player ?round ?turn ?location WHERE { { ?attribute mnply:attribute_of game1:MonopolyPlayer_1 . ?attribute mnply:located_at ?location . ?attribute mnply:assessed_at ?turn . ?turn mnply:occurs_during ?round . ?round mnply:has_ordinal_value 11 . } UNION { ?attribute mnply:attribute_of game1:MonopolyPlayer_1 . ?attribute mnply:located_at ?location . ?attribute mnply:assessed_at ?turn . ?turn mnply:occurs_during ?round .?round mnply:has_ordinal_value 20} . } }
Example Queries • Return the number of each type of equipment used in the game SELECT ?equipmenttype (COUNT(?equipment) AS ?equipmentcount) WHERE { ?equipmenttyperdfs:subClassOfmnply:MonopolyEquipment . ?equipment rdf:type ?equipmenttype . ?attribute mnply:attribute_of ?player . ?attribute mnply:located_at game1:MonopolyBoardwalk_Instance_1 . } GROUP BY ?equipmenttype
Ontofox • OntoFox is a web-based system to support ontology reuse. It allows users to input terms, fetch selected properties, annotations, and certain classes of related terms from source ontologies and save the results using the RDF/XML serialization of the OWL. • http://ontofox.hegroup.org/
(One way of) Using Ontofox • Identify an ontology from which you wish to extract terms • (e.g. Environment Ontology http://purl.bioontology.org/ontology/ENVO ) • Get the full id of the lowest level terms • (e.g. http://purl.obolibrary.org/obo/ENVO_00002021 • http://purl.obolibrary.org/obo/ENVO_00002022, etc. • Get the full id of the highest level term • (http://purl.obolibrary.org/obo/ENVO_00002297) • Select a setting for retrieving intermediate terms • (e.g. IncludeAllIntermediates) • Input URI for annotations to be selected • (e.g. http://www.w3.org/2000/01/rdf-schema#label) • Enter a URI for the output file • (e.g. http://purl.obolibrary.org/obo/external/ENVO_extract.owl)