SPARQL University Query Tasks
Overview
This skill provides guidance for writing SPARQL queries against RDF/Turtle datasets, with emphasis on ensuring complete data analysis, proper query construction, and thorough verification.
Workflow
Step 1: Complete Data Acquisition
Before writing any query, ensure complete visibility of the source data.
Critical actions:
- Read the entire Turtle (.ttl) or RDF file without truncation
- If data appears truncated, request additional content or use pagination
- Count distinct entities to verify data completeness
- Document all entity types, predicates, and relationships observed
Verification checkpoint: Confirm the number of distinct entities matches expectations before proceeding.
Step 2: Schema Understanding
Map out the data structure before query construction.
Key elements to identify:
- All entity types (classes) in the dataset
- All predicates/properties used
- Relationships between entities (e.g., professor → department → students)
- Data types for literals (strings, dates, integers)
- Naming conventions and value formats
Common patterns in academic data:
- Roles/titles often use specific prefixes (e.g., "Professor of", "Associate Professor")
- Dates may require comparison logic for "current" status
- Geographic codes may use ISO standards (country codes)
- Enrollment may span multiple departments
Step 3: Criteria Decomposition
Break down filtering requirements into discrete, testable conditions.
For each criterion:
- Identify the exact predicate path to the relevant data
- Determine the comparison type (equality, prefix match, membership, numeric)
- Consider edge cases in the criterion interpretation
- Test each criterion independently before combining
Example decomposition:
- "Full professors" → Filter where role starts with specific prefix
- "Working in EU countries" → Filter country codes against EU membership list
- "Departments with >10 students" → Count students per department, apply threshold
Step 4: Query Construction
Build the query incrementally with validation at each stage.
Construction sequence:
- Start with the most restrictive filter to reduce result set
- Add one filter at a time, verifying intermediate results
- Include all necessary SELECT variables
- Add aggregation (GROUP BY, GROUP_CONCAT) last
Syntax validation:
- Verify all prefixes are declared
- Ensure FILTER expressions are properly closed
- Check string comparisons use correct functions (STRSTARTS, CONTAINS, regex)
- Confirm numeric comparisons handle data types correctly
Output format considerations:
- Determine if results need aggregation (e.g., concatenating multiple values)
- Specify sort order and separators for concatenated values
- Distinguish between filtering criteria and output requirements (e.g., filter by EU countries but output ALL countries)
Step 5: Verification Strategy
Test the query against known expectations.
Verification methods:
- Run the query and examine raw output
- Manually trace through data for at least 2-3 entities to verify correctness
- Check for both inclusion (expected entities present) AND exclusion (unexpected entities absent)
- Verify aggregated values by manual count
Cross-reference checklist:
- Do the returned entities match manual analysis?
- Are all expected entities present in results?
- Are any unexpected entities incorrectly included?
- Do aggregated counts/values match manual verification?
Common Pitfalls
Incomplete Data Reading
- Problem: Working with truncated data leads to missing entities
- Prevention: Always confirm complete file content; re-read if truncated
Query Truncation
- Problem: Long queries may be incompletely written
- Prevention: After writing, read back the query file to verify completeness
Criterion Misinterpretation
- Problem: Confusing filter criteria with output requirements
- Prevention: Distinguish between "filter BY X" vs "output X" - these may differ
Date/Time Edge Cases
- Problem: Incorrect handling of boundary dates
- Prevention: Clarify whether comparisons are inclusive or exclusive; test boundaries
Aggregation Errors
- Problem: Missing GROUP BY clauses or incorrect GROUP_CONCAT usage
- Prevention: Verify aggregation syntax matches the query structure
EU Country List
- Problem: Incomplete or outdated list of EU member country codes
- Prevention: Use comprehensive list: AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT, LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE
Cross-Entity Relationships
- Problem: Miscounting entities across relationships (e.g., students in departments)
- Prevention: Trace the full predicate path; verify join conditions
Testing Protocol
- Syntax check: Ensure query parses without errors
- Subset test: Run on a known subset of data with expected results
- Full test: Run on complete dataset
- Manual verification: Trace 2-3 results through source data
- Boundary test: Check edge cases in filters (dates, counts, string matches)
Iteration Approach
If initial results do not match expectations:
- Isolate which filter condition is causing discrepancies
- Test each filter independently
- Examine entities that should appear but don't (false negatives)
- Examine entities that shouldn't appear but do (false positives)
- Adjust filter logic based on findings
- Re-verify after each adjustment
1---2name: sparql-university3description: Guidance for writing SPARQL queries against RDF/Turtle datasets, particularly for university or academic data. This skill should be used when tasks involve querying RDF data with SPARQL, filtering entities based on multiple criteria, aggregating results, or working with Turtle (.ttl) files.4---56# SPARQL University Query Tasks78## Overview910This skill provides guidance for writing SPARQL queries against RDF/Turtle datasets, with emphasis on ensuring complete data analysis, proper query construction, and thorough verification.1112## Workflow1314### Step 1: Complete Data Acquisition1516Before writing any query, ensure complete visibility of the source data.1718**Critical actions:**19- Read the entire Turtle (.ttl) or RDF file without truncation20- If data appears truncated, request additional content or use pagination21- Count distinct entities to verify data completeness22- Document all entity types, predicates, and relationships observed2324**Verification checkpoint:** Confirm the number of distinct entities matches expectations before proceeding.2526### Step 2: Schema Understanding2728Map out the data structure before query construction.2930**Key elements to identify:**31- All entity types (classes) in the dataset32- All predicates/properties used33- Relationships between entities (e.g., professor → department → students)34- Data types for literals (strings, dates, integers)35- Naming conventions and value formats3637**Common patterns in academic data:**38- Roles/titles often use specific prefixes (e.g., "Professor of", "Associate Professor")39- Dates may require comparison logic for "current" status40- Geographic codes may use ISO standards (country codes)41- Enrollment may span multiple departments4243### Step 3: Criteria Decomposition4445Break down filtering requirements into discrete, testable conditions.4647**For each criterion:**481. Identify the exact predicate path to the relevant data492. Determine the comparison type (equality, prefix match, membership, numeric)503. Consider edge cases in the criterion interpretation514. Test each criterion independently before combining5253**Example decomposition:**54- "Full professors" → Filter where role starts with specific prefix55- "Working in EU countries" → Filter country codes against EU membership list56- "Departments with >10 students" → Count students per department, apply threshold5758### Step 4: Query Construction5960Build the query incrementally with validation at each stage.6162**Construction sequence:**631. Start with the most restrictive filter to reduce result set642. Add one filter at a time, verifying intermediate results653. Include all necessary SELECT variables664. Add aggregation (GROUP BY, GROUP_CONCAT) last6768**Syntax validation:**69- Verify all prefixes are declared70- Ensure FILTER expressions are properly closed71- Check string comparisons use correct functions (STRSTARTS, CONTAINS, regex)72- Confirm numeric comparisons handle data types correctly7374**Output format considerations:**75- Determine if results need aggregation (e.g., concatenating multiple values)76- Specify sort order and separators for concatenated values77- Distinguish between filtering criteria and output requirements (e.g., filter by EU countries but output ALL countries)7879### Step 5: Verification Strategy8081Test the query against known expectations.8283**Verification methods:**841. Run the query and examine raw output852. Manually trace through data for at least 2-3 entities to verify correctness863. Check for both inclusion (expected entities present) AND exclusion (unexpected entities absent)874. Verify aggregated values by manual count8889**Cross-reference checklist:**90- Do the returned entities match manual analysis?91- Are all expected entities present in results?92- Are any unexpected entities incorrectly included?93- Do aggregated counts/values match manual verification?9495## Common Pitfalls9697### Incomplete Data Reading98- **Problem:** Working with truncated data leads to missing entities99- **Prevention:** Always confirm complete file content; re-read if truncated100101### Query Truncation102- **Problem:** Long queries may be incompletely written103- **Prevention:** After writing, read back the query file to verify completeness104105### Criterion Misinterpretation106- **Problem:** Confusing filter criteria with output requirements107- **Prevention:** Distinguish between "filter BY X" vs "output X" - these may differ108109### Date/Time Edge Cases110- **Problem:** Incorrect handling of boundary dates111- **Prevention:** Clarify whether comparisons are inclusive or exclusive; test boundaries112113### Aggregation Errors114- **Problem:** Missing GROUP BY clauses or incorrect GROUP_CONCAT usage115- **Prevention:** Verify aggregation syntax matches the query structure116117### EU Country List118- **Problem:** Incomplete or outdated list of EU member country codes119- **Prevention:** Use comprehensive list: AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT, LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE120121### Cross-Entity Relationships122- **Problem:** Miscounting entities across relationships (e.g., students in departments)123- **Prevention:** Trace the full predicate path; verify join conditions124125## Testing Protocol1261271. **Syntax check:** Ensure query parses without errors1282. **Subset test:** Run on a known subset of data with expected results1293. **Full test:** Run on complete dataset1304. **Manual verification:** Trace 2-3 results through source data1315. **Boundary test:** Check edge cases in filters (dates, counts, string matches)132133## Iteration Approach134135If initial results do not match expectations:1361371. Isolate which filter condition is causing discrepancies1382. Test each filter independently1393. Examine entities that should appear but don't (false negatives)1404. Examine entities that shouldn't appear but do (false positives)1415. Adjust filter logic based on findings1426. Re-verify after each adjustment