130 likes | 308 Views
SPARQL 101: Query fundamentals, sample queries, Query builder, and simple reports. Nicholas Rejack – nrejack@ufl.edu VIVO Implementation Fest – Boulder, CO Wednesday, May 16, 2012 – 1:30 – 2:30 PM . Goal of this presentation: Provide you with a basic introduction to querying
E N D
SPARQL 101: Query fundamentals, sample queries, Query builder, and simple reports Nicholas Rejack – nrejack@ufl.edu VIVO Implementation Fest – Boulder, CO Wednesday, May 16, 2012 – 1:30 – 2:30 PM
Goal of this presentation: Provide you with a basic introduction to querying Provide you with some building blocks to piece together new queries
SPARQL basics • SPARQL = SPARQL Protocol And RDF Query Language • Similiarity to SQL querying: • SELECT • FROM • WHERE • ORDER BY etc. clauses the same • Differences: We’re binding triples, not columns • We need to use either prefixed (namespace) elements or URIs • What will not be covered in these sessions: • Updates
Basic variable binding in all 3 locations • 1) Binding variable in subject position: • “show me all the info about this” • URI example (1) (use case: find all triples about a particular URI) • Prefixed example (2) (use case: show all the information about a particular ontology element) • 2) Binding variable in predicate position: • “show me all the uses of this predicate” • Prefixed example (3) (use cases: show me all the uses of this predicate) • Labeled example (4) & (5) (add selected variables)
Basic variable binding in all 3 locations • 3) Binding variable in object position • “show me all the reverse links back to the subject” • URI example (6)
Restricting results: LIMIT • Results list may be too long, or take too long to return • Restrict amount you return with LIMIT keyword • Example (7)
COUNT keyword • Use COUNT to get a sum (8) • Syntax: • SELECTcount(var) or SELECT (count(var) as ?var2) • Be careful what you are counting: • You may need to view the data before re-running the query to count it (9)
Displaying the graph • Use GRAPH keyword (10) • Syntax: • SELECT * WHERE • { • GRAPH ?g • { • Query • } • }
Simple reporting with CSV files • Use the CSV output option to generate simple reports
Binding multiple variables • Query builder example: building author lists
Resources for further learning • Contribute queries via SF wiki: • http://sourceforge.net/apps/mediawiki/vivo/index.php?title=SPARQL_Queries_for_Data_Maintenance
Questions? • Contact: Nicholas Rejack (nrejack@ufl.edu)